diff --git a/src/preload/cider-preload.js b/src/preload/cider-preload.js index 31b6f662..42990ce2 100644 --- a/src/preload/cider-preload.js +++ b/src/preload/cider-preload.js @@ -22,7 +22,8 @@ const MusicKitInterop = { }); /** wsapi */ - MusicKit.getInstance().addEventListener(MusicKit.Events.nowPlayingItemDidChange, () => { + MusicKit.getInstance().addEventListener(MusicKit.Events.nowPlayingItemDidChange, async () => { + await MusicKitInterop.modifyNamesOnLocale(); if (MusicKitInterop.filterTrack(MusicKitInterop.getAttributes(), false, true) || !app.cfg.lastfm.filterLoop) { global.ipcRenderer.send('nowPlayingItemDidChange', MusicKitInterop.getAttributes()); } @@ -36,7 +37,28 @@ const MusicKitInterop = { console.warn(`[mediaPlaybackError] ${e}`); }) }, + async modifyNamesOnLocale() { + if (app.mklang == '' || app.mklang == null) { + return; + } + const mk = MusicKit.getInstance() + const nowPlayingItem = mk.nowPlayingItem; + if ((nowPlayingItem?._songId ?? nowPlayingItem?.songId) == null){ + return; + } + const id = nowPlayingItem?._songId ?? (nowPlayingItem?.songId ?? nowPlayingItem?.id) + if (id != null) { + try{ + const query = await mk.api.v3.music(`/v1${((nowPlayingItem?._songId ?? nowPlayingItem?.songId) != null) ? `/catalog/${mk.storefrontId}/` : `/me/library/`}songs/${id}?l=${app.mklang}`); + if (query?.data?.data[0]){ + let attrs = query?.data?.data[0]?.attributes; + if (attrs?.name) { nowPlayingItem.attributes.name = attrs?.name ?? ''} + if (attrs?.albumName) { nowPlayingItem.attributes.albumName = attrs?.albumName ?? ''} + if (attrs?.artistName) { nowPlayingItem.attributes.artistName = attrs?.artistName ?? ''} + }} catch (e) { return;} + } else {return;} + }, getAttributes: function () { const mk = MusicKit.getInstance() const nowPlayingItem = mk.nowPlayingItem; @@ -51,8 +73,8 @@ const MusicKitInterop = { attributes.playParams = attributes?.playParams ?? {id: 'no-id-found'}; attributes.playParams.id = attributes?.playParams?.id ?? 'no-id-found'; attributes.url = { - cider: `cider://play/s/${nowPlayingItem?._songId ?? 'no-id-found'}`, - appleMusic: attributes.websiteUrl ? attributes.websiteUrl : `https://music.apple.com/${mk.storefrontId}/song/${nowPlayingItem?._songId ?? 'no-id-found'}` + cider: `cider://play/s/${nowPlayingItem?._songId ?? (nowPlayingItem?.songId ??'no-id-found')}`, + appleMusic: attributes.websiteUrl ? attributes.websiteUrl : `https://music.apple.com/${mk.storefrontId}/song/${nowPlayingItem?._songId ?? (nowPlayingItem?.songId ??'no-id-found')}` } if (attributes.playParams.id === 'no-id-found') { attributes.playParams.id = nowPlayingItem?.id ?? 'no-id-found'; @@ -69,7 +91,7 @@ const MusicKitInterop = { attributes?.playParams?.id === cache.playParams.id ? Date.now() + attributes?.remainingTime : attributes?.startTime + attributes?.durationInMillis - ); + ); return attributes; }, diff --git a/src/renderer/index.js b/src/renderer/index.js index 17372d48..26689312 100644 --- a/src/renderer/index.js +++ b/src/renderer/index.js @@ -734,7 +734,7 @@ const app = new Vue({ } catch (e) { } if (!previewURL) { - app.mk.api.v3.music(`/v1/catalog/${app.mk.storefrontId}/songs/${app.mk.nowPlayingItem._songId ?? app.mk.nowPlayingItem.relationships.catalog.data[0].id}`).then((response) => { + app.mk.api.v3.music(`/v1/catalog/${app.mk.storefrontId}/songs/${app.mk.nowPlayingItem?._songId ?? (app.mk.nowPlayingItem["songId"] ?? app.mk.nowPlayingItem.relationships.catalog.data[0].id)}`).then((response) => { previewURL = response.data.data[0].attributes.previews[0].url if (previewURL) ipcRenderer.send('getPreviewURL', previewURL) @@ -2298,12 +2298,12 @@ const app = new Vue({ } }, loadAMLyrics() { - const songID = (this.mk.nowPlayingItem != null) ? this.mk.nowPlayingItem["_songId"] ?? -1 : -1; + const songID = (this.mk.nowPlayingItem != null) ? this.mk.nowPlayingItem["_songId"] ?? (this.mk.nowPlayingItem["songId"] ?? -1) : -1; // this.getMXM( trackName, artistName, 'en', duration); if (songID != -1) { - MusicKit.getInstance().api.lyric(songID) + this.mk.api.v3.music(`v1/catalog/${this.mk.storefrontId}/songs/${songID}/lyrics`) .then((response) => { - this.lyricsMediaItem = response.attributes["ttml"] + this.lyricsMediaItem = response.data?.data[0]?.attributes["ttml"] this.parseTTML() }) } @@ -2329,7 +2329,7 @@ const app = new Vue({ }, async losslessBadge() { - const songID = (this.mk.nowPlayingItem != null) ? this.mk.nowPlayingItem["_songId"] ?? -1 : -1; + const songID = (this.mk.nowPlayingItem != null) ? this.mk.nowPlayingItem["_songId"] ?? (this.mk.nowPlayingItem["songId"] ?? -1) : -1; if (app.cfg.advanced.ciderPPE && songID != -1) { /**let extendedAssets = await app.mk.api.song(songID, {extend : 'extendedAssetUrls'}) if (extendedAssets.attributes.audioTraits.includes('lossless')) {*/ @@ -2414,7 +2414,7 @@ const app = new Vue({ const track = encodeURIComponent((this.mk.nowPlayingItem != null) ? this.mk.nowPlayingItem.title ?? '' : ''); const artist = encodeURIComponent((this.mk.nowPlayingItem != null) ? this.mk.nowPlayingItem.artistName ?? '' : ''); const time = encodeURIComponent((this.mk.nowPlayingItem != null) ? (Math.round((this.mk.nowPlayingItem.attributes["durationInMillis"] ?? -1000) / 1000) ?? -1) : -1); - const id = encodeURIComponent((this.mk.nowPlayingItem != null) ? app.mk.nowPlayingItem._songId ?? '' : ''); + const id = encodeURIComponent((this.mk.nowPlayingItem != null) ? app.mk.nowPlayingItem._songId ?? (app.mk.nowPlayingItem["songId"] ?? '') : ''); let lrcfile = ""; let richsync = []; const lang = app.cfg.lyrics.mxm_language // translation language @@ -3413,7 +3413,7 @@ const app = new Vue({ "icon": "./assets/feather/share.svg", "name": app.getLz('action.share'), "action": function () { - app.mkapi(app.mk.nowPlayingItem.attributes?.playParams?.kind ?? app.mk.nowPlayingItem.type ?? 'songs', false, app.mk.nowPlayingItem._songId ?? app.mk.nowPlayingItem.id ?? '').then(u => { + app.mkapi(app.mk.nowPlayingItem.attributes?.playParams?.kind ?? app.mk.nowPlayingItem.type ?? 'songs', false, app.mk.nowPlayingItem._songId ?? (app.mk.nowPlayingItem.songId ?? app.mk.nowPlayingItem.id) ?? '').then(u => { app.copyToClipboard((u.data.data.length && u.data.data.length > 0) ? u.data.data[0].attributes.url : u.data.data.attributes.url) }) } @@ -3422,7 +3422,7 @@ const app = new Vue({ "icon": "./assets/feather/share.svg", "name": `${app.getLz('action.share')} (song.link)`, "action": function () { - app.mkapi(app.mk.nowPlayingItem.attributes?.playParams?.kind ?? app.mk.nowPlayingItem.type ?? 'songs', false, app.mk.nowPlayingItem._songId ?? app.mk.nowPlayingItem.id ?? '').then(u => { + app.mkapi(app.mk.nowPlayingItem.attributes?.playParams?.kind ?? app.mk.nowPlayingItem.type ?? 'songs', false, app.mk.nowPlayingItem._songId ?? (app.mk.nowPlayingItem.songId ?? app.mk.nowPlayingItem.id) ?? '').then(u => { app.songLinkShare((u.data.data.length && u.data.data.length > 0) ? u.data.data[0].attributes.url : u.data.data.attributes.url) }) } diff --git a/src/renderer/views/components/mediaitem-list-item.ejs b/src/renderer/views/components/mediaitem-list-item.ejs index d74d0c2a..c2df9efd 100644 --- a/src/renderer/views/components/mediaitem-list-item.ejs +++ b/src/renderer/views/components/mediaitem-list-item.ejs @@ -23,12 +23,12 @@ <%- include("../svg/play.svg") %> -
+
{{ (item.attributes && !showIndexPlaylist) ? (item.attributes.trackNumber ?? '') : ((index * 1 + 1 ) ?? '')}}
-
+