Join GitHub today
GitHub is home to over 50 million developers working together to host and review code, manage projects, and build software together.
Sign upGitHub is where the world builds software
Millions of developers and companies build, ship, and maintain their software on GitHub — the largest and most advanced development platform in the world.
How to add album art, track and artist data to file with YouTube-DL Embedded in Python #12225
Comments
|
Add |
|
How would I include "artist", "description" etc? |
|
@dyablade looks lke you need a custom PostProcessor for it since import youtube_dl
from youtube_dl.postprocessor.ffmpeg import FFmpegMetadataPP
class MyLogger(object):
def debug(self, msg):
pass
def warning(self, msg):
pass
def error(self, msg):
print(msg)
def console_hook(d):
if d['status'] == 'finished':
print('Done downloading, now converting ...')
if d['status'] == 'downloading':
if d.get('eta') is not None:
print(d['_percent_str'])
else:
print('Unknown ETA')
class FFmpegMP3MetadataPP(FFmpegMetadataPP):
def __init__(self, downloader=None, metadata=None):
self.metadata = metadata or {}
super(FFmpegMP3MetadataPP, self).__init__(downloader)
def run(self, information):
information = self.purge_metadata(information)
information.update(self.metadata)
return super(FFmpegMP3MetadataPP, self).run(information)
def purge_metadata(self, info):
info.pop('title', None)
info.pop('track', None)
info.pop('upload_date', None)
info.pop('description', None)
info.pop('webpage_url', None)
info.pop('track_number', None)
info.pop('artist', None)
info.pop('creator', None)
info.pop('uploader', None)
info.pop('uploader_id', None)
info.pop('genre', None)
info.pop('album', None)
info.pop('album_artist', None)
info.pop('disc_number', None)
return info
url = 'https://www.youtube.com/watch?v=EL8e2ujXe8g'
metadata = {
"title": "Stop",
"artist": "Movie",
}
ydl_opts = {
'format': 'bestaudio/best',
'postprocessors': [{
'key': 'FFmpegExtractAudio',
'preferredcodec': 'mp3',
'preferredquality': '192',
}],
'outtmpl': 'result.%(format)s',
'logger': MyLogger(),
'progress_hooks': [console_hook],
}
with youtube_dl.YoutubeDL(ydl_opts) as ydl:
ffmpeg_mp3_metadata_pp = FFmpegMP3MetadataPP(ydl, metadata)
ydl.add_post_processor(ffmpeg_mp3_metadata_pp)
ydl.download([url]) |
How would i use the ytd_opts{} to add track data to the converted mp3 file, specifcally the album art, artist, and album?