From fbc76ea62ad2396a61be6b1ae65bd8140589a3d6 Mon Sep 17 00:00:00 2001 From: Salt Date: Wed, 4 Mar 2020 03:13:59 -0600 Subject: [PATCH] Switch to MP3, add ID3 tag support RIP opus --- badwitch.py | 15 +++++++++++++-- requirements.txt | 1 + 2 files changed, 14 insertions(+), 2 deletions(-) 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