Reputation: 489
I am trying to use youtube-dl to download some youtube video sound as mp3 and embed the thumbnail as well. But i get the following error every time i try:
thumbnail_filename = info['thumbnails'][-1]['filename'] KeyError: 'filename'
Here is my youtube-dl options
ydl_opts = {
'key':'IgnoreErrors',
'format': 'bestaudio/best',
'download_archive': self.songs_data,
'outtmpl': '/'+download_path+'/'+'%(title)s.%(ext)s',
'progress_hooks': [self.my_hook],
'postprocessors': [{
'key': 'FFmpegExtractAudio',
'preferredcodec': 'mp3',
'preferredquality': '192'},
{'key': 'EmbedThumbnail'},]}
Any ideas why? embed thumbnail does not have any arguments.
Thank you
Upvotes: 7
Views: 7448
Reputation: 11
I had to solve this problem independently, but I used Gigalala to get the final step.
Here is a working Youtube-DL / yt_dlp options variable for downloading mp3's with thumbnails and metadata.
ydl_opts = {
'format': 'bestaudio[ext=mp3]/best',
'writethumbnail': True,
'postprocessors': [
{'key': 'FFmpegExtractAudio', 'preferredcodec': 'mp3','preferredquality': '192'},
{'key': 'FFmpegMetadata', 'add_metadata': 'True'},
{'key': 'EmbedThumbnail','already_have_thumbnail': False,}
],
}
I found that the order of the postprocessors is very important. I had to embed metadata first, as it wipes the embed thumbnail. This is the fix for Youtube-DL not embedding thumbnails through the python version.
Upvotes: 1
Reputation: 489
So I figured it out on on my own although its not documented on youtube-dl api.
You need to add 'writethumbnail':True
to options, and change the order on the post processors so 'key': 'FFmpegExtractAudio'
is before 'key': 'EmbedThumbnail'
ydl_opts = {
'writethumbnail': True,
'format': 'bestaudio/best',
'download_archive': self.songs_data,
'outtmpl': '/'+download_path+'/'+'%(title)s.%(ext)s',
'progress_hooks': [self.my_hook],
'postprocessors': [
{'key': 'FFmpegExtractAudio',
'preferredcodec': 'mp3',
'preferredquality': '192'},
{'key': 'EmbedThumbnail',},]}
Upvotes: 9