Professional Documents
Culture Documents
"""Gets work title, disambiguation, parent work and its disambiguation, composer,
composer sort name and performers
"""
import subprocess
import musicbrainzngs
class ParentWorkPlugin(BeetsPlugin):
def __init__(self):
super(ParentWorkPlugin, self).__init__()
self.import_stages = [self.imported]
# possible options
# self.config.add({
# u'bin': u'KeyFinder',
# u'auto': True,
# u'overwrite': False,
# })
# self.add_media_field('work', 'work title')
# self.add_media_field('work_disamb', 'work title disambiguation')
# self.add_media_field('parent_work', 'parent work title')
# self.add_media_field('parent_work_disamb', 'parent work title
disambiguation')
# self.add_media_field('parent_composer', 'parent composer name')
# self.add_media_field('parent_composer_sort', 'parent composer sort
name')
# self.add_media_field('performer', 'performer name')
# self.add_media_field('performer_sort', 'performer sort name')
def commands(self):
cmd = ui.Subcommand('parentwork',
help=u'fetches parent works, composers and performers')
cmd.func = self.command
return [cmd]
performer_types=['performer','instrument','vocals','conductor','orchestra','chorus
master','concertmaster']
rec_rels=musicbrainzngs.get_recording_by_id(recording_id,
includes=['work-rels', 'artist-rels'])
if 'artist-relation-list' in rec_rels['recording']:
for dudes in rec_rels['recording']['artist-relation-list']:
if dudes['type'] in performer_types:
performer.append(dudes['artist']['name'])
performer_sort.append(dudes['artist']['sort-name'])
if 'work-relation-list' in rec_rels['recording']:
for work_relation in rec_rels['recording']['work-relation-
list']:
work_id=work_relation['work']['id']
work_info=musicbrainzngs.get_work_by_id(work_id,
includes=["work-rels", "artist-rels"])
work.append(work_info['work']['title'])
if 'disambiguation' in work_info['work']:
work_disambig.append(work_info['work']
['disambiguation'])
partof=True
while partof:
partof=False
if 'work-relation-list' in work_info['work']:
for work_father in work_info['work']['work-
relation-list']:
if work_father['type'] == 'parts':
if 'direction' in work_father:
if work_father['direction'] ==
'backward':
father_id=work_father['work']
['id']
partof=True
parent_composer_sort.append(artist['artist']['sort-name'])
else:
print('no composer')
print('add one at')
print('https://musicbrainz.org/work/'+
work_info['work']['id'])
if work_info['work']['title'] in parent_work:
pass
else:
parent_work.append(work_info['work']['title'])
if 'disambiguation' in work_info['work']:
parent_work_disambig.append(work_info['work']
['disambiguation'])
except musicbrainzngs.musicbrainz.NetworkError:
continue
i=i+1
break
item['parent_work']=parent_work
item['parent_work_disambig']=parent_work_disambig
item['work']=work
item['work_disambig']=work_disambig
item['performer']=performer
item['performer_sort']=performer_sort
item['parent_composer']=parent_composer
item['parent_composer_sort']=parent_composer_sort
item.try_write()
item.store()