Skip to content

Commit

Permalink
Refactor/rename existing genres finalize method
Browse files Browse the repository at this point in the history
  • Loading branch information
JOJ0 committed Jan 13, 2025
1 parent fee1c90 commit 5f85506
Showing 1 changed file with 14 additions and 10 deletions.
24 changes: 14 additions & 10 deletions beetsplug/lastgenre/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -323,15 +323,19 @@ def _get_existing_genres(self, obj, separator):
return item_genre
return []

def _dedup_genres(self, genres, whitelist_only=False):
"""Return a list of deduplicated genres. Depending on the
whitelist_only option, gives filtered or unfiltered results.
Makes sure genres are handled all lower case."""
if whitelist_only:
return unique_list(
[g.lower() for g in genres if self._is_valid(g)]
)
return unique_list([g.lower() for g in genres])
def _polish_existing_genres(self, genres, whitelist_only=False):
"""Return a list of deduplicated and formatted genres. Depending on the
whitelist_only option, gives filtered or unfiltered results."""
valid_genres = unique_list(
[
g.lower()
for g in genres
if not whitelist_only or self._is_valid(g)
]
)
if self.config["title_case"]:
return [g.title() for g in valid_genres]
return valid_genres

def _combine_genres(self, old: list[str], new: list[str]) -> str | None:

Check failure on line 340 in beetsplug/lastgenre/__init__.py

View workflow job for this annotation

GitHub Actions / Check types with mypy

X | Y syntax for unions requires Python 3.10
"""Combine old and new genres."""
Expand Down Expand Up @@ -368,7 +372,7 @@ def _get_genre(self, obj) -> str | None:
genres = self._get_existing_genres(obj, separator)
if genres and not self.config["force"]:
# Without force pre-populated tags are deduplicated and returned.
keep_genres = self._dedup_genres(genres)
keep_genres = self._polish_existing_genres(genres)
return separator.join(keep_genres), "keep"

Check failure on line 376 in beetsplug/lastgenre/__init__.py

View workflow job for this annotation

GitHub Actions / Check types with mypy

Incompatible return value type (got "tuple[Any, str]", expected "Optional[str]")

if self.config["force"]:
Expand Down

0 comments on commit 5f85506

Please sign in to comment.