Switch to MP3, add ID3 tag support

RIP opus
This commit is contained in:
Salt 2020-03-04 03:13:59 -06:00
parent 19a01589e7
commit fbc76ea62a
2 changed files with 14 additions and 2 deletions

View File

@ -11,6 +11,7 @@
from appdirs import AppDirs from appdirs import AppDirs
from pathlib import Path from pathlib import Path
import argparse import argparse
import eyed3
import json import json
import logging import logging
import pathlib import pathlib
@ -69,9 +70,9 @@ class Library:
Path(destpath).mkdir(parents=True, exist_ok=True) Path(destpath).mkdir(parents=True, exist_ok=True)
for song, songcontent in albumcontent.items(): for song, songcontent in albumcontent.items():
destfile = str(destpath / song) + '.%(ext)s' destfile = str(destpath / song) + '.%(ext)s'
logging.debug('Saving to: ' + destfile)
# See if we already have it # See if we already have it
matches = sorted(Path(destpath).glob(song + '.*')) if Path(destfile).exists():
if not matches == []:
logging.info('Already have song: ' + song) logging.info('Already have song: ' + song)
continue continue
# Download the song # Download the song
@ -88,6 +89,16 @@ class Library:
} }
with youtube_dl.YoutubeDL(ytdl_opts) as ydl: with youtube_dl.YoutubeDL(ytdl_opts) as ydl:
ydl.download([songcontent['source']]) 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) print('Downloaded song: ' + song)
class BadWitch: class BadWitch:

View File

@ -1,2 +1,3 @@
appdirs>=1.4.3 appdirs>=1.4.3
eyed3>=0.8.8
youtube-dl youtube-dl