Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Embedding thumbnail to mp3 with Youtube-dl raise exception

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

like image 320
Gigalala Avatar asked Jul 28 '16 21:07

Gigalala


1 Answers

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',},]}
like image 58
Gigalala Avatar answered Oct 16 '22 07:10

Gigalala