change to library-songs retrieval method

This commit is contained in:
booploops 2022-03-07 22:15:04 -08:00
parent f6bce2019d
commit 082137ed9d
4 changed files with 13283 additions and 166 deletions

View file

@ -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) {
onProgress({
response: response,
total: returnData.length
})
try {
await sendReq(response.data.next, options) 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() {

View file

@ -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.songs.downloadState = 1
if (downloaded == null) {
app.mk.api.v3.music(`/v1/me/library/songs/`, params).then((response) => {
processChunk(response.data)
}).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.show = true
self.library.backgroundNotification.message = app.getLz('notification.updatingLibrarySongs') self.library.backgroundNotification.message = app.getLz('notification.updatingLibrarySongs')
self.library.backgroundNotification.total = downloaded.meta.total self.library.backgroundNotification.total = data.response.data.meta.total
self.library.backgroundNotification.progress = library.length self.library.backgroundNotification.progress = data.total
},
onSuccess: () => {
}
})
self.library.songs.listing = library
self.library.songs.downloadState = 2
self.library.backgroundNotification.show = false
self.searchLibrarySongs()
CiderCache.putCache(cacheId, library)
console.log("Done!")
if (downloaded.meta.total == 0) {
self.library.songs.downloadState = 3
return return
}
if (typeof downloaded.next == "undefined") {
console.log("downloaded.next is undefined")
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()
}, },
// 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) {
@ -3875,7 +3824,8 @@ const app = new Vue({
} else { } else {
ipcRenderer.send('windowontop', false) ipcRenderer.send('windowontop', false)
this.cfg.visual.miniplayer_top_toggle = false; this.cfg.visual.miniplayer_top_toggle = false;
}} else { }
} 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

File diff suppressed because it is too large Load diff

View file

@ -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;