From 0fb6802ff35ad9cfd03e3ce50f4de768cdba750c Mon Sep 17 00:00:00 2001 From: Core <64542347+coredev-uk@users.noreply.github.com> Date: Thu, 17 Feb 2022 03:02:16 +0000 Subject: [PATCH] Revert "Merge remote-tracking branch 'origin/develop' into develop" This reverts commit 5b360e74faf937a6e54fda80e5851fc36707a528, reversing changes made to 548688341d953bd5cfe5f27b32a60fcc8b338c08. --- src/main/plugins/lastfm.ts | 77 ++++++++++++++++++-------------------- 1 file changed, 37 insertions(+), 40 deletions(-) diff --git a/src/main/plugins/lastfm.ts b/src/main/plugins/lastfm.ts index c5222203..ea66bb2c 100644 --- a/src/main/plugins/lastfm.ts +++ b/src/main/plugins/lastfm.ts @@ -79,47 +79,46 @@ export default class LastFMPlugin { } private scrobbleSong(attributes: any) { - if (this._timer) clearTimeout(this._timer); + if(this._timer) clearTimeout(this._timer); var self = this; this._timer = setTimeout(async () => { - const currentAttributes = attributes; + const currentAttributes = attributes; - if (!self._lastfm || self._lastfm.cachedAttributes === attributes) { - return - } + if (!self._lastfm || self._lastfm.cachedAttributes === attributes) { + return + } - if (self._lastfm.cachedAttributes) { - if (self._lastfm.cachedAttributes.playParams.id === attributes.playParams.id) return; - } + if (self._lastfm.cachedAttributes) { + if (self._lastfm.cachedAttributes.playParams.id === attributes.playParams.id) return; + } - const artist = await this.getPrimaryArtist(attributes) + const artist = await this.getPrimaryArtist(attributes) - if (currentAttributes.status && currentAttributes === attributes) { - if (fs.existsSync(this.sessionPath)) { - // Scrobble playing song. - if (attributes.status === true) { - self._lastfm.track.scrobble({ - 'artist': artist, - 'track': attributes.name, - 'album': attributes.albumName, - 'albumArtist': artist, - 'timestamp': new Date().getTime() / 1000 - }, function (err: any, scrobbled: any) { - if (err) { - return console.error('[LastFM] An error occurred while scrobbling', err); - } + if (currentAttributes.status && currentAttributes === attributes) { + if (fs.existsSync(this.sessionPath)) { + // Scrobble playing song. + if (attributes.status === true) { + self._lastfm.track.scrobble({ + 'artist': artist, + 'track': attributes.name, + 'album': attributes.albumName, + 'albumArtist': artist, + 'timestamp': new Date().getTime() / 1000 + }, function (err: any, scrobbled: any) { + if (err) { + return console.error('[LastFM] An error occurred while scrobbling', err); + } - console.log('[LastFM] Successfully scrobbled: ', scrobbled); - }); - self._lastfm.cachedAttributes = attributes - } - } else { - self.authenticate(); + console.log('[LastFM] Successfully scrobbled: ', scrobbled); + }); + self._lastfm.cachedAttributes = attributes } } else { - return console.log('[LastFM] Did not add ', attributes.name, '—', artist, 'because now playing a other song.'); + self.authenticate(); } - }, Math.round(attributes.durationInMillis * (self._store.lastfm.scrobble_after / 100))); + } else { + return console.log('[LastFM] Did not add ', attributes.name, '—', artist, 'because now playing a other song.'); + }},Math.round(attributes.durationInMillis * (self._store.lastfm.scrobble_after / 100))); } private async updateNowPlayingSong(attributes: any) { @@ -156,7 +155,7 @@ export default class LastFMPlugin { } } - private async getPrimaryArtist(attributes: any) { + private async getPrimaryArtist (attributes: any) { const songId = attributes.playParams.catalogId || attributes.playParams.id if (!this._store.lastfm.enabledRemoveFeaturingArtists || !songId) return attributes.artistName; @@ -259,21 +258,19 @@ export default class LastFMPlugin { */ onPlaybackStateDidChange(attributes: object): void { this.updateNowPlayingSong(attributes) - // this.scrobbleSong(attributes) + this.scrobbleSong(attributes) } /** * Runs on song change * @param attributes Music Attributes */ - lfmItemChange(attributes: any): void { - attributes.status = true - if (!this._store.lastfm.filterLoop) { + nowPlayingItemDidChangeLastFM(attributes: object): void { + if (!this._store.lastfm.filterLoop){ this._lastfm.cachedNowPlayingAttributes = false; - this._lastfm.cachedAttributes = false - } - this.updateNowPlayingSong(attributes) - this.scrobbleSong(attributes) + this._lastfm.cachedAttributes = false} + this.updateNowPlayingSong(attributes) + this.scrobbleSong(attributes) } }