mirror of
https://github.com/beetbox/beets.git
synced 2025-12-07 17:16:07 +01:00
lastgenre: remove duplicate genres
This commit is contained in:
parent
e77814fa48
commit
df47f19e86
2 changed files with 16 additions and 0 deletions
|
|
@ -197,6 +197,15 @@ class LastGenrePlugin(plugins.BeetsPlugin):
|
|||
if len(tags_all) >= count:
|
||||
break
|
||||
tags = tags_all
|
||||
|
||||
def remove_duplicates(seq):
|
||||
"""Remove duplicates from sequence wile preserving order"""
|
||||
seen = set()
|
||||
seen_add = seen.add
|
||||
return [ x for x in seq if x not in seen and not seen_add(x)]
|
||||
|
||||
tags = remove_duplicates(tags)
|
||||
|
||||
# c14n only adds allowed genres but we may have had forbidden genres in
|
||||
# the original tags list
|
||||
tags = [x.title() for x in tags if self._is_allowed(x)]
|
||||
|
|
|
|||
|
|
@ -129,6 +129,13 @@ class LastGenrePluginTest(unittest.TestCase, TestHelper):
|
|||
self.assertEqual(self.plugin._resolve_genres(['iota blues']),
|
||||
'')
|
||||
|
||||
def test_no_duplicate(self):
|
||||
"""Remove duplicated genres.
|
||||
"""
|
||||
self._setup_config(count=99)
|
||||
self.assertEqual(self.plugin._resolve_genres(['blues', 'blues']),
|
||||
'Blues')
|
||||
|
||||
|
||||
def suite():
|
||||
return unittest.TestLoader().loadTestsFromName(__name__)
|
||||
|
|
|
|||
Loading…
Reference in a new issue