fix locale on nowplaying
This commit is contained in:
parent
a47091ea67
commit
636aeb450e
3 changed files with 36 additions and 14 deletions
|
@ -22,7 +22,8 @@ const MusicKitInterop = {
|
||||||
});
|
});
|
||||||
/** wsapi */
|
/** 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) {
|
if (MusicKitInterop.filterTrack(MusicKitInterop.getAttributes(), false, true) || !app.cfg.lastfm.filterLoop) {
|
||||||
global.ipcRenderer.send('nowPlayingItemDidChange', MusicKitInterop.getAttributes());
|
global.ipcRenderer.send('nowPlayingItemDidChange', MusicKitInterop.getAttributes());
|
||||||
}
|
}
|
||||||
|
@ -36,7 +37,28 @@ const MusicKitInterop = {
|
||||||
console.warn(`[mediaPlaybackError] ${e}`);
|
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 () {
|
getAttributes: function () {
|
||||||
const mk = MusicKit.getInstance()
|
const mk = MusicKit.getInstance()
|
||||||
const nowPlayingItem = mk.nowPlayingItem;
|
const nowPlayingItem = mk.nowPlayingItem;
|
||||||
|
@ -51,8 +73,8 @@ const MusicKitInterop = {
|
||||||
attributes.playParams = attributes?.playParams ?? {id: 'no-id-found'};
|
attributes.playParams = attributes?.playParams ?? {id: 'no-id-found'};
|
||||||
attributes.playParams.id = attributes?.playParams?.id ?? 'no-id-found';
|
attributes.playParams.id = attributes?.playParams?.id ?? 'no-id-found';
|
||||||
attributes.url = {
|
attributes.url = {
|
||||||
cider: `cider://play/s/${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 ?? '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') {
|
if (attributes.playParams.id === 'no-id-found') {
|
||||||
attributes.playParams.id = nowPlayingItem?.id ?? 'no-id-found';
|
attributes.playParams.id = nowPlayingItem?.id ?? 'no-id-found';
|
||||||
|
@ -69,7 +91,7 @@ const MusicKitInterop = {
|
||||||
attributes?.playParams?.id === cache.playParams.id
|
attributes?.playParams?.id === cache.playParams.id
|
||||||
? Date.now() + attributes?.remainingTime
|
? Date.now() + attributes?.remainingTime
|
||||||
: attributes?.startTime + attributes?.durationInMillis
|
: attributes?.startTime + attributes?.durationInMillis
|
||||||
);
|
);
|
||||||
return attributes;
|
return attributes;
|
||||||
},
|
},
|
||||||
|
|
||||||
|
|
|
@ -734,7 +734,7 @@ const app = new Vue({
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
}
|
}
|
||||||
if (!previewURL) {
|
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
|
previewURL = response.data.data[0].attributes.previews[0].url
|
||||||
if (previewURL)
|
if (previewURL)
|
||||||
ipcRenderer.send('getPreviewURL', previewURL)
|
ipcRenderer.send('getPreviewURL', previewURL)
|
||||||
|
@ -2298,12 +2298,12 @@ const app = new Vue({
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
loadAMLyrics() {
|
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);
|
// this.getMXM( trackName, artistName, 'en', duration);
|
||||||
if (songID != -1) {
|
if (songID != -1) {
|
||||||
MusicKit.getInstance().api.lyric(songID)
|
this.mk.api.v3.music(`v1/catalog/${this.mk.storefrontId}/songs/${songID}/lyrics`)
|
||||||
.then((response) => {
|
.then((response) => {
|
||||||
this.lyricsMediaItem = response.attributes["ttml"]
|
this.lyricsMediaItem = response.data?.data[0]?.attributes["ttml"]
|
||||||
this.parseTTML()
|
this.parseTTML()
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
@ -2329,7 +2329,7 @@ const app = new Vue({
|
||||||
},
|
},
|
||||||
|
|
||||||
async losslessBadge() {
|
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) {
|
if (app.cfg.advanced.ciderPPE && songID != -1) {
|
||||||
/**let extendedAssets = await app.mk.api.song(songID, {extend : 'extendedAssetUrls'})
|
/**let extendedAssets = await app.mk.api.song(songID, {extend : 'extendedAssetUrls'})
|
||||||
if (extendedAssets.attributes.audioTraits.includes('lossless')) {*/
|
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 track = encodeURIComponent((this.mk.nowPlayingItem != null) ? this.mk.nowPlayingItem.title ?? '' : '');
|
||||||
const artist = encodeURIComponent((this.mk.nowPlayingItem != null) ? this.mk.nowPlayingItem.artistName ?? '' : '');
|
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 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 lrcfile = "";
|
||||||
let richsync = [];
|
let richsync = [];
|
||||||
const lang = app.cfg.lyrics.mxm_language // translation language
|
const lang = app.cfg.lyrics.mxm_language // translation language
|
||||||
|
@ -3413,7 +3413,7 @@ const app = new Vue({
|
||||||
"icon": "./assets/feather/share.svg",
|
"icon": "./assets/feather/share.svg",
|
||||||
"name": app.getLz('action.share'),
|
"name": app.getLz('action.share'),
|
||||||
"action": function () {
|
"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)
|
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",
|
"icon": "./assets/feather/share.svg",
|
||||||
"name": `${app.getLz('action.share')} (song.link)`,
|
"name": `${app.getLz('action.share')} (song.link)`,
|
||||||
"action": function () {
|
"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)
|
app.songLinkShare((u.data.data.length && u.data.data.length > 0) ? u.data.data[0].attributes.url : u.data.data.attributes.url)
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
|
@ -23,12 +23,12 @@
|
||||||
<%- include("../svg/play.svg") %>
|
<%- include("../svg/play.svg") %>
|
||||||
</button>
|
</button>
|
||||||
</div>
|
</div>
|
||||||
<div v-if="!(app.mk.isPlaying && (((app.mk.nowPlayingItem._songId ?? app.mk.nowPlayingItem.id ) == item.attributes.playParams.id) || (app.mk.nowPlayingItem.id == item.id ))) && showIndex" :style="{display: ((showIndex && !showInLibrary) ? 'block' : 'none'), 'margin-left':'11px'}">
|
<div v-if="!(app.mk.isPlaying && (((app.mk.nowPlayingItem._songId ?? (app.mk.nowPlayingItem.songId ?? app.mk.nowPlayingItem.id )) == item.attributes.playParams.id) || (app.mk.nowPlayingItem.id == item.id ))) && showIndex" :style="{display: ((showIndex && !showInLibrary) ? 'block' : 'none'), 'margin-left':'11px'}">
|
||||||
<div>
|
<div>
|
||||||
<div>{{ (item.attributes && !showIndexPlaylist) ? (item.attributes.trackNumber ?? '') : ((index * 1 + 1 ) ?? '')}}</div>
|
<div>{{ (item.attributes && !showIndexPlaylist) ? (item.attributes.trackNumber ?? '') : ((index * 1 + 1 ) ?? '')}}</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div v-if="app.mk.isPlaying && (((app.mk.nowPlayingItem._songId ?? app.mk.nowPlayingItem.id ) == item.attributes.playParams.id) || (app.mk.nowPlayingItem.id == item.id))" :style="{display: (showInLibrary ? 'none' : 'block')}">
|
<div v-if="app.mk.isPlaying && (((app.mk.nowPlayingItem._songId ?? (app.mk.nowPlayingItem.songId ?? app.mk.nowPlayingItem.id )) == item.attributes.playParams.id) || (app.mk.nowPlayingItem.id == item.id))" :style="{display: (showInLibrary ? 'none' : 'block')}">
|
||||||
<div class="loadbar-sound"></div>
|
<div class="loadbar-sound"></div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue