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:
|
if targetalbum is not None and not album == targetalbum:
|
||||||
logging.debug('Skipping album ' + album)
|
logging.debug('Skipping album ' + album)
|
||||||
continue
|
continue
|
||||||
# God have mercy on my soul
|
# Get albumartist
|
||||||
artist = next(iter(albumcontent.values()))['artist']
|
# Sets to Various Artists if multiple
|
||||||
destpath = (Path.home() / 'Music' / artist / album)
|
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)
|
Path(destpath).mkdir(parents=True, exist_ok=True)
|
||||||
|
# Actually download and tag songs
|
||||||
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)
|
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():
|
||||||
|
# Skip downloading
|
||||||
logging.info('Already have song: ' + song)
|
logging.info('Already have song: ' + song)
|
||||||
continue
|
else:
|
||||||
# Download the song
|
# Download the song
|
||||||
ytdl_opts = {
|
ytdl_opts = {
|
||||||
'format': 'bestaudio',
|
'format': 'bestaudio',
|
||||||
'postprocessors': [{
|
'postprocessors': [{
|
||||||
'key': 'FFmpegExtractAudio',
|
'key': 'FFmpegExtractAudio',
|
||||||
'preferredcodec': 'mp3',
|
'preferredcodec': 'mp3',
|
||||||
'preferredquality': '192'
|
'preferredquality': '192'
|
||||||
}],
|
}],
|
||||||
'quiet': True,
|
'quiet': True,
|
||||||
'playlist_items': 1,
|
'playlist_items': 1,
|
||||||
'outtmpl': destfile
|
'outtmpl': destfile
|
||||||
}
|
}
|
||||||
with youtube_dl.YoutubeDL(ytdl_opts) as ydl:
|
with youtube_dl.YoutubeDL(ytdl_opts) as ydl:
|
||||||
ydl.download([songcontent['source']])
|
ydl.download([songcontent['source']])
|
||||||
|
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 / song) + '.mp3')
|
||||||
|
resultfile.tag.album_artist = albumartist
|
||||||
resultfile.tag.artist = songcontent['artist']
|
resultfile.tag.artist = songcontent['artist']
|
||||||
resultfile.tag.album = album
|
resultfile.tag.album = album
|
||||||
resultfile.tag.title = song
|
resultfile.tag.title = song
|
||||||
resultfile.tag.track_num = songcontent['track']
|
resultfile.tag.track_num = songcontent['track']
|
||||||
resultfile.tag.save()
|
resultfile.tag.save()
|
||||||
print('Downloaded song: ' + song)
|
|
||||||
|
|
||||||
class BadWitch:
|
class BadWitch:
|
||||||
# Our program
|
# Our program
|
||||||
|
Loading…
Reference in New Issue
Block a user