diff --git a/badwitch.py b/badwitch.py index 217a6bb..a98a17f 100755 --- a/badwitch.py +++ b/badwitch.py @@ -14,6 +14,7 @@ import argparse import eyed3 import json import logging +import math import pathlib import sys import youtube_dl @@ -74,7 +75,9 @@ class Library: Path(destpath).mkdir(parents=True, exist_ok=True) # Actually download and tag songs for song, songcontent in albumcontent.items(): - destfile = str(destpath / song) + '.%(ext)s' + zeroes = int(math.log10(len(albumcontent)) + 1) + filename = str(songcontent['track']).zfill(zeroes) + ' - ' + song + destfile = str(destpath / filename) + '.%(ext)s' logging.debug('Saving to: ' + destfile) # See if we already have it if Path(str(destpath / song) + '.mp3').exists(): @@ -98,7 +101,7 @@ class Library: print('Downloaded song: ' + song) # Add tags logging.debug('Adding tags') - resultfile = eyed3.load(str(destpath / song) + '.mp3') + resultfile = eyed3.load(str(destpath / filename) + '.mp3') resultfile.tag.album_artist = albumartist resultfile.tag.artist = songcontent['artist'] resultfile.tag.album = album