PLUGIN_NAME = 'Additional Sort Names'
PLUGIN_AUTHOR = 'David Kellner'
PLUGIN_VERSION = '1.1'
PLUGIN_API_VERSIONS = ['2.8']
PLUGIN_LICENSE = 'GPL-2.0-or-later'
PLUGIN_LICENSE_URL = 'https://www.gnu.org/licenses/gpl-2.0.html'
PLUGIN_DESCRIPTION = '''
Provides the artist sort names for writers and lyricists.
Values are available as additional variables _writersort
and
_lyricistsort
for usage in a script.
'''
from picard import log
from picard.album import Album
from picard.mbjson import _relation_attributes # available since Picard 2.8
from picard.metadata import Metadata, register_track_metadata_processor
from picard.util.tags import TAG_NAMES
def provide_sort_names(album: Album, metadata: Metadata, track: dict, release: dict):
recording = track['recording']
if not 'relations' in recording:
log.error('Please enable track relationships in the metadata options.')
return
writer_sort = []
lyricist_sort = []
for recording_rel in recording['relations']:
if recording_rel['type'] == 'performance':
work = recording_rel['work']
if not 'relations' in work:
continue
for work_rel in work['relations']:
rel_type = work_rel['type']
if not rel_type in ['writer', 'lyricist']:
continue
artist = work_rel['artist']
attributes = _relation_attributes(work_rel)
if rel_type == 'writer':
writer_sort.append(artist['sort-name'])
elif rel_type == 'lyricist' and not 'instrumental' in attributes:
lyricist_sort.append(artist['sort-name'])
metadata['~writersort'] = writer_sort
metadata['~lyricistsort'] = lyricist_sort
register_track_metadata_processor(provide_sort_names)
# provide display names for possible custom tags
TAG_NAMES.update({
'lyricistsort': N_('Lyricist Sort Order'),
'writersort': N_('Writer Sort Order'),
})