simplify check for fallback in beetsplug/lastgenre/__init__.py

Co-authored-by: Šarūnas Nejus <snejus@protonmail.com>
This commit is contained in:
dunkla 2025-12-28 15:12:32 +01:00 committed by Šarūnas Nejus
parent fe562f4009
commit f2af5f8778
No known key found for this signature in database

View file

@ -473,22 +473,15 @@ class LastGenrePlugin(plugins.BeetsPlugin):
return result
# Nothing found, leave original if configured and valid.
if obj.genre and self.config["keep_existing"]:
# Check if at least one genre is valid
valid_genres = [
g
for g in genres
if not self.whitelist or self._is_valid(g.lower())
]
if valid_genres:
if genres and self.config["keep_existing"]:
if valid_genres := self._filter_valid(genres):
return valid_genres, "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
# 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 as a list.
if fallback := self.config["fallback"].get():
@ -505,7 +498,6 @@ class LastGenrePlugin(plugins.BeetsPlugin):
obj.genres, label = self._get_genre(obj)
self._log.debug("Resolved ({}): {}", label, obj.genres)
ui.show_model_changes(obj, fields=["genres"], print_obj=False)
@singledispatchmethod