Add support for artist aliases

Use MusicBrainz artist aliases to import files with artist names in an
appriorate locale
This commit is contained in:
Sam Doshi 2013-02-16 17:11:15 +00:00
parent 7a1a7d035f
commit 781949fa01
2 changed files with 38 additions and 2 deletions

View file

@ -48,6 +48,11 @@ RELEASE_INCLUDES = ['artists', 'media', 'recordings', 'release-groups',
'labels', 'artist-credits']
TRACK_INCLUDES = ['artists']
# only versions >= 0.3 support artist aliases
if musicbrainzngs.musicbrainz._version >= '0.3':
RELEASE_INCLUDES.append('aliases')
TRACK_INCLUDES.append('aliases')
def configure():
"""Set up the python-musicbrainz-ngs module according to settings
from the beets configuration. This should be called at startup.
@ -74,12 +79,42 @@ def _flatten_artist_credit(credit):
artist_sort_parts.append(el)
else:
prefered_locales = config['import']['artist_aliases'].as_str_seq()
chosen_alias = None
if 'alias-list' in el['artist']:
alias_list = el['artist']['alias-list']
# Get a list of the aliases that have set locales
set_locales = [a for a in alias_list if 'locale' in a]
# Search locales in order
for locale in prefered_locales:
# Does anything match
matches = [a for a in set_locales if a['locale'] == locale]
# Skip to next locale if no matches
if len(matches) == 0:
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 len(primaries) > 0:
chosen_alias = primaries[0]
else:
chosen_alias = matches[0]
# If we get here we must have found an acceptable alias
# so stop looking
break
# An artist.
cur_artist_name = el['artist']['name']
if chosen_alias is not None:
cur_artist_name = chosen_alias['alias']
else:
cur_artist_name = el['artist']['name']
artist_parts.append(cur_artist_name)
# Artist sort name.
if 'sort-name' in el['artist']:
if chosen_alias is not None:
artist_sort_parts.append(chosen_alias['sort-name'])
elif 'sort-name' in el['artist']:
artist_sort_parts.append(el['artist']['sort-name'])
else:
artist_sort_parts.append(cur_artist_name)

View file

@ -16,6 +16,7 @@ import:
quiet: no
singletons: no
default_action: apply
artist_aliases: []
clutter: ["Thumbs.DB", ".DS_Store"]
ignore: [".*", "*~"]