i hate lastfm

like really really
hate
it
This commit is contained in:
Core 2022-02-17 02:56:41 +00:00
parent cb82ff482d
commit 548688341d
No known key found for this signature in database
GPG key ID: FE9BF1B547F8F3C6
3 changed files with 20 additions and 13 deletions

View file

@ -69,9 +69,9 @@ ipcMain.on('nowPlayingItemDidChange', (_event, attributes) => {
CiderPlug.callPlugins('onNowPlayingItemDidChange', attributes); CiderPlug.callPlugins('onNowPlayingItemDidChange', attributes);
}); });
ipcMain.on('lfmItemChange', (_event, attributes) => { ipcMain.on('nowPlayingItemDidChangeLastFM', (_event, attributes) => {
CiderPlug.callPlugins('lfmItemChange', attributes); CiderPlug.callPlugin('lastfm', 'nowPlayingItemDidChangeLastFM', attributes);
}); })
app.on('before-quit', () => { app.on('before-quit', () => {
CiderPlug.callPlugins('onBeforeQuit'); CiderPlug.callPlugins('onBeforeQuit');

View file

@ -265,7 +265,7 @@ export default class LastFMPlugin {
* Runs on song change * Runs on song change
* @param attributes Music Attributes * @param attributes Music Attributes
*/ */
lfmItemChange(attributes: object): void { nowPlayingItemDidChangeLastFM(attributes: object): void {
if (!this._store.lastfm.filterLoop){ if (!this._store.lastfm.filterLoop){
this._lastfm.cachedNowPlayingAttributes = false; this._lastfm.cachedNowPlayingAttributes = false;
this._lastfm.cachedAttributes = false} this._lastfm.cachedAttributes = false}

View file

@ -7,9 +7,10 @@ let cache = {playParams: {id: 0}, status: null, remainingTime: 0},
const MusicKitInterop = { const MusicKitInterop = {
init: function () { init: function () {
MusicKit.getInstance().addEventListener(MusicKit.Events.playbackStateDidChange, () => { MusicKit.getInstance().addEventListener(MusicKit.Events.playbackStateDidChange, () => {
if (MusicKitInterop.filterTrack(MusicKitInterop.getAttributes(), true, false)) { const attributes = MusicKitInterop.getAttributes()
global.ipcRenderer.send('playbackStateDidChange', MusicKitInterop.getAttributes()) if (MusicKitInterop.filterTrack(attributes, true, false)) {
ipcRenderer.send('wsapi-updatePlaybackState', MusicKitInterop.getAttributes()); global.ipcRenderer.send('playbackStateDidChange', attributes)
ipcRenderer.send('wsapi-updatePlaybackState', attributes);
// if (typeof _plugins != "undefined") { // if (typeof _plugins != "undefined") {
// _plugins.execute("OnPlaybackStateChanged", {Attributes: MusicKitInterop.getAttributes()}) // _plugins.execute("OnPlaybackStateChanged", {Attributes: MusicKitInterop.getAttributes()})
// } // }
@ -23,12 +24,18 @@ const MusicKitInterop = {
/** wsapi */ /** wsapi */
MusicKit.getInstance().addEventListener(MusicKit.Events.nowPlayingItemDidChange, async () => { MusicKit.getInstance().addEventListener(MusicKit.Events.nowPlayingItemDidChange, async () => {
// await MusicKitInterop.modifyNamesOnLocale(); const attributes = MusicKitInterop.getAttributes()
if (MusicKitInterop.filterTrack(MusicKitInterop.getAttributes(), false, true) || !app.cfg.lastfm.filterLoop) { const trackFilter = MusicKitInterop.filterTrack(attributes, false, true)
global.ipcRenderer.send('lfmItemChange', MusicKitInterop.getAttributes());
if (trackFilter) {
global.ipcRenderer.send('nowPlayingItemDidChange', attributes);
} }
global.ipcRenderer.send('nowPlayingItemDidChange', MusicKitInterop.getAttributes()); // LastFM's Custom Call
// await MusicKitInterop.modifyNamesOnLocale();
if (trackFilter || !app.cfg.lastfm.filterLoop) {
global.ipcRenderer.send('nowPlayingItemDidChangeLastFM', attributes);
}
}); });
MusicKit.getInstance().addEventListener(MusicKit.Events.authorizationStatusDidChange, () => { MusicKit.getInstance().addEventListener(MusicKit.Events.authorizationStatusDidChange, () => {
@ -69,7 +76,7 @@ const MusicKitInterop = {
const attributes = (nowPlayingItem != null ? nowPlayingItem.attributes : {}); const attributes = (nowPlayingItem != null ? nowPlayingItem.attributes : {});
attributes.status = isPlayingExport ?? false; attributes.status = isPlayingExport ?? false;
attributes.name = attributes?.name ?? 'No Title Found'; attributes.name = attributes?.name ?? 'no-title-found';
attributes.artwork = attributes?.artwork ?? {url: ''}; attributes.artwork = attributes?.artwork ?? {url: ''};
attributes.artwork.url = (attributes?.artwork?.url ?? '').replace(`{f}`, "png"); attributes.artwork.url = (attributes?.artwork?.url ?? '').replace(`{f}`, "png");
attributes.playParams = attributes?.playParams ?? {id: 'no-id-found'}; attributes.playParams = attributes?.playParams ?? {id: 'no-id-found'};
@ -98,7 +105,7 @@ const MusicKitInterop = {
}, },
filterTrack: function (a, playbackCheck, mediaCheck) { filterTrack: function (a, playbackCheck, mediaCheck) {
if (a.title === "No Title Found" || a.playParams.id === "no-id-found") { if (a.name === 'no-title-found' || a.playParams.id === "no-id-found") {
return; return;
} else if (mediaCheck && a.playParams.id === cache.playParams.id) { } else if (mediaCheck && a.playParams.id === cache.playParams.id) {
return; return;