diff --git a/badwitch.py b/badwitch.py index 9769158..23b60a5 100755 --- a/badwitch.py +++ b/badwitch.py @@ -11,6 +11,7 @@ from appdirs import AppDirs from pathlib import Path import argparse +import eyed3 import json import logging import pathlib @@ -69,9 +70,9 @@ class Library: Path(destpath).mkdir(parents=True, exist_ok=True) for song, songcontent in albumcontent.items(): destfile = str(destpath / song) + '.%(ext)s' + logging.debug('Saving to: ' + destfile) # See if we already have it - matches = sorted(Path(destpath).glob(song + '.*')) - if not matches == []: + if Path(destfile).exists(): logging.info('Already have song: ' + song) continue # Download the song @@ -88,6 +89,16 @@ class Library: } with youtube_dl.YoutubeDL(ytdl_opts) as ydl: ydl.download([songcontent['source']]) + # Add tags + logging.debug('Adding tags') + resultfile = eyed3.load(str(destpath / song) + '.mp3') + print(resultfile) + + resultfile.tag.artist = songcontent['artist'] + resultfile.tag.album = album + resultfile.tag.title = song + resultfile.tag.track_num = songcontent['track'] + resultfile.tag.save() print('Downloaded song: ' + song) class BadWitch: diff --git a/requirements.txt b/requirements.txt index 7b4b647..5dc5ccb 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,2 +1,3 @@ appdirs>=1.4.3 +eyed3>=0.8.8 youtube-dl