Add track number to MP3 filenames

Me: I wanna add zeroes to track numbers
Python: Gonna have to import math for that hefty fuckin task
This commit is contained in:
Salt 2020-03-06 03:42:19 -06:00
parent 334ec3a53c
commit cb2dbde126

View File

@ -14,6 +14,7 @@ import argparse
import eyed3 import eyed3
import json import json
import logging import logging
import math
import pathlib import pathlib
import sys import sys
import youtube_dl import youtube_dl
@ -74,7 +75,9 @@ class Library:
Path(destpath).mkdir(parents=True, exist_ok=True) Path(destpath).mkdir(parents=True, exist_ok=True)
# Actually download and tag songs # Actually download and tag songs
for song, songcontent in albumcontent.items(): 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) logging.debug('Saving to: ' + destfile)
# See if we already have it # See if we already have it
if Path(str(destpath / song) + '.mp3').exists(): if Path(str(destpath / song) + '.mp3').exists():
@ -98,7 +101,7 @@ class Library:
print('Downloaded song: ' + song) print('Downloaded song: ' + song)
# Add tags # Add tags
logging.debug('Adding 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.album_artist = albumartist
resultfile.tag.artist = songcontent['artist'] resultfile.tag.artist = songcontent['artist']
resultfile.tag.album = album resultfile.tag.album = album