From 0fc4d3d400dfaac55179d3c062a2c69091397c22 Mon Sep 17 00:00:00 2001 From: infojunkie Date: Sat, 13 Jul 2024 17:39:20 -0700 Subject: [PATCH] Support different composer tags; Copy album artists into track artists if needed --- pyproject.toml | 2 +- src/discogs_tag/cli.py | 13 +++++++++---- tests/test_discogs_tag.py | 40 ++++++++++++++++++++++++++++++++++++--- 3 files changed, 47 insertions(+), 8 deletions(-) diff --git a/pyproject.toml b/pyproject.toml index 02e3594..f0241f8 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,6 +1,6 @@ [tool.poetry] name = "discogs-tag" -version = "1.0.1" +version = "1.1.0" description = "An audio tagger based on Discogs metadata." authors = ["infojunkie "] readme = "README.md" diff --git a/src/discogs_tag/cli.py b/src/discogs_tag/cli.py index 3d85848..5687f47 100644 --- a/src/discogs_tag/cli.py +++ b/src/discogs_tag/cli.py @@ -25,6 +25,11 @@ 'albumartist' ] +COMPOSER_TAGS = [ + 'Written-By', + 'Composed By' +] + AUDIO_EXTENSIONS = ['flac', 'mp3'] def tag( @@ -187,7 +192,7 @@ def safe_year(audio): 'artists': [{ 'anv': artist } for artist in audio.get('artist', [])], 'title': audio.get('title', [''])[0], 'extraartists': [{ - 'role': 'Written-By', + 'role': 'Composed By', 'anv': composer } for composer in audio.get('composer', [])] }) @@ -347,8 +352,8 @@ def artist_name(artist): artists = [] if 'artists' in track: artists += [artist_name(artist) for artist in track['artists']] - if 'extraartists' in track: - artists += [artist_name(artist) for artist in filter(lambda a: a['role'].casefold() != 'Written-By'.casefold(), track['extraartists'])] + if not artists: + artists += [artist_name(artist) for artist in release['artists']] if artists: audio['artist'] = ', '.join(artists) @@ -373,7 +378,7 @@ def artist_name(artist): audio['album'] = release['title'] if not options['skip_composer']: - composers = [artist_name(composer) for composer in filter(lambda a: a['role'].casefold() == 'Written-By'.casefold(), track['extraartists'])] if 'extraartists' in track else None + composers = [artist_name(composer) for composer in filter(lambda a: a['role'].casefold() in [(lambda c: c.casefold())(c) for c in COMPOSER_TAGS], track['extraartists'])] if 'extraartists' in track else None if composers: audio['composer'] = ', '.join(composers) diff --git a/tests/test_discogs_tag.py b/tests/test_discogs_tag.py index 64ab51f..2bc6467 100644 --- a/tests/test_discogs_tag.py +++ b/tests/test_discogs_tag.py @@ -81,14 +81,48 @@ def test_merge_metadata(): 'name': 'Guitarist' }, { 'role': 'Written-By', - 'name': 'Composer' + 'name': 'Composer 1' + }, { + 'role': 'Composed By', + 'name': 'Composer 2' + }] + }, { 'title': 'Some other title' }, parse_options({ 'skip': None })) + assert audio['title'] == 'Title' + assert audio['artist'] == 'Artist 1, Artist 2, Artist 3' + assert audio['discnumber'] == '1' + assert audio['tracknumber'] == '02' + assert audio['composer'] == 'Composer 1, Composer 2' + assert audio['date'] == '2002' + + audio = merge_metadata({ + 'year': 2002, + 'artists': [{ + 'anv': 'Artist 1' + }, { + 'name': 'Artist 2' + }, { + 'anv': '', + 'name': 'Artist 3 (56)' + }], + }, { + 'title': 'Title', + 'position': '1-02', + 'extraartists': [{ + 'role': 'Guitar', + 'name': 'Guitarist' + }, { + 'role': 'Written-By', + 'name': 'Composer 1' + }, { + 'role': 'Composed By', + 'name': 'Composer 2' }] }, { 'title': 'Some other title' }, parse_options({ 'skip': None })) assert audio['title'] == 'Title' - assert audio['artist'] == 'Artist 1, Artist 2, Artist 3, Guitarist' + assert audio['artist'] == 'Artist 1, Artist 2, Artist 3' assert audio['discnumber'] == '1' assert audio['tracknumber'] == '02' - assert audio['composer'] == 'Composer' + assert audio['composer'] == 'Composer 1, Composer 2' assert audio['date'] == '2002' def test_apply_metadata():