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

@ -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);
@ -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"
) { ) {
@ -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.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) {
@ -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 { } 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;