Fixed remove primary artist stuff for lastfm
This commit is contained in:
parent
1fe3fb1b98
commit
9eea5d3561
1 changed files with 26 additions and 8 deletions
|
@ -22,7 +22,7 @@ const MusicKitInterop = {
|
||||||
ipcRenderer.send("wsapi-updatePlaybackState", attributes);
|
ipcRenderer.send("wsapi-updatePlaybackState", attributes);
|
||||||
// lastfm call
|
// lastfm call
|
||||||
if (app.mk.currentPlaybackProgress === app.cfg.connectivity.lastfm.scrobble_after / 100) {
|
if (app.mk.currentPlaybackProgress === app.cfg.connectivity.lastfm.scrobble_after / 100) {
|
||||||
attributes.primaryArtist = app.cfg.connectivity.lastfm.enabled && app.cfg.connectivity.lastfm.remove_featured ? await this.fetchPrimaryArtist(attributes.artistName) : attributes.artistName;
|
attributes.primaryArtist = app.cfg.connectivity.lastfm.remove_featured ? await this.fetchPrimaryArtist() : attributes.artistName;
|
||||||
ipcRenderer.send("lastfm:scrobbleTrack", attributes);
|
ipcRenderer.send("lastfm:scrobbleTrack", attributes);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
@ -36,7 +36,7 @@ const MusicKitInterop = {
|
||||||
MusicKit.getInstance().addEventListener(MusicKit.Events.nowPlayingItemDidChange, async () => {
|
MusicKit.getInstance().addEventListener(MusicKit.Events.nowPlayingItemDidChange, async () => {
|
||||||
console.debug("[cider:preload] nowPlayingItemDidChange");
|
console.debug("[cider:preload] nowPlayingItemDidChange");
|
||||||
const attributes = MusicKitInterop.getAttributes();
|
const attributes = MusicKitInterop.getAttributes();
|
||||||
attributes.primaryArtist = app.cfg.connectivity.lastfm.enabled && app.cfg.connectivity.lastfm.remove_featured ? await this.fetchPrimaryArtist(attributes.artistName) : attributes.artistName;
|
attributes.primaryArtist = app.cfg.connectivity.lastfm.remove_featured ? await this.fetchPrimaryArtist() : attributes.artistName;
|
||||||
|
|
||||||
if (MusicKitInterop.filterTrack(attributes, false, true)) {
|
if (MusicKitInterop.filterTrack(attributes, false, true)) {
|
||||||
global.ipcRenderer.send("nowPlayingItemDidChange", attributes);
|
global.ipcRenderer.send("nowPlayingItemDidChange", attributes);
|
||||||
|
@ -81,13 +81,31 @@ const MusicKitInterop = {
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
|
|
||||||
async fetchPrimaryArtist(artist) {
|
async fetchPrimaryArtist() {
|
||||||
if (app.mk.nowPlayingItem?.relationships?.artists) {
|
const songID = app.mk.nowPlayingItem.attributes.playParams.catalogId || app.mk.nowPlayingItem.attributes.playParams.id
|
||||||
const artist = await app.mk.api.artist(app.mk.nowPlayingItem.relationships.artists.data[0].id);
|
const res = await MusicKit.getInstance().api.v3.music("/v1/catalog/" + MusicKit.getInstance().storefrontId + `/songs/${songID}`, {
|
||||||
return artist.attributes.name;
|
include: {
|
||||||
} else {
|
songs: ["artists"]
|
||||||
return artist;
|
}
|
||||||
|
})
|
||||||
|
if (!res || !res.data) {
|
||||||
|
console.warn("[cider:preload] fetchPrimaryArtist: no response");
|
||||||
|
return app.mk.nowPlayingItem.attributes.artistName;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (!res.data.data.length) {
|
||||||
|
console.error(`[cider:preload] fetchPrimaryArtist: Unable to locate song with id of ${songID}`)
|
||||||
|
return app.mk.nowPlayingItem.attributes.artistName;
|
||||||
|
}
|
||||||
|
const songData = res.data.data[0]
|
||||||
|
const artistData = songData.relationships.artists.data
|
||||||
|
if (artistData.length < 1) {
|
||||||
|
console.error(`[cider:preload] fetchPrimaryArtist: Unable to find artists related to the song with id of ${songID}`)
|
||||||
|
return app.mk.nowPlayingItem.attributes.artistName;
|
||||||
|
}
|
||||||
|
|
||||||
|
const primaryArtist = artistData[0]
|
||||||
|
return primaryArtist.attributes.name
|
||||||
},
|
},
|
||||||
|
|
||||||
getAttributes: function () {
|
getAttributes: function () {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue