Skip to content

Commit

Permalink
Fix position numbering
Browse files Browse the repository at this point in the history
  • Loading branch information
infojunkie committed Jul 1, 2024
1 parent 64c020c commit 2cd1ff4
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 7 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.5.0"
version = "0.5.1"
description = "A rudimentary audio tagger based on Discogs metadata."
authors = ["infojunkie <[email protected]>"]
readme = "README.md"
Expand Down
8 changes: 3 additions & 5 deletions src/discogs_tag/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -161,14 +161,12 @@ def read_metadata(audios, options):
"""Read metadata from audio files and return data structure that mimics Discogs release."""
def safe_position(audio, n):
try:
position = audio.get('tracknumber', [str(n)])[0].split('/')
tracknumber = audio.get('tracknumber', [str(n)])[0].split('/')
discnumber = audio.get('discnumber')
if discnumber:
position.insert(1, discnumber[0])
if len(position) == 1:
return position[0].lstrip('0')
return discnumber[0].lstrip('0') + '-' + tracknumber[0].lstrip('0')
else:
return position[1].lstrip('0') + '-' + position[0].lstrip('0')
return tracknumber[0].lstrip('0')
except:
return str(n)

Expand Down
13 changes: 12 additions & 1 deletion tests/test_discogs_tag.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,18 @@ def test_read_metadata():
'album': ['Album'],
'composer': ['Composer'],
'genre': ['Genre'],
'tracknumber': ['2'],
'tracknumber': ['0002'],
'title': ['Title'],
'date': ['2024']
}], {})
assert release['tracklist'][0]['position'] == '2'
release = read_metadata([{
'artist': ['Artist'],
'albumartist': ['Album Artist'],
'album': ['Album'],
'composer': ['Composer'],
'genre': ['Genre'],
'tracknumber': ['2/10'],
'title': ['Title'],
'date': ['2024']
}], {})
Expand Down

0 comments on commit 2cd1ff4

Please sign in to comment.