Skip to content

Commit

Permalink
Use util.unique_list in fav of deduplicate
Browse files Browse the repository at this point in the history
  • Loading branch information
JOJ0 committed Jan 12, 2025
1 parent 884e070 commit cc9fdae
Showing 1 changed file with 5 additions and 12 deletions.
17 changes: 5 additions & 12 deletions beetsplug/lastgenre/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
import yaml

from beets import config, library, plugins, ui
from beets.util import normpath, plurality
from beets.util import normpath, plurality, unique_list

LASTFM = pylast.LastFMNetwork(api_key=plugins.LASTFM_KEY)

Expand All @@ -45,15 +45,8 @@
}


def deduplicate(seq):
"""Remove duplicates from sequence while preserving order."""
seen = set()
return [x for x in seq if x not in seen and not seen.add(x)]


# Canonicalization tree processing.


def flatten_tree(elem, path, branches):
"""Flatten nested lists/dictionaries into lists of strings
(branches).
Expand Down Expand Up @@ -240,7 +233,7 @@ def _resolve_genres(self, tags):
break
tags = tags_all

tags = deduplicate(tags)
tags = unique_list(tags)

# Sort the tags by specificity.
if self.config["prefer_specific"]:
Expand Down Expand Up @@ -334,10 +327,10 @@ def _dedup_genres(self, genres, whitelist_only=False):
whitelist_only option, gives filtered or unfiltered results.
Makes sure genres are handled all lower case."""
if whitelist_only:
return deduplicate(
return unique_list(
[g.lower() for g in genres if self._is_valid(g)]
)
return deduplicate([g.lower() for g in genres])
return unique_list([g.lower() for g in genres])

def _combine_and_label_genres(
self, new_genres: list, keep_genres: list, log_label: str
Expand All @@ -356,7 +349,7 @@ def _combine_and_label_genres(
'logging label'.
"""
self._log.debug(f"fetched last.fm tags: {new_genres}")
combined = deduplicate(keep_genres + new_genres)
combined = unique_list(keep_genres + new_genres)
resolved = self._resolve_genres(combined)
reduced = self._to_delimited_genre_string(resolved)

Expand Down

0 comments on commit cc9fdae

Please sign in to comment.