From d7dd447e7ab663c6413ca4a952414fcb21ba05e7 Mon Sep 17 00:00:00 2001 From: Core Date: Tue, 13 Sep 2022 19:35:03 +0100 Subject: [PATCH] initial --- src/renderer/main/vueapp.js | 52 +++++++++++++++-- src/renderer/views/pages/radio.ejs | 94 ++++++------------------------ 2 files changed, 66 insertions(+), 80 deletions(-) diff --git a/src/renderer/main/vueapp.js b/src/renderer/main/vueapp.js index 7b8581a7..37ce1bbd 100644 --- a/src/renderer/main/vueapp.js +++ b/src/renderer/main/vueapp.js @@ -46,9 +46,8 @@ const app = new Vue({ listennow: [], madeforyou: [], radio: { - personal: {}, - recent: {}, - amlive: {}, + "editorial": [], + "recent": [], }, mklang: "en", webview: { @@ -783,6 +782,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 +3004,48 @@ 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[music-videos]": "artists", + "include[songs]": "artists", + "include[stations]": "events", + extend: "artistUrl,editorialArtwork", + "fields[artists]": "name,url,artwork,editorialArtwork,genreNames,editorialNotes", + "format[resources]": "map", + "art[url]": "f", + l: app.mklang + }).then((radio) => { + app.radio.editorial = radio.data.resources + console.debug(app.radio); + }) + + + app.mk.api.v3.music(`/v1/me/recent/radio-stations`, { + "platform": "web", + "art[url]": "f", + "format[resources]": "map", + l: app.mklang + }).then((radio) => { + app.radio.recent = radio.data + 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 +3064,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..6f1c3017 100644 --- a/src/renderer/views/pages/radio.ejs +++ b/src/renderer/views/pages/radio.ejs @@ -1,28 +1,18 @@ @@ -33,59 +23,11 @@ data: function() { return { app: this.$root, - radio: { personal: [], recent: [], am: [] } - } + }; }, - 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(); }, - methods: { - async getPersonalStations(attempts = 0) { - if (attempts > 3) { - return [] - } - 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) - } - }, - } - }) + methods: {} + });