Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 5 additions & 9 deletions beetsplug/lastgenre/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -480,15 +480,11 @@ def _try_resolve_stage(

# 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"
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
# Process existing genres to apply whitelist and canonicalization
if result := _try_resolve_stage(
"original fallback", keep_genres, []
):
return result

# Return fallback string.
if fallback := self.config["fallback"].get():
Expand Down
2 changes: 2 additions & 0 deletions beetsplug/lastgenre/genres-tree.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -791,3 +791,5 @@
- world fusion
- worldbeat

- '':
- blacklisted genre
2 changes: 2 additions & 0 deletions docs/changelog.rst
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ Bug fixes
- :doc:`plugins/musicbrainz`: Fix fetching very large releases that have more
than 500 tracks. :bug:`6355`
- :doc:`plugins/badfiles`: Fix number of found errors in log message
- :doc:`plugins/lastgenre`: Apply canonicalization to genres of items with no
Last.fm results

..
For plugin developers
Expand Down
24 changes: 22 additions & 2 deletions test/plugins/test_lastgenre.py
Original file line number Diff line number Diff line change
Expand Up @@ -338,7 +338,7 @@ def test_sort_by_depth(self):
"album": None,
"artist": None,
},
("any existing", "original fallback"),
("Any Existing", "keep + original fallback, any"),
),
# 7.1 - Keep the original genre when force and keep_existing are on, and
# whitelist is enabled, and genre is valid.
Expand All @@ -358,7 +358,7 @@ def test_sort_by_depth(self):
"album": None,
"artist": None,
},
("Jazz", "original fallback"),
("Jazz", "keep + original fallback, whitelist"),
),
# 7.2 - Return the configured fallback when force is on but
# keep_existing is not.
Expand All @@ -380,6 +380,26 @@ def test_sort_by_depth(self):
},
("fallback genre", "fallback"),
),
# 7.3 - Filter out genres that map to an empty string in tree when
# keep_existing is enabled and no Last.fm results are found
(
{
"force": True,
"keep_existing": True,
"source": "track",
"whitelist": False,
"fallback": "fallback genre",
"canonical": True,
"prefer_specific": False,
},
"blacklisted genre",
{
"track": None,
"album": None,
"artist": None,
},
("fallback genre", "fallback"),
),
# 8 - fallback to fallback if no original
(
{
Expand Down
Loading