diff --git a/src/renderer/main/vueapp.js b/src/renderer/main/vueapp.js index 7b8581a7..bffa034c 100644 --- a/src/renderer/main/vueapp.js +++ b/src/renderer/main/vueapp.js @@ -45,11 +45,7 @@ const app = new Vue({ browsepage: [], listennow: [], madeforyou: [], - radio: { - personal: {}, - recent: {}, - amlive: {}, - }, + radio: [], mklang: "en", webview: { url: "", @@ -783,6 +779,9 @@ const app = new Vue({ this.mk.volume = -1; } + // Restore mk + + // load cached library let librarySongs = await CiderCache.getCache("library-songs"); let libraryAlbums = await CiderCache.getCache("library-albums"); @@ -3002,6 +3001,36 @@ const app = new Vue({ this.getListenNow(attempt + 1); } }, + async getRadioPage(attempt = 0) { + if (this.radio.timestamp > Date.now() - 120000) { + return; + } + if (attempt > 3) { + return; + } + try { + app.mk.api.v3.music(`/v1/editorial/${app.mk.storefrontId}/groupings`, { + platform: "web", + name: "radio", + "omit[resource:artists]": "relationships", + "include[albums]": "artists", + "include[songs]": "artists", + "include[music-videos]": "artists", + extend: "editorialArtwork,artistUrl", + "fields[artists]": "name,url,artwork,editorialArtwork,genreNames,editorialNotes", + "art[url]": "f", + l: app.mklang, + }).then((radio) => { + app.radio = radio.data.data[0]; + console.debug(app.radio); + }) + + this.radio.timestamp = Date.now(); + } catch (e) { + console.log(e); + this.getRadioPage(attempt + 1); + } + }, async getBrowsePage(attempt = 0) { if (this.browsepage.timestamp > Date.now() - 120000) { return; @@ -3020,7 +3049,7 @@ const app = new Vue({ extend: "editorialArtwork,artistUrl", "fields[artists]": "name,url,artwork,editorialArtwork,genreNames,editorialNotes", "art[url]": "f", - l: this.mklang, + l: app.mklang, }); this.browsepage = browse.data.data[0]; this.browsepage.timestamp = Date.now(); diff --git a/src/renderer/views/pages/radio.ejs b/src/renderer/views/pages/radio.ejs index 793f8a27..486a9964 100644 --- a/src/renderer/views/pages/radio.ejs +++ b/src/renderer/views/pages/radio.ejs @@ -1,28 +1,73 @@ @@ -33,59 +78,30 @@ data: function() { return { app: this.$root, - radio: { personal: [], recent: [], am: [] } - } + recent: [] + }; }, - async mounted() { - this.radio.personal = await this.getPersonalStations() - this.radio.recent = await this.getRecentStations() - this.radio.am = await this.getAmStations() - console.log(this.radio) - // this.getPersonalStations(); - // this.getAmStations(); + mounted() { + this.$root.getRadioPage(); + debugger + this.getRecentlyPlayed(); + debugger }, methods: { - async getPersonalStations(attempts = 0) { - if (attempts > 3) { - return [] + getRecentlyPlayed: async function (next = null) { + const recent = await app.mk.api.v3.music(`${next ?? "/v1/me/recent/radio-stations"}`, { + "platform": "web", + "art[url]": "f", + l: app.mklang + }) + + console.debug(recent.data.data) + this.recent = this.recent.concat(recent.data.data); + + if (recent.data.next) { + this.getRecentlyPlayed(recent.data.next); } - try { - return (await app.mk.api.v3.music(`/v1/catalog/${app.mk.api.v3.storefrontId}/stations`, { - "filter[identity]": "personal", - })).data.data - } catch (e) { - console.error(`Failed to get personal stations: ${e}`) - await this.getPersonalStations(attempts + 1) - } - }, - async getRecentStations(attempts = 0) { - if (attempts > 3) { - return [] - } - try { - return (await app.mk.api.v3.music(`/v1/me/recent/radio-stations`, { - "platform": "web", - "art[url]": "f", - l: app.mklang - })).data.data - } catch (e) { - console.error(`Failed to get recent stations: ${e}`) - await this.getRecentStations(attempts + 1) - } - }, - async getAmStations(attempt = 0) { - if (attempt > 3) { - return [] - } - try { - return (await app.mk.api.v3.music(`/v1/catalog/${app.mk.api.v3.storefrontId}/stations`, { - "filter[featured]": "apple-music-live-radio", - })).data.data - } catch (e) { - console.error(`Failed to get AM stations: ${e}`) - await this.getAmStations(attempt + 1) - } - }, + } } - }) + });