From d4ada3ce431df9f87db01a90dbcd8da183f05a48 Mon Sep 17 00:00:00 2001 From: J0J0 Todos Date: Wed, 30 Aug 2023 10:20:34 +0200 Subject: [PATCH 1/6] Fix track-level genre handling in lastgenre plugin When `lastgenre.source: track` is configured, - `lastgenre -a` _should not_ fall back to the album level genre (by making use of the with_album=False kwarg of the Libary's get method). - `lastgenre -a`, when finally storing the genres of _an album_, should _not_ also write the tracks genres (by making use of the inherit=False kwarg of the Album's store method. --- beetsplug/lastgenre/__init__.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/beetsplug/lastgenre/__init__.py b/beetsplug/lastgenre/__init__.py index f86ac7bc19..d41dbab17a 100644 --- a/beetsplug/lastgenre/__init__.py +++ b/beetsplug/lastgenre/__init__.py @@ -411,7 +411,7 @@ def lastgenre_func(lib, opts, args): self._log.info( "genre for album {0} ({1}): {0.genre}", album, src ) - album.store() + album.store(inherit=False) for item in album.items(): # If we're using track-level sources, also look up each From 9ec2a8146f3c791b1dfec7d2221d5b0002311d7c Mon Sep 17 00:00:00 2001 From: J0J0 Todos Date: Sun, 21 May 2023 10:29:13 +0200 Subject: [PATCH 2/6] Streamline lastgenre singleton log with album log It was rather confusing that the lastgenre plugin, when handling singletons, sometimes showed that it applied genres from last.fm and sometimes didn't (it did only in debug log). This streamlines the behaviour: - Change debug to info log. - Streamline wording. - Display details about the track. --- beetsplug/lastgenre/__init__.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/beetsplug/lastgenre/__init__.py b/beetsplug/lastgenre/__init__.py index d41dbab17a..9cfd06aa8e 100644 --- a/beetsplug/lastgenre/__init__.py +++ b/beetsplug/lastgenre/__init__.py @@ -432,10 +432,10 @@ def lastgenre_func(lib, opts, args): # an album for item in lib.items(ui.decargs(args)): item.genre, src = self._get_genre(item) - self._log.debug( - "added last.fm item genre ({0}): {1}", src, item.genre - ) item.store() + self._log.info( + "genre for track {0} ({1}): {0.genre}", item, src + ) lastgenre_cmd.func = lastgenre_func return [lastgenre_cmd] From 18e76f08c73445a128c3cc191fbae4bdd32d4b43 Mon Sep 17 00:00:00 2001 From: J0J0 Todos Date: Sat, 4 Nov 2023 00:53:52 +0100 Subject: [PATCH 3/6] Prevent album genre inherit only when source:track is configured. --- beetsplug/lastgenre/__init__.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/beetsplug/lastgenre/__init__.py b/beetsplug/lastgenre/__init__.py index 9cfd06aa8e..ac1e556929 100644 --- a/beetsplug/lastgenre/__init__.py +++ b/beetsplug/lastgenre/__init__.py @@ -411,7 +411,10 @@ def lastgenre_func(lib, opts, args): self._log.info( "genre for album {0} ({1}): {0.genre}", album, src ) - album.store(inherit=False) + if "track" in self.sources: + album.store(inherit=False) + else: + album.store() for item in album.items(): # If we're using track-level sources, also look up each From 9d09d6f317490fb0a1694d106c870d4531e158e4 Mon Sep 17 00:00:00 2001 From: J0J0 Todos Date: Sat, 4 Nov 2023 10:08:56 +0100 Subject: [PATCH 4/6] Fix lastgenre source:track handling during imports --- beetsplug/lastgenre/__init__.py | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/beetsplug/lastgenre/__init__.py b/beetsplug/lastgenre/__init__.py index ac1e556929..d829180f1e 100644 --- a/beetsplug/lastgenre/__init__.py +++ b/beetsplug/lastgenre/__init__.py @@ -451,15 +451,20 @@ def imported(self, session, task): self._log.debug( "added last.fm album genre ({0}): {1}", src, album.genre ) - album.store() + # If we're using track-level sources, store the album genre only, + # then also look up individual track genres. if "track" in self.sources: + album.store(inherit=False) for item in album.items(): item.genre, src = self._get_genre(item) self._log.debug( "added last.fm item genre ({0}): {1}", src, item.genre ) item.store() + # Store the album genre and inherit to tracks. + else: + album.store() else: item = task.item From 0c10635ff7897f5c6a616496bbb09537bc339d5f Mon Sep 17 00:00:00 2001 From: J0J0 Todos Date: Sat, 4 Nov 2023 10:24:16 +0100 Subject: [PATCH 5/6] Another round of lastgenre logging nitpicks - Printing out album/item in default format could lead to unreadable clutter depending on the user's configured formats. - The album's name and the individual tracks' title should be just sufficient to provide context as well readability. - Log like this while importing as well as in standalone runs. --- beetsplug/lastgenre/__init__.py | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/beetsplug/lastgenre/__init__.py b/beetsplug/lastgenre/__init__.py index d829180f1e..0498c4c526 100644 --- a/beetsplug/lastgenre/__init__.py +++ b/beetsplug/lastgenre/__init__.py @@ -409,7 +409,9 @@ def lastgenre_func(lib, opts, args): for album in lib.albums(ui.decargs(args)): album.genre, src = self._get_genre(album) self._log.info( - "genre for album {0} ({1}): {0.genre}", album, src + 'genre for album "{0.album}" ({1}): {0.genre}', + album, + src, ) if "track" in self.sources: album.store(inherit=False) @@ -423,7 +425,7 @@ def lastgenre_func(lib, opts, args): item.genre, src = self._get_genre(item) item.store() self._log.info( - "genre for track {0} ({1}): {0.genre}", + 'genre for track "{0.title}" ({1}): {0.genre}', item, src, ) @@ -437,7 +439,7 @@ def lastgenre_func(lib, opts, args): item.genre, src = self._get_genre(item) item.store() self._log.info( - "genre for track {0} ({1}): {0.genre}", item, src + "genre for track {0.title} ({1}): {0.genre}", item, src ) lastgenre_cmd.func = lastgenre_func @@ -449,7 +451,7 @@ def imported(self, session, task): album = task.album album.genre, src = self._get_genre(album) self._log.debug( - "added last.fm album genre ({0}): {1}", src, album.genre + 'genre for album "{0.album}" ({1}): {0.genre}', album, src ) # If we're using track-level sources, store the album genre only, @@ -459,7 +461,9 @@ def imported(self, session, task): for item in album.items(): item.genre, src = self._get_genre(item) self._log.debug( - "added last.fm item genre ({0}): {1}", src, item.genre + 'genre for track "{0.title}" ({1}): {0.genre}', + item, + src, ) item.store() # Store the album genre and inherit to tracks. @@ -470,7 +474,9 @@ def imported(self, session, task): item = task.item item.genre, src = self._get_genre(item) self._log.debug( - "added last.fm item genre ({0}): {1}", src, item.genre + 'genre for track "{0.title}" ({1}): {0.genre}', + item, + src, ) item.store() From 55c0f7ad4c3edf6f31dcb61f4bd3d92aa2800a5c Mon Sep 17 00:00:00 2001 From: J0J0 Todos Date: Wed, 8 Jan 2025 07:55:16 +0100 Subject: [PATCH 6/6] Changelog for PR #5582 --- docs/changelog.rst | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/docs/changelog.rst b/docs/changelog.rst index d318b053a3..186749d461 100644 --- a/docs/changelog.rst +++ b/docs/changelog.rst @@ -33,6 +33,11 @@ Bug fixes: * :ref:`query-sort`: Fix a bug that would raise an exception when sorting on a non-string field that is not populated in all items. :bug:`5512` +* :doc:`plugins/lastgenre`: Fix track-level genre handling. Now when an album-level + genre is set already, single tracks don't fall back to the album's genre and + request their own last.fm genre. Also log messages regarding what's been + tagged are now more polished. + :bug:`5582` For packagers: