lastgenre: Fix "original fallback" conditions

This was not thought through clearly before. It now behaves as follows
which I suppose is least surprising to a user:

- force is on, keep_existing is on, but the whitelist is DISABLED
- no stage found anything on last.fm
- fall back to the original genre

If in this example the whitelist would be ENABLED, the behaviour
changes: Only if the existing genre passes the whitelist test the
original is kept.
This commit is contained in:
J0J0 Todos 2025-03-27 23:23:39 +01:00
parent de9020055d
commit eb83491788
2 changed files with 47 additions and 5 deletions

View file

@ -441,11 +441,12 @@ class LastGenrePlugin(plugins.BeetsPlugin):
label = f"keep + {label}"
return self._format_and_stringify(resolved_genres), label
# Nothing found, leave original.
if obj.genre:
return obj.genre, "original fallback"
# Nothing found, leave original if configured and valid.
if obj.genre and self.config["keep_existing"]:
if not self.whitelist or self._is_valid(obj.genre.lower()):
return obj.genre, "original fallback"
# No original, return fallback string.
# Return fallback string.
if fallback := self.config["fallback"].get():
return fallback, "fallback"

View file

@ -292,7 +292,8 @@ class LastGenrePluginTest(BeetsTestCase):
},
("Unknown Genre, Jazz", "keep + artist, any"),
),
# 7 - fallback to any original when nothing found and whitelist disabled
# 7 - Keep the original genre when force and keep_existing are on, and
# whitelist is disabled
(
{
"force": True,
@ -303,6 +304,46 @@ class LastGenrePluginTest(BeetsTestCase):
"canonical": False,
"prefer_specific": False,
},
"any existing",
{
"track": None,
"album": None,
"artist": None,
},
("any existing", "original fallback"),
),
# 7.1 - Keep the original genre when force and keep_existing are on, and
# whitelist is enabled, and genre is valid.
(
{
"force": True,
"keep_existing": True,
"source": "track",
"whitelist": True,
"fallback": "fallback genre",
"canonical": False,
"prefer_specific": False,
},
"Jazz",
{
"track": None,
"album": None,
"artist": None,
},
("Jazz", "original fallback"),
),
# 7.2 - Return the configured fallback when force is on but
# keep_existing is not.
(
{
"force": True,
"keep_existing": False,
"source": "track",
"whitelist": True,
"fallback": "fallback genre",
"canonical": False,
"prefer_specific": False,
},
"Jazz",
{
"track": None,