change to library-songs retrieval method
This commit is contained in:
parent
f6bce2019d
commit
082137ed9d
4 changed files with 13283 additions and 166 deletions
|
@ -1,17 +1,32 @@
|
||||||
const MusicKitTools = {
|
const MusicKitTools = {
|
||||||
async v3Continuous (href, options = {}, reqOptions = {}) {
|
async v3Continuous ({
|
||||||
|
href,
|
||||||
|
options = {},
|
||||||
|
reqOptions = {},
|
||||||
|
onProgress = () => {},
|
||||||
|
onError = () => {},
|
||||||
|
onSuccess = () => {}
|
||||||
|
} = {}) {
|
||||||
let returnData = []
|
let returnData = []
|
||||||
async function sendReq(href, options) {
|
async function sendReq(href, options) {
|
||||||
const response = await app.mk.api.v3.music(href, options)
|
const response = await app.mk.api.v3.music(href, options).catch(error => onError)
|
||||||
|
|
||||||
returnData = returnData.concat(response.data.data)
|
returnData = returnData.concat(response.data.data)
|
||||||
if(response.data.next) {
|
if(response.data.next) {
|
||||||
await sendReq(response.data.next, options)
|
onProgress({
|
||||||
|
response: response,
|
||||||
|
total: returnData.length
|
||||||
|
})
|
||||||
|
try {
|
||||||
|
await sendReq(response.data.next, options)
|
||||||
|
}catch(e){
|
||||||
|
await sendReq(response.data.next, options)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
await sendReq(href, options)
|
await sendReq(href, options)
|
||||||
|
onSuccess(returnData)
|
||||||
return returnData
|
return returnData
|
||||||
},
|
},
|
||||||
getHeader() {
|
getHeader() {
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
import {store} from './vuex-store.js';
|
import { store } from './vuex-store.js';
|
||||||
|
|
||||||
Vue.use(VueHorizontal);
|
Vue.use(VueHorizontal);
|
||||||
Vue.use(VueObserveVisibility);
|
Vue.use(VueObserveVisibility);
|
||||||
|
@ -542,13 +542,13 @@ const app = new Vue({
|
||||||
this.modals.addToPlaylist = false
|
this.modals.addToPlaylist = false
|
||||||
await app.mk.api.v3.music(
|
await app.mk.api.v3.music(
|
||||||
`/v1/me/library/playlists/${playlist_id}/tracks`, {}, {
|
`/v1/me/library/playlists/${playlist_id}/tracks`, {}, {
|
||||||
fetchOptions: {
|
fetchOptions: {
|
||||||
method: "POST",
|
method: "POST",
|
||||||
body: JSON.stringify({
|
body: JSON.stringify({
|
||||||
data: pl_items
|
data: pl_items
|
||||||
})
|
})
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
}
|
||||||
).then(() => {
|
).then(() => {
|
||||||
if (this.page == 'playlist_' + this.showingPlaylist.id) {
|
if (this.page == 'playlist_' + this.showingPlaylist.id) {
|
||||||
this.getPlaylistFromID(this.showingPlaylist.id, true)
|
this.getPlaylistFromID(this.showingPlaylist.id, true)
|
||||||
|
@ -1017,7 +1017,7 @@ const app = new Vue({
|
||||||
console.log("playlist has no cache")
|
console.log("playlist has no cache")
|
||||||
}
|
}
|
||||||
|
|
||||||
if(cachedTrackMapping) {
|
if (cachedTrackMapping) {
|
||||||
console.log("using cached track mapping")
|
console.log("using cached track mapping")
|
||||||
this.playlists.trackMapping = cachedTrackMapping
|
this.playlists.trackMapping = cachedTrackMapping
|
||||||
}
|
}
|
||||||
|
@ -1033,7 +1033,7 @@ const app = new Vue({
|
||||||
const playlistData = await app.mk.api.v3.music(`/v1/me/library/playlist-folders/${parent}/children/`)
|
const playlistData = await app.mk.api.v3.music(`/v1/me/library/playlist-folders/${parent}/children/`)
|
||||||
await asyncForEach(playlistData.data.data, async (playlist) => {
|
await asyncForEach(playlistData.data.data, async (playlist) => {
|
||||||
playlist.parent = parent
|
playlist.parent = parent
|
||||||
if(
|
if (
|
||||||
playlist.type != "library-playlist-folders" &&
|
playlist.type != "library-playlist-folders" &&
|
||||||
typeof playlist.attributes.playParams["versionHash"] != "undefined"
|
typeof playlist.attributes.playParams["versionHash"] != "undefined"
|
||||||
) {
|
) {
|
||||||
|
@ -1103,12 +1103,12 @@ const app = new Vue({
|
||||||
this.newPlaylist()
|
this.newPlaylist()
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: app.getLz('term.createNewPlaylistFolder'),
|
name: app.getLz('term.createNewPlaylistFolder'),
|
||||||
action: () => {
|
action: () => {
|
||||||
this.newPlaylistFolder()
|
this.newPlaylistFolder()
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
}
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
this.showMenuPanel(menu, event)
|
this.showMenuPanel(menu, event)
|
||||||
|
@ -1117,13 +1117,13 @@ const app = new Vue({
|
||||||
let self = this
|
let self = this
|
||||||
this.mk.api.v3.music(
|
this.mk.api.v3.music(
|
||||||
`/v1/me/library/playlist-folders/${id}`, {}, {
|
`/v1/me/library/playlist-folders/${id}`, {}, {
|
||||||
fetchOptions: {
|
fetchOptions: {
|
||||||
method: "PATCH",
|
method: "PATCH",
|
||||||
body: JSON.stringify({
|
body: JSON.stringify({
|
||||||
attributes: { name: name }
|
attributes: { name: name }
|
||||||
})
|
})
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
}
|
||||||
).then(res => {
|
).then(res => {
|
||||||
self.refreshPlaylists()
|
self.refreshPlaylists()
|
||||||
})
|
})
|
||||||
|
@ -1132,13 +1132,13 @@ const app = new Vue({
|
||||||
let self = this
|
let self = this
|
||||||
this.mk.api.v3.music(
|
this.mk.api.v3.music(
|
||||||
`/v1/me/library/playlists/${id}`, {}, {
|
`/v1/me/library/playlists/${id}`, {}, {
|
||||||
fetchOptions: {
|
fetchOptions: {
|
||||||
method: "PATCH",
|
method: "PATCH",
|
||||||
body: JSON.stringify({
|
body: JSON.stringify({
|
||||||
attributes: { name: name }
|
attributes: { name: name }
|
||||||
})
|
})
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
}
|
||||||
).then(res => {
|
).then(res => {
|
||||||
self.refreshPlaylists()
|
self.refreshPlaylists()
|
||||||
})
|
})
|
||||||
|
@ -1401,7 +1401,7 @@ const app = new Vue({
|
||||||
*/
|
*/
|
||||||
convertTime(time = 0, format = 'short') {
|
convertTime(time = 0, format = 'short') {
|
||||||
|
|
||||||
if(isNaN(time)) {
|
if (isNaN(time)) {
|
||||||
time = 0
|
time = 0
|
||||||
}
|
}
|
||||||
if (typeof time !== "number") {
|
if (typeof time !== "number") {
|
||||||
|
@ -1516,9 +1516,9 @@ const app = new Vue({
|
||||||
document.querySelector("#app-content").scrollTop = 0
|
document.querySelector("#app-content").scrollTop = 0
|
||||||
} else if (kind == "editorial-elements") {
|
} else if (kind == "editorial-elements") {
|
||||||
console.log(item)
|
console.log(item)
|
||||||
if (item.relationships?.contents?.data != null && item.relationships?.contents?.data.length > 0){
|
if (item.relationships?.contents?.data != null && item.relationships?.contents?.data.length > 0) {
|
||||||
this.routeView(item.relationships.contents.data[0])
|
this.routeView(item.relationships.contents.data[0])
|
||||||
} else if (item.attributes?.link?.url != null){
|
} else if (item.attributes?.link?.url != null) {
|
||||||
window.open(item.attributes.link.url)
|
window.open(item.attributes.link.url)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -2048,7 +2048,7 @@ const app = new Vue({
|
||||||
}
|
}
|
||||||
let librarySongs = await CiderCache.getCache(cacheId)
|
let librarySongs = await CiderCache.getCache(cacheId)
|
||||||
if (librarySongs) {
|
if (librarySongs) {
|
||||||
this.library.songs.listing = librarySongs
|
this.library.songs.listing.data = librarySongs
|
||||||
this.searchLibrarySongs()
|
this.searchLibrarySongs()
|
||||||
}
|
}
|
||||||
if (this.songstest) {
|
if (this.songstest) {
|
||||||
|
@ -2058,8 +2058,9 @@ const app = new Vue({
|
||||||
this.library.backgroundNotification.show = true
|
this.library.backgroundNotification.show = true
|
||||||
this.library.backgroundNotification.message = app.getLz('notification.updatingLibrarySongs')
|
this.library.backgroundNotification.message = app.getLz('notification.updatingLibrarySongs')
|
||||||
|
|
||||||
function downloadChunk() {
|
library = await MusicKitTools.v3Continuous({
|
||||||
const params = {
|
href: `/v1/me/library/songs/`,
|
||||||
|
options: {
|
||||||
"include[library-songs]": "catalog,artists,albums",
|
"include[library-songs]": "catalog,artists,albums",
|
||||||
"fields[artists]": "name,url,id",
|
"fields[artists]": "name,url,id",
|
||||||
"fields[albums]": "name,url,id",
|
"fields[albums]": "name,url,id",
|
||||||
|
@ -2067,80 +2068,28 @@ const app = new Vue({
|
||||||
"fields[catalog]": "artistUrl,albumUrl",
|
"fields[catalog]": "artistUrl,albumUrl",
|
||||||
"fields[songs]": "artistName,artistUrl,artwork,contentRating,editorialArtwork,name,playParams,releaseDate,url",
|
"fields[songs]": "artistName,artistUrl,artwork,contentRating,editorialArtwork,name,playParams,releaseDate,url",
|
||||||
limit: 100,
|
limit: 100,
|
||||||
l: self.mklang
|
l: app.mklang,
|
||||||
}
|
},
|
||||||
const safeparams = {
|
onProgress: (data) => {
|
||||||
"platform": "web",
|
console.log(`${data.total}/${data.response.data.meta.total}`)
|
||||||
"limit": 80
|
self.library.backgroundNotification.show = true
|
||||||
}
|
self.library.backgroundNotification.message = app.getLz('notification.updatingLibrarySongs')
|
||||||
self.library.songs.downloadState = 1
|
self.library.backgroundNotification.total = data.response.data.meta.total
|
||||||
if (downloaded == null) {
|
self.library.backgroundNotification.progress = data.total
|
||||||
app.mk.api.v3.music(`/v1/me/library/songs/`, params).then((response) => {
|
},
|
||||||
processChunk(response.data)
|
onSuccess: () => {
|
||||||
}).catch((error) => {
|
|
||||||
console.log('safe loading');
|
|
||||||
app.mk.api.v3.music(`/v1/me/library/songs/`, safeparams).then((response) => {
|
|
||||||
processChunk(response.data)
|
|
||||||
}).catch((error) => {
|
|
||||||
console.log('safe loading failed', error)
|
|
||||||
app.library.songs.downloadState = 2
|
|
||||||
app.library.backgroundNotification.show = false
|
|
||||||
})
|
|
||||||
})
|
|
||||||
} else {
|
|
||||||
if (downloaded.next != null) {
|
|
||||||
app.mk.api.v3.music(downloaded.next, params).then((response) => {
|
|
||||||
processChunk(response.data)
|
|
||||||
}).catch((error) => {
|
|
||||||
console.log('safe loading');
|
|
||||||
app.mk.api.v3.music(downloaded.next, safeparams).then((response) => {
|
|
||||||
processChunk(response.data)
|
|
||||||
}).catch((error) => {
|
|
||||||
console.log('safe loading failed', error)
|
|
||||||
app.library.songs.downloadState = 2
|
|
||||||
app.library.backgroundNotification.show = false
|
|
||||||
})
|
|
||||||
})
|
|
||||||
} else {
|
|
||||||
console.log("Download next", downloaded.next)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
function processChunk(response) {
|
}
|
||||||
downloaded = response
|
})
|
||||||
library = library.concat(downloaded.data)
|
|
||||||
self.library.backgroundNotification.show = true
|
|
||||||
self.library.backgroundNotification.message = app.getLz('notification.updatingLibrarySongs')
|
|
||||||
self.library.backgroundNotification.total = downloaded.meta.total
|
|
||||||
self.library.backgroundNotification.progress = library.length
|
|
||||||
|
|
||||||
if (downloaded.meta.total == 0) {
|
self.library.songs.listing = library
|
||||||
self.library.songs.downloadState = 3
|
self.library.songs.downloadState = 2
|
||||||
return
|
self.library.backgroundNotification.show = false
|
||||||
}
|
self.searchLibrarySongs()
|
||||||
if (typeof downloaded.next == "undefined") {
|
CiderCache.putCache(cacheId, library)
|
||||||
console.log("downloaded.next is undefined")
|
console.log("Done!")
|
||||||
self.library.songs.listing = library
|
|
||||||
self.library.songs.downloadState = 2
|
|
||||||
self.library.backgroundNotification.show = false
|
|
||||||
self.searchLibrarySongs()
|
|
||||||
CiderCache.putCache(cacheId, library)
|
|
||||||
}
|
|
||||||
if (downloaded.meta.total > library.length || typeof downloaded.meta.next != "undefined") {
|
|
||||||
console.log(`downloading next chunk - ${library.length} songs so far`)
|
|
||||||
downloadChunk()
|
|
||||||
} else {
|
|
||||||
self.library.songs.listing = library
|
|
||||||
self.library.songs.downloadState = 2
|
|
||||||
self.library.backgroundNotification.show = false
|
|
||||||
self.searchLibrarySongs()
|
|
||||||
CiderCache.putCache(cacheId, library)
|
|
||||||
// console.log(library)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
downloadChunk()
|
return
|
||||||
},
|
},
|
||||||
// copy the getLibrarySongsFull function except change Songs to Albums
|
// copy the getLibrarySongsFull function except change Songs to Albums
|
||||||
async getLibraryAlbumsFull(force = false, index) {
|
async getLibraryAlbumsFull(force = false, index) {
|
||||||
|
@ -2239,7 +2188,7 @@ const app = new Vue({
|
||||||
}
|
}
|
||||||
if (downloaded.meta.total > library.length || typeof downloaded.meta.next != "undefined") {
|
if (downloaded.meta.total > library.length || typeof downloaded.meta.next != "undefined") {
|
||||||
console.log(`downloading next chunk - ${library.length
|
console.log(`downloading next chunk - ${library.length
|
||||||
} albums so far`)
|
} albums so far`)
|
||||||
downloadChunk()
|
downloadChunk()
|
||||||
} else {
|
} else {
|
||||||
self.library.albums.listing = library
|
self.library.albums.listing = library
|
||||||
|
@ -2348,7 +2297,7 @@ const app = new Vue({
|
||||||
}
|
}
|
||||||
if (downloaded.meta.total > library.length || typeof downloaded.meta.next != "undefined") {
|
if (downloaded.meta.total > library.length || typeof downloaded.meta.next != "undefined") {
|
||||||
console.log(`downloading next chunk - ${library.length
|
console.log(`downloading next chunk - ${library.length
|
||||||
} artists so far`)
|
} artists so far`)
|
||||||
downloadChunk()
|
downloadChunk()
|
||||||
} else {
|
} else {
|
||||||
self.library.artists.listing = library
|
self.library.artists.listing = library
|
||||||
|
@ -2484,13 +2433,13 @@ const app = new Vue({
|
||||||
let self = this
|
let self = this
|
||||||
this.mk.api.v3.music(
|
this.mk.api.v3.music(
|
||||||
"/v1/me/library/playlist-folders/", {}, {
|
"/v1/me/library/playlist-folders/", {}, {
|
||||||
fetchOptions: {
|
fetchOptions: {
|
||||||
method: "POST",
|
method: "POST",
|
||||||
body: JSON.stringify({
|
body: JSON.stringify({
|
||||||
attributes: { name: name }
|
attributes: { name: name }
|
||||||
})
|
})
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
}
|
||||||
).then((res) => {
|
).then((res) => {
|
||||||
let playlist = (res.data.data[0])
|
let playlist = (res.data.data[0])
|
||||||
self.playlists.listing.push({
|
self.playlists.listing.push({
|
||||||
|
@ -3055,21 +3004,21 @@ const app = new Vue({
|
||||||
if (ids.length > 0) {
|
if (ids.length > 0) {
|
||||||
if (app.mk.queue._itemIDs.length > 0) {
|
if (app.mk.queue._itemIDs.length > 0) {
|
||||||
app.mk.playLater({ [kind + "s"]: itemsToPlay[kind] }).then(function () {
|
app.mk.playLater({ [kind + "s"]: itemsToPlay[kind] }).then(function () {
|
||||||
ind += 1;
|
ind += 1;
|
||||||
console.log(ind, Object.keys(itemsToPlay).length)
|
console.log(ind, Object.keys(itemsToPlay).length)
|
||||||
if (ind >= Object.keys(itemsToPlay).length) {
|
if (ind >= Object.keys(itemsToPlay).length) {
|
||||||
app.mk.changeToMediaAtIndex(app.mk.queue._itemIDs.indexOf(item.attributes.playParams.id ?? item.id))
|
app.mk.changeToMediaAtIndex(app.mk.queue._itemIDs.indexOf(item.attributes.playParams.id ?? item.id))
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
}
|
||||||
)
|
)
|
||||||
} else {
|
} else {
|
||||||
app.mk.setQueue({ [kind + "s"]: itemsToPlay[kind] }).then(function () {
|
app.mk.setQueue({ [kind + "s"]: itemsToPlay[kind] }).then(function () {
|
||||||
ind += 1;
|
ind += 1;
|
||||||
console.log(ind, Object.keys(itemsToPlay).length)
|
console.log(ind, Object.keys(itemsToPlay).length)
|
||||||
if (ind >= Object.keys(itemsToPlay).length) {
|
if (ind >= Object.keys(itemsToPlay).length) {
|
||||||
app.mk.changeToMediaAtIndex(app.mk.queue._itemIDs.indexOf(item.attributes.playParams.id ?? item.id))
|
app.mk.changeToMediaAtIndex(app.mk.queue._itemIDs.indexOf(item.attributes.playParams.id ?? item.id))
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
}
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -3648,36 +3597,36 @@ const app = new Vue({
|
||||||
app.love(app.mk.nowPlayingItem)
|
app.love(app.mk.nowPlayingItem)
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"icon": "./assets/feather/heart.svg",
|
"icon": "./assets/feather/heart.svg",
|
||||||
"id": "unlove",
|
"id": "unlove",
|
||||||
"active": true,
|
"active": true,
|
||||||
"name": app.getLz('action.unlove'),
|
"name": app.getLz('action.unlove'),
|
||||||
"hidden": true,
|
"hidden": true,
|
||||||
"action": function () {
|
"action": function () {
|
||||||
app.unlove(app.mk.nowPlayingItem)
|
app.unlove(app.mk.nowPlayingItem)
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"icon": "./assets/feather/thumbs-down.svg",
|
"icon": "./assets/feather/thumbs-down.svg",
|
||||||
"id": "dislike",
|
"id": "dislike",
|
||||||
"name": app.getLz('action.dislike'),
|
"name": app.getLz('action.dislike'),
|
||||||
"hidden": false,
|
"hidden": false,
|
||||||
"disabled": true,
|
"disabled": true,
|
||||||
"action": function () {
|
"action": function () {
|
||||||
app.dislike(app.mk.nowPlayingItem)
|
app.dislike(app.mk.nowPlayingItem)
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"icon": "./assets/feather/thumbs-down.svg",
|
"icon": "./assets/feather/thumbs-down.svg",
|
||||||
"id": "undo_dislike",
|
"id": "undo_dislike",
|
||||||
"name": app.getLz('action.undoDislike'),
|
"name": app.getLz('action.undoDislike'),
|
||||||
"active": true,
|
"active": true,
|
||||||
"hidden": true,
|
"hidden": true,
|
||||||
"action": function () {
|
"action": function () {
|
||||||
app.unlove(app.mk.nowPlayingItem)
|
app.unlove(app.mk.nowPlayingItem)
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
],
|
],
|
||||||
items: [
|
items: [
|
||||||
{
|
{
|
||||||
|
@ -3868,14 +3817,15 @@ const app = new Vue({
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
pinMiniPlayer(status = false) {
|
pinMiniPlayer(status = false) {
|
||||||
if (!status){
|
if (!status) {
|
||||||
if (!this.cfg.visual.miniplayer_top_toggle) {
|
if (!this.cfg.visual.miniplayer_top_toggle) {
|
||||||
ipcRenderer.send('windowontop', true)
|
ipcRenderer.send('windowontop', true)
|
||||||
this.cfg.visual.miniplayer_top_toggle = true;
|
this.cfg.visual.miniplayer_top_toggle = true;
|
||||||
|
} else {
|
||||||
|
ipcRenderer.send('windowontop', false)
|
||||||
|
this.cfg.visual.miniplayer_top_toggle = false;
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
ipcRenderer.send('windowontop', false)
|
|
||||||
this.cfg.visual.miniplayer_top_toggle = false;
|
|
||||||
}} else {
|
|
||||||
ipcRenderer.send('windowontop', this.cfg.visual.miniplayer_top_toggle ?? false)
|
ipcRenderer.send('windowontop', this.cfg.visual.miniplayer_top_toggle ?? false)
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
13152
src/renderer/style.css
Normal file
13152
src/renderer/style.css
Normal file
File diff suppressed because it is too large
Load diff
|
@ -558,14 +558,14 @@ input[type=range].web-slider::-webkit-slider-runnable-track {
|
||||||
.app-sidebar-notification {
|
.app-sidebar-notification {
|
||||||
text-align: center;
|
text-align: center;
|
||||||
font-size: 12px;
|
font-size: 12px;
|
||||||
min-height: 60px;
|
min-height: 36px;
|
||||||
display: flex;
|
display: flex;
|
||||||
justify-content: center;
|
justify-content: center;
|
||||||
align-items: center;
|
align-items: center;
|
||||||
border-top: 1px solid rgb(200 200 200 / 15%);
|
border-top: 1px solid rgb(200 200 200 / 15%);
|
||||||
background: rgb(0 0 0 / 15%);
|
background: rgb(0 0 0 / 15%);
|
||||||
flex-direction: column;
|
flex-direction: column;
|
||||||
padding: 20px 0px;
|
padding: 10px 0px;
|
||||||
|
|
||||||
&.libraryNotification {
|
&.libraryNotification {
|
||||||
flex-direction: row;
|
flex-direction: row;
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue