Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add work, work-disambig and work_id tags #3272

Merged
merged 14 commits into from
May 31, 2019
9 changes: 9 additions & 0 deletions beets/autotag/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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?
Expand Down Expand Up @@ -167,6 +173,9 @@ def apply_metadata(album_info, mapping):
'composer',
'composer_sort',
'arranger',
'work',
'mb_workid',
'work_disambig',
)
}

Expand Down
9 changes: 8 additions & 1 deletion beets/autotag/hooks.py
Original file line number Diff line number Diff line change
Expand Up @@ -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``
Expand All @@ -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
Expand All @@ -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'):
Expand Down
12 changes: 12 additions & 0 deletions beets/autotag/mb.py
Original file line number Diff line number Diff line change
Expand Up @@ -210,9 +210,17 @@ def track_info(recording, index=None, medium=None, medium_index=None,
lyricist = []
composer = []
composer_sort = []
work = []
mb_workid = []
work_disambig = []
for work_relation in recording.get('work-relation-list', ()):
if work_relation['type'] != 'performance':
continue
work.append(work_relation['work']['title'])
mb_workid.append(work_relation['work']['id'])
if 'disambiguation' in work_relation['work']:
work_disambig.append(work_relation['work']['disambiguation'])

for artist_relation in work_relation['work'].get(
'artist-relation-list', ()):
if 'type' in artist_relation:
Expand All @@ -237,6 +245,10 @@ def track_info(recording, index=None, medium=None, medium_index=None,
arranger.append(artist_relation['artist']['name'])
if arranger:
info.arranger = u', '.join(arranger)
if work:
info.work = u', '.join(work)
info.mb_workid = u', '.join(mb_workid)
info.work_disambig = u', '.join(work_disambig)

info.decode()
return info
Expand Down
3 changes: 3 additions & 0 deletions beets/library.py
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand Down
3 changes: 3 additions & 0 deletions test/_common.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down