diff --git a/beets/autotag/__init__.py b/beets/autotag/__init__.py index 13923d034..bcd43554e 100644 --- a/beets/autotag/__init__.py +++ b/beets/autotag/__init__.py @@ -125,6 +125,10 @@ def apply_metadata(items, album_info): item.artist = track_info.artist else: item.artist = album_info.artist + if track_info.artist_sort_name: + item.artist_sort_name = track_info.artist_sort_name + elif album_info.artist_sort_name: + item.artist_sort_name = album_info.artist_sort_name item.albumartist = album_info.artist item.album = album_info.album item.tracktotal = len(items) diff --git a/beets/autotag/hooks.py b/beets/autotag/hooks.py index 618cbe33b..849021688 100644 --- a/beets/autotag/hooks.py +++ b/beets/autotag/hooks.py @@ -36,13 +36,14 @@ class AlbumInfo(object): - ``day``: release day - ``label``: music label responsible for the release - ``mediums``: the number of discs in this release + - ``artist_sort_name``: name of the release's artists for sorting The fields up through ``tracks`` are required. The others are optional and may be None. """ def __init__(self, album, album_id, artist, artist_id, tracks, asin=None, albumtype=None, va=False, year=None, month=None, day=None, - label=None, mediums=None): + label=None, mediums=None, artist_sort_name=None): self.album = album self.album_id = album_id self.artist = artist @@ -56,6 +57,8 @@ class AlbumInfo(object): self.day = day self.label = label self.mediums = mediums + if artist_sort_name != '': + self.artist_sort_name = artist_sort_name class TrackInfo(object): """Describes a canonical track present on a release. Appears as part @@ -68,12 +71,14 @@ class TrackInfo(object): - ``length``: float: duration of the track in seconds - ``medium``: the disc number this track appears on in the album - ``medium_index``: the track's position on the disc + - ``artist_sort_name``: name of the release's artists for sorting Only ``title`` and ``track_id`` are required. The rest of the fields may be None. """ def __init__(self, title, track_id, artist=None, artist_id=None, - length=None, medium=None, medium_index=None): + length=None, medium=None, medium_index=None, + artist_sort_name=None): self.title = title self.track_id = track_id self.artist = artist @@ -81,7 +86,8 @@ class TrackInfo(object): self.length = length self.medium = medium self.medium_index = medium_index - + if artist_sort_name != '': + self.artist_sort_name = artist_sort_name # Aggregation of sources. diff --git a/beets/autotag/mb.py b/beets/autotag/mb.py index aeefab022..2a4caf8e9 100644 --- a/beets/autotag/mb.py +++ b/beets/autotag/mb.py @@ -85,12 +85,17 @@ def album_info(release): """ # Get artist name using join phrases. artist_parts = [] + artist_sort_parts = [] for el in release['artist-credit']: if isinstance(el, basestring): artist_parts.append(el) else: artist_parts.append(el['artist']['name']) + artist_sort_parts.append(el['artist']['sort-name']) artist_name = ''.join(artist_parts) + artist_sort_name = ', '.join(artist_sort_parts) + if artist_sort_name == artist_name: + artist_sort_name = '' # Basic info. track_infos = [] @@ -111,6 +116,7 @@ def album_info(release): release['artist-credit'][0]['artist']['id'], track_infos, mediums=len(release['medium-list']), + artist_sort_name = artist_sort_name, ) info.va = info.artist_id == VARIOUS_ARTISTS_ID if 'asin' in release: diff --git a/beets/library.py b/beets/library.py index 98655e11b..a9941d48a 100644 --- a/beets/library.py +++ b/beets/library.py @@ -42,6 +42,7 @@ ITEM_FIELDS = [ ('title', 'text', True, True), ('artist', 'text', True, True), + ('artist_sort_name', 'text', True, True), ('album', 'text', True, True), ('albumartist', 'text', True, True), ('genre', 'text', True, True), diff --git a/beets/mediafile.py b/beets/mediafile.py index 15b9912af..e7f6e948d 100644 --- a/beets/mediafile.py +++ b/beets/mediafile.py @@ -738,6 +738,11 @@ class MediaFile(object): mp4 = StorageStyle("\xa9ART"), etc = StorageStyle('artist'), ) + artist_sort_name = MediaField( + mp3 = StorageStyle('TSOP'), + mp4 = StorageStyle("soar"), + etc = StorageStyle('ARTISTSORT'), + ) album = MediaField( mp3 = StorageStyle('TALB'), mp4 = StorageStyle("\xa9alb"),