From 1f7f2e2174d4f906867abf47e18a475245363dd4 Mon Sep 17 00:00:00 2001 From: inalone Date: Tue, 22 Feb 2022 01:22:00 +0000 Subject: [PATCH 1/3] last.fm: initial implementation of filterAlbumName --- src/i18n/en_US.json | 1 + src/main/base/store.ts | 1 + src/main/plugins/lastfm.ts | 12 ++++++++++-- src/renderer/views/pages/settings.ejs | 9 ++++++++- 4 files changed, 20 insertions(+), 3 deletions(-) diff --git a/src/i18n/en_US.json b/src/i18n/en_US.json index 5a7043ff..24b9639f 100644 --- a/src/i18n/en_US.json +++ b/src/i18n/en_US.json @@ -331,6 +331,7 @@ "settings.option.connectivity.lastfmScrobble.delay": "Last.fm Scrobble Delay (%)", "settings.option.connectivity.lastfmScrobble.nowPlaying": "Enable Last.fm Now Playing", "settings.option.connectivity.lastfmScrobble.removeFeatured": "Remove featuring artists from song title (Last.fm)", + "settings.option.connectivity.lastfmScrobble.filterAlbumName": "Filter attributes from album name (Last.fm)", "settings.option.connectivity.lastfmScrobble.filterLoop": "Filter looped track (Last.fm)", "settings.header.debug": "Debug", "settings.option.debug.copy_log": "Copy logs to clipboard", diff --git a/src/main/base/store.ts b/src/main/base/store.ts index 4436b3fc..20cca9a3 100644 --- a/src/main/base/store.ts +++ b/src/main/base/store.ts @@ -103,6 +103,7 @@ export class Store { "scrobble_after": 30, "auth_token": "", "enabledRemoveFeaturingArtists": true, + "filterAlbumName": false, "filterLoop": true, "NowPlaying": "true" }, diff --git a/src/main/plugins/lastfm.ts b/src/main/plugins/lastfm.ts index a7433b8b..2ca26892 100644 --- a/src/main/plugins/lastfm.ts +++ b/src/main/plugins/lastfm.ts @@ -101,7 +101,7 @@ export default class LastFMPlugin { self._lastfm.track.scrobble({ 'artist': artist, 'track': attributes.name, - 'album': attributes.albumName, + 'album': this.getAlbumName(attributes), 'albumArtist': artist, 'timestamp': new Date().getTime() / 1000 }, function (err: any, scrobbled: any) { @@ -139,7 +139,7 @@ export default class LastFMPlugin { this._lastfm.track.updateNowPlaying({ 'artist': artist, 'track': attributes.name, - 'album': attributes.albumName, + 'album': this.getAlbumName(attributes), 'albumArtist': artist }, function (err: any, nowPlaying: any) { if (err) { @@ -156,6 +156,14 @@ export default class LastFMPlugin { } } + private getAlbumName(attributes: any): string { + if (!this._store.lastfm.filterAlbumName) { + return attributes.albumName; + } + + return attributes.albumName.replace(/ - Single| - EP/g, ''); + } + private async getPrimaryArtist(attributes: any) { const songId = attributes.playParams.catalogId || attributes.playParams.id diff --git a/src/renderer/views/pages/settings.ejs b/src/renderer/views/pages/settings.ejs index 2b85851c..7c1964e3 100644 --- a/src/renderer/views/pages/settings.ejs +++ b/src/renderer/views/pages/settings.ejs @@ -606,6 +606,14 @@ +
+
+ {{$root.getLz('settings.option.connectivity.lastfmScrobble.filterAlbumName')}} +
+
+ +
+
{{$root.getLz('settings.option.connectivity.lastfmScrobble.filterLoop')}} @@ -617,7 +625,6 @@
-
{{$root.getLz('settings.header.debug')}}
From 68a28c0baba6a1c8f08380cdd5f6f049ce18cef3 Mon Sep 17 00:00:00 2001 From: inalone <60921914+inalone@users.noreply.github.com> Date: Tue, 22 Feb 2022 11:03:18 +0000 Subject: [PATCH 2/3] last.fm: made removing attributes from album default behaviour --- src/i18n/en_US.json | 1 - src/main/base/store.ts | 1 - src/main/plugins/lastfm.ts | 10 ++++------ src/renderer/views/pages/settings.ejs | 8 -------- 4 files changed, 4 insertions(+), 16 deletions(-) diff --git a/src/i18n/en_US.json b/src/i18n/en_US.json index 24b9639f..5a7043ff 100644 --- a/src/i18n/en_US.json +++ b/src/i18n/en_US.json @@ -331,7 +331,6 @@ "settings.option.connectivity.lastfmScrobble.delay": "Last.fm Scrobble Delay (%)", "settings.option.connectivity.lastfmScrobble.nowPlaying": "Enable Last.fm Now Playing", "settings.option.connectivity.lastfmScrobble.removeFeatured": "Remove featuring artists from song title (Last.fm)", - "settings.option.connectivity.lastfmScrobble.filterAlbumName": "Filter attributes from album name (Last.fm)", "settings.option.connectivity.lastfmScrobble.filterLoop": "Filter looped track (Last.fm)", "settings.header.debug": "Debug", "settings.option.debug.copy_log": "Copy logs to clipboard", diff --git a/src/main/base/store.ts b/src/main/base/store.ts index 20cca9a3..4436b3fc 100644 --- a/src/main/base/store.ts +++ b/src/main/base/store.ts @@ -103,7 +103,6 @@ export class Store { "scrobble_after": 30, "auth_token": "", "enabledRemoveFeaturingArtists": true, - "filterAlbumName": false, "filterLoop": true, "NowPlaying": "true" }, diff --git a/src/main/plugins/lastfm.ts b/src/main/plugins/lastfm.ts index 2ca26892..f35befa6 100644 --- a/src/main/plugins/lastfm.ts +++ b/src/main/plugins/lastfm.ts @@ -93,6 +93,7 @@ export default class LastFMPlugin { } const artist = await this.getPrimaryArtist(attributes) + const album = this.getAlbumName(attributes) if (currentAttributes.status && currentAttributes === attributes) { if (fs.existsSync(this.sessionPath)) { @@ -101,7 +102,7 @@ export default class LastFMPlugin { self._lastfm.track.scrobble({ 'artist': artist, 'track': attributes.name, - 'album': this.getAlbumName(attributes), + 'album': album, 'albumArtist': artist, 'timestamp': new Date().getTime() / 1000 }, function (err: any, scrobbled: any) { @@ -133,13 +134,14 @@ export default class LastFMPlugin { if (fs.existsSync(this.sessionPath)) { const artist = await this.getPrimaryArtist(attributes) + const album = this.getAlbumName(attributes) // update Now Playing if (attributes.status === true) { this._lastfm.track.updateNowPlaying({ 'artist': artist, 'track': attributes.name, - 'album': this.getAlbumName(attributes), + 'album': album, 'albumArtist': artist }, function (err: any, nowPlaying: any) { if (err) { @@ -157,10 +159,6 @@ export default class LastFMPlugin { } private getAlbumName(attributes: any): string { - if (!this._store.lastfm.filterAlbumName) { - return attributes.albumName; - } - return attributes.albumName.replace(/ - Single| - EP/g, ''); } diff --git a/src/renderer/views/pages/settings.ejs b/src/renderer/views/pages/settings.ejs index 7c1964e3..dc09e212 100644 --- a/src/renderer/views/pages/settings.ejs +++ b/src/renderer/views/pages/settings.ejs @@ -606,14 +606,6 @@
-
-
- {{$root.getLz('settings.option.connectivity.lastfmScrobble.filterAlbumName')}} -
-
- -
-
{{$root.getLz('settings.option.connectivity.lastfmScrobble.filterLoop')}} From 637427309e96a0f0ff43df6489114b60f0b936c5 Mon Sep 17 00:00:00 2001 From: vapormusic Date: Tue, 22 Feb 2022 20:00:35 +0700 Subject: [PATCH 3/3] Update settings.ejs --- src/renderer/views/pages/settings.ejs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/renderer/views/pages/settings.ejs b/src/renderer/views/pages/settings.ejs index dc09e212..6c2ae392 100644 --- a/src/renderer/views/pages/settings.ejs +++ b/src/renderer/views/pages/settings.ejs @@ -617,6 +617,7 @@
+
{{$root.getLz('settings.header.debug')}}
@@ -888,4 +889,4 @@ } } }) - \ No newline at end of file +