Skip to content

Commit

Permalink
Support multiple discs and don't overwrite empty artists
Browse files Browse the repository at this point in the history
  • Loading branch information
infojunkie committed Oct 26, 2023
1 parent 48cbd79 commit 7a97e11
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 5 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.3"
version = "0.1.4"
description = "A rudimentary audio tagger based on Discogs metadata."
authors = ["infojunkie <[email protected]>"]
readme = "README.md"
Expand Down
15 changes: 11 additions & 4 deletions src/discogs_tag/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import json
import os
from pprint import pprint
from glob import glob
import glob
from discogs_tag import __NAME__, __VERSION__

def tag(release, dir = './', dry = False):
Expand All @@ -14,15 +14,22 @@ def tag(release, dir = './', dry = False):
})
with urllib.request.urlopen(request) as response:
data = json.load(response)
files = sorted(glob(os.path.join(dir, '*.flac')) + glob(os.path.join(dir, '*.mp3')))
files = sorted(
glob.glob(os.path.join(glob.escape(dir), '**', '*.flac'), recursive=True) +
glob.glob(os.path.join(glob.escape(dir), '**', '*.mp3'), recursive=True)
)
tracks = list(filter(lambda t: t['type_'] == 'track', data['tracklist']))
if (len(files) != len(tracks)):
raise Exception(f'Expecting {len(tracks)} files but found {len(files)}. Aborting.')
for n, track in enumerate(tracks):
audio = mutagen.File(files[n], easy=True)
audio['title'] = track['title']
audio['artist'] = ', '.join([artist_name(artist) for artist in track['artists']]) if 'artists' in track else ''
audio['tracknumber'] = track['position']
if 'artists' in track:
audio['artist'] = ', '.join([artist_name(artist) for artist in track['artists']])
positions = track['position'].split('-')
audio['tracknumber'] = positions[-1]
if (len(positions) > 1):
audio['discnumber'] = positions[0]
composers = ', '.join([artist_name(composer) for composer in filter(lambda a: a['role'].casefold() == 'Written-By'.casefold(), track['extraartists'])]) if 'extraartists' in track else None
if (composers):
audio['composer'] = composers
Expand Down

0 comments on commit 7a97e11

Please sign in to comment.