lastgenre: remove duplicate genres

This commit is contained in:
Fabrice Laporte 2014-06-28 10:31:12 +02:00
parent e77814fa48
commit df47f19e86
2 changed files with 16 additions and 0 deletions

View file

@ -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)]

View file

@ -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__)