mirror of
https://github.com/beetbox/beets.git
synced 2026-01-09 01:15:38 +01:00
Merge pull request #633 from sampsyo/issue-632
Only use primary artist aliases. Fixes #632.
This commit is contained in:
commit
e628b8f3a7
2 changed files with 14 additions and 15 deletions
|
|
@ -80,20 +80,13 @@ def _preferred_alias(aliases):
|
|||
|
||||
# Search configured locales in order.
|
||||
for locale in config['import']['languages'].as_str_seq():
|
||||
# Find matching aliases for this locale.
|
||||
matches = [a for a in aliases if a['locale'] == locale]
|
||||
# Find matching primary aliases for this locale.
|
||||
matches = [a for a in aliases if a['locale'] == locale and 'primary' in a]
|
||||
# Skip to the next locale if we have no matches
|
||||
if not matches:
|
||||
continue
|
||||
|
||||
# Find the aliases that have the primary flag set.
|
||||
primaries = [a for a in matches if 'primary' in a]
|
||||
# Take the primary if we have it, otherwise take the first
|
||||
# match with the correct locale.
|
||||
if primaries:
|
||||
return primaries[0]
|
||||
else:
|
||||
return matches[0]
|
||||
return matches[0]
|
||||
|
||||
def _flatten_artist_credit(credit):
|
||||
"""Given a list representing an ``artist-credit`` block, flatten the
|
||||
|
|
|
|||
|
|
@ -366,27 +366,28 @@ class ArtistFlatteningTest(_common.TestCase):
|
|||
|
||||
def test_alias(self):
|
||||
credit_dict = self._credit_dict()
|
||||
self._add_alias(credit_dict, suffix='en', locale='en')
|
||||
self._add_alias(credit_dict, suffix='en_GB', locale='en_GB')
|
||||
self._add_alias(credit_dict, suffix='en', locale='en', primary=True)
|
||||
self._add_alias(credit_dict, suffix='en_GB', locale='en_GB', primary=True)
|
||||
self._add_alias(credit_dict, suffix='fr', locale='fr')
|
||||
self._add_alias(credit_dict, suffix='fr_P', locale='fr', primary=True)
|
||||
self._add_alias(credit_dict, suffix='pt_BR', locale='pt_BR')
|
||||
|
||||
# test no alias
|
||||
config['import']['languages'] = ['']
|
||||
flat = mb._flatten_artist_credit([credit_dict])
|
||||
self.assertEqual(flat, ('NAME', 'SORT', 'CREDIT'))
|
||||
|
||||
# test en
|
||||
# test en primary
|
||||
config['import']['languages'] = ['en']
|
||||
flat = mb._flatten_artist_credit([credit_dict])
|
||||
self.assertEqual(flat, ('ALIASen', 'ALIASSORTen', 'CREDIT'))
|
||||
|
||||
# test en_GB en
|
||||
# test en_GB en primary
|
||||
config['import']['languages'] = ['en_GB', 'en']
|
||||
flat = mb._flatten_artist_credit([credit_dict])
|
||||
self.assertEqual(flat, ('ALIASen_GB', 'ALIASSORTen_GB', 'CREDIT'))
|
||||
|
||||
# test en en_GB
|
||||
# test en en_GB primary
|
||||
config['import']['languages'] = ['en', 'en_GB']
|
||||
flat = mb._flatten_artist_credit([credit_dict])
|
||||
self.assertEqual(flat, ('ALIASen', 'ALIASSORTen', 'CREDIT'))
|
||||
|
|
@ -396,6 +397,11 @@ class ArtistFlatteningTest(_common.TestCase):
|
|||
flat = mb._flatten_artist_credit([credit_dict])
|
||||
self.assertEqual(flat, ('ALIASfr_P', 'ALIASSORTfr_P', 'CREDIT'))
|
||||
|
||||
# test for not matching non-primary
|
||||
config['import']['languages'] = ['pt_BR', 'fr']
|
||||
flat = mb._flatten_artist_credit([credit_dict])
|
||||
self.assertEqual(flat, ('ALIASfr_P', 'ALIASSORTfr_P', 'CREDIT'))
|
||||
|
||||
def suite():
|
||||
return unittest.TestLoader().loadTestsFromName(__name__)
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue