From 2cd1ff436b23c714a9470e89c66e8bc780955749 Mon Sep 17 00:00:00 2001 From: infojunkie Date: Sun, 30 Jun 2024 17:27:17 -0700 Subject: [PATCH] Fix position numbering --- pyproject.toml | 2 +- src/discogs_tag/cli.py | 8 +++----- tests/test_discogs_tag.py | 13 ++++++++++++- 3 files changed, 16 insertions(+), 7 deletions(-) diff --git a/pyproject.toml b/pyproject.toml index bd8929a..7ca5085 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -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 "] readme = "README.md" diff --git a/src/discogs_tag/cli.py b/src/discogs_tag/cli.py index adc8d7b..252a489 100644 --- a/src/discogs_tag/cli.py +++ b/src/discogs_tag/cli.py @@ -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) diff --git a/tests/test_discogs_tag.py b/tests/test_discogs_tag.py index 20764d2..e110002 100644 --- a/tests/test_discogs_tag.py +++ b/tests/test_discogs_tag.py @@ -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'] }], {})