From 5f855061d776239c6f4ff8c29e0d6a06cea18204 Mon Sep 17 00:00:00 2001 From: J0J0 Todos Date: Mon, 13 Jan 2025 23:06:01 +0100 Subject: [PATCH] Refactor/rename existing genres finalize method --- beetsplug/lastgenre/__init__.py | 24 ++++++++++++++---------- 1 file changed, 14 insertions(+), 10 deletions(-) diff --git a/beetsplug/lastgenre/__init__.py b/beetsplug/lastgenre/__init__.py index 475c87f745..2ac8a7d57c 100644 --- a/beetsplug/lastgenre/__init__.py +++ b/beetsplug/lastgenre/__init__.py @@ -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: """Combine old and new genres.""" @@ -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" if self.config["force"]: