mirror of
https://github.com/beetbox/beets.git
synced 2026-03-26 15:24:05 +01:00
lastgenre: Dedup fallback handling in _get_genre
and fix fallback types
This commit is contained in:
parent
4c5f4c84b9
commit
c17eebb16e
1 changed files with 9 additions and 9 deletions
|
|
@ -460,6 +460,12 @@ class LastGenrePlugin(plugins.BeetsPlugin):
|
|||
and the whitelist feature was disabled.
|
||||
"""
|
||||
|
||||
def _fallback_stage() -> tuple[list[str], str]:
|
||||
"""Return the fallback genre and label."""
|
||||
if fallback := self.config["fallback"].get():
|
||||
return [fallback], "fallback"
|
||||
return [], "fallback unconfigured"
|
||||
|
||||
def _try_resolve_stage(
|
||||
stage_label: str,
|
||||
keep_genres: list[str],
|
||||
|
|
@ -496,8 +502,7 @@ class LastGenrePlugin(plugins.BeetsPlugin):
|
|||
):
|
||||
return result
|
||||
|
||||
# Return fallback string (None if not set).
|
||||
return self.config["fallback"].get(), "fallback"
|
||||
return _fallback_stage()
|
||||
|
||||
# If cleanup_existing is not set, the pre-populated tags are
|
||||
# returned as-is.
|
||||
|
|
@ -587,7 +592,7 @@ class LastGenrePlugin(plugins.BeetsPlugin):
|
|||
return result
|
||||
|
||||
# Nothing found, leave original if configured and valid.
|
||||
if genres and self.config["keep_existing"].get(bool):
|
||||
if genres and self.config["keep_existing"].get():
|
||||
if isinstance(obj, library.Item):
|
||||
# For track items, use track artist (important for compilations).
|
||||
artist = getattr(obj, "artist", None)
|
||||
|
|
@ -605,12 +610,7 @@ class LastGenrePlugin(plugins.BeetsPlugin):
|
|||
):
|
||||
return result
|
||||
|
||||
# Return fallback as a list.
|
||||
if fallback := self.config["fallback"].get():
|
||||
return [fallback], "fallback"
|
||||
|
||||
# No fallback configured.
|
||||
return [], "fallback unconfigured"
|
||||
return _fallback_stage()
|
||||
|
||||
# Beets plugin hooks and CLI.
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue