Skip to content

Commit

Permalink
Support different composer tags; Copy album artists into track artist…
Browse files Browse the repository at this point in the history
…s if needed
  • Loading branch information
infojunkie committed Jul 14, 2024
1 parent d914dbc commit 0fc4d3d
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 8 deletions.
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -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 <[email protected]>"]
readme = "README.md"
Expand Down
13 changes: 9 additions & 4 deletions src/discogs_tag/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,11 @@
'albumartist'
]

COMPOSER_TAGS = [
'Written-By',
'Composed By'
]

AUDIO_EXTENSIONS = ['flac', 'mp3']

def tag(
Expand Down Expand Up @@ -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', [])]
})
Expand Down Expand Up @@ -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)

Expand All @@ -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)

Expand Down
40 changes: 37 additions & 3 deletions tests/test_discogs_tag.py
Original file line number Diff line number Diff line change
Expand Up @@ -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():
Expand Down

0 comments on commit 0fc4d3d

Please sign in to comment.