Revert "Revert "Merge remote-tracking branch 'origin/develop' into develop""

This reverts commit 0fb6802ff3.
This commit is contained in:
Core 2022-02-17 03:06:27 +00:00
parent bd3a2b6172
commit 35aa69c2d6
No known key found for this signature in database
GPG key ID: FE9BF1B547F8F3C6

View file

@ -79,46 +79,47 @@ export default class LastFMPlugin {
} }
private scrobbleSong(attributes: any) { private scrobbleSong(attributes: any) {
if(this._timer) clearTimeout(this._timer); if (this._timer) clearTimeout(this._timer);
var self = this; var self = this;
this._timer = setTimeout(async () => { this._timer = setTimeout(async () => {
const currentAttributes = attributes; const currentAttributes = attributes;
if (!self._lastfm || self._lastfm.cachedAttributes === attributes) { if (!self._lastfm || self._lastfm.cachedAttributes === attributes) {
return return
} }
if (self._lastfm.cachedAttributes) { if (self._lastfm.cachedAttributes) {
if (self._lastfm.cachedAttributes.playParams.id === attributes.playParams.id) return; 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 (currentAttributes.status && currentAttributes === attributes) {
if (fs.existsSync(this.sessionPath)) { if (fs.existsSync(this.sessionPath)) {
// Scrobble playing song. // Scrobble playing song.
if (attributes.status === true) { if (attributes.status === true) {
self._lastfm.track.scrobble({ self._lastfm.track.scrobble({
'artist': artist, 'artist': artist,
'track': attributes.name, 'track': attributes.name,
'album': attributes.albumName, 'album': attributes.albumName,
'albumArtist': artist, 'albumArtist': artist,
'timestamp': new Date().getTime() / 1000 'timestamp': new Date().getTime() / 1000
}, function (err: any, scrobbled: any) { }, function (err: any, scrobbled: any) {
if (err) { if (err) {
return console.error('[LastFM] An error occurred while scrobbling', err); return console.error('[LastFM] An error occurred while scrobbling', err);
} }
console.log('[LastFM] Successfully scrobbled: ', scrobbled); console.log('[LastFM] Successfully scrobbled: ', scrobbled);
}); });
self._lastfm.cachedAttributes = attributes self._lastfm.cachedAttributes = attributes
}
} else {
self.authenticate();
} }
} else { } else {
self.authenticate(); return console.log('[LastFM] Did not add ', attributes.name, '—', artist, 'because now playing a other song.');
} }
} else { }, Math.round(attributes.durationInMillis * (self._store.lastfm.scrobble_after / 100)));
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) { private async updateNowPlayingSong(attributes: any) {
@ -155,7 +156,7 @@ export default class LastFMPlugin {
} }
} }
private async getPrimaryArtist (attributes: any) { private async getPrimaryArtist(attributes: any) {
const songId = attributes.playParams.catalogId || attributes.playParams.id const songId = attributes.playParams.catalogId || attributes.playParams.id
if (!this._store.lastfm.enabledRemoveFeaturingArtists || !songId) return attributes.artistName; if (!this._store.lastfm.enabledRemoveFeaturingArtists || !songId) return attributes.artistName;
@ -258,19 +259,21 @@ export default class LastFMPlugin {
*/ */
onPlaybackStateDidChange(attributes: object): void { onPlaybackStateDidChange(attributes: object): void {
this.updateNowPlayingSong(attributes) this.updateNowPlayingSong(attributes)
this.scrobbleSong(attributes) // this.scrobbleSong(attributes)
} }
/** /**
* Runs on song change * Runs on song change
* @param attributes Music Attributes * @param attributes Music Attributes
*/ */
nowPlayingItemDidChangeLastFM(attributes: object): void { lfmItemChange(attributes: any): void {
if (!this._store.lastfm.filterLoop){ attributes.status = true
if (!this._store.lastfm.filterLoop) {
this._lastfm.cachedNowPlayingAttributes = false; this._lastfm.cachedNowPlayingAttributes = false;
this._lastfm.cachedAttributes = false} this._lastfm.cachedAttributes = false
this.updateNowPlayingSong(attributes) }
this.scrobbleSong(attributes) this.updateNowPlayingSong(attributes)
this.scrobbleSong(attributes)
} }
} }