fix(lastgenre): Canonicalize keep_existing fallback (#6303)

This commit is contained in:
J0J0 Todos 2026-01-31 13:27:35 +01:00 committed by GitHub
commit a327c28470
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 35 additions and 0 deletions

View file

@ -482,6 +482,13 @@ class LastGenrePlugin(plugins.BeetsPlugin):
if obj.genre and self.config["keep_existing"]:
if not self.whitelist or self._is_valid(obj.genre.lower()):
return obj.genre, "original fallback"
else:
# If the original genre doesn't match a whitelisted genre, check
# if we can canonicalize it to find a matching, whitelisted genre!
if result := _try_resolve_stage(
"original fallback", keep_genres, []
):
return result
# Return fallback string.
if fallback := self.config["fallback"].get():

View file

@ -57,6 +57,9 @@ New features:
Bug fixes:
- :doc:`/plugins/lastgenre`: Canonicalize genres when ``force`` and
``keep_existing`` are ``on``, yet no genre info on lastfm could be found.
:bug:`6303`
- Handle potential OSError when unlinking temporary files in ArtResizer.
:bug:`5615`
- :doc:`/plugins/spotify`: Updated Spotify API credentials. :bug:`6270`

View file

@ -541,6 +541,31 @@ class LastGenrePluginTest(PluginTestCase):
"keep + album, whitelist",
),
),
# 16 - canonicalization transforms non-whitelisted original genres to canonical
# forms and deduplication works, **even** when no new genres are found online.
#
# "Cosmic Disco" is not in the default whitelist, thus gets resolved "up" in the
# tree to "Disco" and "Electronic".
(
{
"force": True,
"keep_existing": True,
"source": "album",
"whitelist": True,
"canonical": True,
"prefer_specific": False,
"count": 10,
},
"Cosmic Disco",
{
"album": [],
"artist": [],
},
(
"Disco, Electronic",
"keep + original fallback, whitelist",
),
),
],
)
def test_get_genre(config_values, item_genre, mock_genres, expected_result):