Always tag files, add album_artist tag
This commit is contained in:
parent
eb3936edc9
commit
334ec3a53c
48
badwitch.py
48
badwitch.py
@ -61,40 +61,50 @@ class Library:
|
||||
if targetalbum is not None and not album == targetalbum:
|
||||
logging.debug('Skipping album ' + album)
|
||||
continue
|
||||
# God have mercy on my soul
|
||||
artist = next(iter(albumcontent.values()))['artist']
|
||||
destpath = (Path.home() / 'Music' / artist / album)
|
||||
# Get albumartist
|
||||
# Sets to Various Artists if multiple
|
||||
albumartist=''
|
||||
for song, songcontent in albumcontent.items():
|
||||
if albumartist == '':
|
||||
albumartist = songcontent['artist']
|
||||
elif albumartist != songcontent['artist']:
|
||||
albumartist = 'Various Artists'
|
||||
break
|
||||
destpath = (Path.home() / 'Music' / albumartist / album)
|
||||
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'
|
||||
logging.debug('Saving to: ' + destfile)
|
||||
# See if we already have it
|
||||
if Path(str(destpath / song) + '.mp3').exists():
|
||||
# Skip downloading
|
||||
logging.info('Already have song: ' + song)
|
||||
continue
|
||||
# Download the song
|
||||
ytdl_opts = {
|
||||
'format': 'bestaudio',
|
||||
'postprocessors': [{
|
||||
'key': 'FFmpegExtractAudio',
|
||||
'preferredcodec': 'mp3',
|
||||
'preferredquality': '192'
|
||||
}],
|
||||
'quiet': True,
|
||||
'playlist_items': 1,
|
||||
'outtmpl': destfile
|
||||
}
|
||||
with youtube_dl.YoutubeDL(ytdl_opts) as ydl:
|
||||
ydl.download([songcontent['source']])
|
||||
else:
|
||||
# Download the song
|
||||
ytdl_opts = {
|
||||
'format': 'bestaudio',
|
||||
'postprocessors': [{
|
||||
'key': 'FFmpegExtractAudio',
|
||||
'preferredcodec': 'mp3',
|
||||
'preferredquality': '192'
|
||||
}],
|
||||
'quiet': True,
|
||||
'playlist_items': 1,
|
||||
'outtmpl': destfile
|
||||
}
|
||||
with youtube_dl.YoutubeDL(ytdl_opts) as ydl:
|
||||
ydl.download([songcontent['source']])
|
||||
print('Downloaded song: ' + song)
|
||||
# Add tags
|
||||
logging.debug('Adding tags')
|
||||
resultfile = eyed3.load(str(destpath / song) + '.mp3')
|
||||
resultfile.tag.album_artist = albumartist
|
||||
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:
|
||||
# Our program
|
||||
|
Loading…
Reference in New Issue
Block a user