Skip to content

Commit

Permalink
Add year
Browse files Browse the repository at this point in the history
  • Loading branch information
infojunkie committed Feb 3, 2024
1 parent 4d2c6a7 commit f42857a
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 6 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 = "0.1.9"
version = "0.1.10"
description = "A rudimentary audio tagger based on Discogs metadata."
authors = ["infojunkie <[email protected]>"]
readme = "README.md"
Expand Down
15 changes: 10 additions & 5 deletions src/discogs_tag/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@ def tag(
skip_artist=False,
skip_title=False,
skip_composer=False,
skip_position=False
skip_position=False,
skip_year=False
):
"""Tag the audio files with the given Discogs release."""
options = locals()
Expand All @@ -32,8 +33,8 @@ def tag(
)
apply_metadata(data, files, options)

def apply_metadata(data, files, options):
tracks = list(filter(lambda t: t['type_'] == 'track', data['tracklist']))
def apply_metadata(release, files, options):
tracks = list(filter(lambda t: t['type_'] == 'track', release['tracklist']))
if len(files) != len(tracks):
if options['ignore']:
print(f'Expecting {len(tracks)} files but found {len(files)}. Ignoring.', file=sys.stderr)
Expand All @@ -43,7 +44,7 @@ def apply_metadata(data, files, options):
for n, track in enumerate(tracks):
try:
audio = mutagen.File(files[n], easy=True)
merge_metadata(track, audio, options)
merge_metadata(release, track, audio, options)
if options['dry']:
pprint(audio)
else:
Expand All @@ -57,7 +58,7 @@ def apply_metadata(data, files, options):
if not options['dry']:
print(f'Processed {len(files)} audio files.')

def merge_metadata(track, audio, options):
def merge_metadata(release, track, audio, options):
if not options['skip_title']:
audio['title'] = track['title']

Expand All @@ -81,6 +82,10 @@ def merge_metadata(track, audio, options):
if len(positions) > 1:
audio['discnumber'] = positions[0]

if not options['skip_year']:
if 'year' in release and release['year']:
audio['date'] = str(release['year'])

def artist_name(artist):
name = None
if 'anv' in artist and artist['anv']:
Expand Down
4 changes: 4 additions & 0 deletions tests/test_discogs_tag.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
def test_merge_metadata():
audio = {}
merge_metadata({
'year': 2002,
}, {
'title': 'Title',
'artists': [{
'anv': 'Artist 1'
Expand All @@ -27,12 +29,14 @@ def test_merge_metadata():
'skip_composer': False,
'skip_title': False,
'skip_position': False,
'skip_year': False
})
assert audio['title'] == 'Title'
assert audio['artist'] == 'Artist 1, Artist 2, Artist 3, Guitarist'
assert audio['discnumber'] == '1'
assert audio['tracknumber'] == '02'
assert audio['composer'] == 'Composer'
assert audio['date'] == '2002'

def test_apply_metadata():
with open('tests/release.json') as release:
Expand Down

0 comments on commit f42857a

Please sign in to comment.