diff --git a/src/renderer/main/vueapp.js b/src/renderer/main/vueapp.js index 9b89f8d2..165c2db1 100644 --- a/src/renderer/main/vueapp.js +++ b/src/renderer/main/vueapp.js @@ -2534,38 +2534,6 @@ const app = new Vue({ this.getBrowsePage(attempt + 1) } }, - async getRadioStations(attempt = 0) { - if (this.radio.timestamp > Date.now() - 120000) { - return - } - if (attempt > 3) { - return - } - try { - this.radio.personal.title = app.getLz('term.personalStations') - this.radio.personal.data = (await app.mk.api.v3.music(`/v1/catalog/${app.mk.api.v3.storefrontId}/stations`, { - "filter[identity]": "personal", - })).data.data - - this.radio.recent.title = app.getLz('term.recentStations') - this.radio.recent.data = (await app.mk.api.v3.music(`/v1/me/recent/radio-stations`, { - "platform": "web", - "art[url]": "f", - l: this.mklang - })).data.data - - this.radio.amlive.title = app.getLz('term.amLive') - this.radio.amlive.data = (await app.mk.api.v3.music(`/v1/catalog/${app.mk.api.v3.storefrontId}/stations`, { - "filter[featured]": "apple-music-live-radio", - })).data.data - - this.radio.timestamp = Date.now() - console.debug(this.radio) - } catch (e) { - console.log(e) - this.getRadioStations(attempt + 1) - } - }, async getMadeForYou(attempt = 0) { if (attempt > 3) { return diff --git a/src/renderer/views/pages/radio.ejs b/src/renderer/views/pages/radio.ejs index f993f117..10d42caa 100644 --- a/src/renderer/views/pages/radio.ejs +++ b/src/renderer/views/pages/radio.ejs @@ -1,9 +1,28 @@ @@ -13,11 +32,60 @@ props: ["data"], data: function () { return { - app: this.$root + app: this.$root, + radio: {personal: [], recent: [], am: []} } }, - mounted() { - this.$root.getRadioStations() + 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(); + }, + 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) + } + }, } }) \ No newline at end of file