diff --git a/beets/autotag/__init__.py b/beets/autotag/__init__.py index a71b9b0a61..ede4fbe128 100644 --- a/beets/autotag/__init__.py +++ b/beets/autotag/__init__.py @@ -54,6 +54,12 @@ def apply_item_metadata(item, track_info): item.composer_sort = track_info.composer_sort if track_info.arranger is not None: item.arranger = track_info.arranger + if track_info.work is not None: + item.work = track_info.work + if track_info.mb_workid is not None: + item.mb_workid = track_info.mb_workid + if track_info.work_disambig is not None: + item.work_disambig = track_info.work_disambig # At the moment, the other metadata is left intact (including album # and track number). Perhaps these should be emptied? @@ -167,6 +173,9 @@ def apply_metadata(album_info, mapping): 'composer', 'composer_sort', 'arranger', + 'work', + 'mb_workid', + 'work_disambig', ) } diff --git a/beets/autotag/hooks.py b/beets/autotag/hooks.py index ec7047b7c7..57cd1c3094 100644 --- a/beets/autotag/hooks.py +++ b/beets/autotag/hooks.py @@ -159,6 +159,9 @@ class TrackInfo(object): - ``composer_sort``: individual track composer sort name - ``arranger`: individual track arranger name - ``track_alt``: alternative track number (tape, vinyl, etc.) + - ``work`: individual track work title + - ``mb_workid`: individual track work id + - ``work_disambig`: individual track work diambiguation Only ``title`` and ``track_id`` are required. The rest of the fields may be None. The indices ``index``, ``medium``, and ``medium_index`` @@ -169,7 +172,8 @@ def __init__(self, title, track_id, release_track_id=None, artist=None, medium_index=None, medium_total=None, artist_sort=None, disctitle=None, artist_credit=None, data_source=None, data_url=None, media=None, lyricist=None, composer=None, - composer_sort=None, arranger=None, track_alt=None): + composer_sort=None, arranger=None, track_alt=None, + work=None, mb_workid=None, work_disambig=None): self.title = title self.track_id = track_id self.release_track_id = release_track_id @@ -191,6 +195,9 @@ def __init__(self, title, track_id, release_track_id=None, artist=None, self.composer_sort = composer_sort self.arranger = arranger self.track_alt = track_alt + self.work = work + self.mb_workid = mb_workid + self.work_disambig = work_disambig # As above, work around a bug in python-musicbrainz-ngs. def decode(self, codec='utf-8'): diff --git a/beets/autotag/mb.py b/beets/autotag/mb.py index 4ea56af7ff..b8f91f440c 100644 --- a/beets/autotag/mb.py +++ b/beets/autotag/mb.py @@ -213,6 +213,11 @@ def track_info(recording, index=None, medium=None, medium_index=None, for work_relation in recording.get('work-relation-list', ()): if work_relation['type'] != 'performance': continue + info.work = work_relation['work']['title'] + info.mb_workid = work_relation['work']['id'] + if 'disambiguation' in work_relation['work']: + info.work_disambig = work_relation['work']['disambiguation'] + for artist_relation in work_relation['work'].get( 'artist-relation-list', ()): if 'type' in artist_relation: diff --git a/beets/library.py b/beets/library.py index 9a9d95256a..6d143ef166 100644 --- a/beets/library.py +++ b/beets/library.py @@ -451,6 +451,9 @@ class Item(LibModel): 'lyricist': types.STRING, 'composer': types.STRING, 'composer_sort': types.STRING, + 'work': types.STRING, + 'mb_workid': types.STRING, + 'work_disambig': types.STRING, 'arranger': types.STRING, 'grouping': types.STRING, 'year': types.PaddedInt(4), diff --git a/test/_common.py b/test/_common.py index 99f2e968f4..7a3ece4d8b 100644 --- a/test/_common.py +++ b/test/_common.py @@ -70,6 +70,9 @@ def item(lib=None): composer=u'the composer', arranger=u'the arranger', grouping=u'the grouping', + work=u'the work title', + mb_workid=u'the work musicbrainz id', + work_disambig=u'the work disambiguation', year=1, month=2, day=3,