ytdl-org / youtube-dl

Command-line program to download videos from YouTube.com and other video sites
http://ytdl-org.github.io/youtube-dl/
The Unlicense
132.36k stars 10.04k forks source link

Embedding thumbnail raise key error 'filename' #10185

Closed gigalala closed 8 years ago

gigalala commented 8 years ago

Please follow the guide below


Make sure you are using the latest version: run youtube-dl --version and ensure your version is 2016.07.28. If it's not read this FAQ entry and update. Issues with outdated version will be rejected.

Hi, I am trying to use the embed thumbnail option on python script, here are my ydl options:

        ydl_opts = {
            'format': 'bestaudio/best',
            'download_archive': self.songs_data,
            'outtmpl': '/'+download_path+'/'+'%(title)s.%(ext)s',
            'progress_hooks': [self.my_hook],
            'postprocessors': [
                {'key': 'EmbedThumbnail',},
                {'key': 'FFmpegExtractAudio',
                'preferredcodec': 'mp3',
                'preferredquality': '192'},]}

But i get the following error:

line 29, in start_download
    ydl.download([download_list])
  File "/Library/Frameworks/Python.framework/Versions/3.4/lib/python3.4/site-packages/youtube_dl/YoutubeDL.py", line 1775, in download
    url, force_generic_extractor=self.params.get('force_generic_extractor', False))
  File "/Library/Frameworks/Python.framework/Versions/3.4/lib/python3.4/site-packages/youtube_dl/YoutubeDL.py", line 693, in extract_info
    return self.process_ie_result(ie_result, download, extra_info)
  File "/Library/Frameworks/Python.framework/Versions/3.4/lib/python3.4/site-packages/youtube_dl/YoutubeDL.py", line 854, in process_ie_result
    extra_info=extra)
  File "/Library/Frameworks/Python.framework/Versions/3.4/lib/python3.4/site-packages/youtube_dl/YoutubeDL.py", line 746, in process_ie_result
    extra_info=extra_info)
  File "/Library/Frameworks/Python.framework/Versions/3.4/lib/python3.4/site-packages/youtube_dl/YoutubeDL.py", line 693, in extract_info
    return self.process_ie_result(ie_result, download, extra_info)
  File "/Library/Frameworks/Python.framework/Versions/3.4/lib/python3.4/site-packages/youtube_dl/YoutubeDL.py", line 739, in process_ie_result
    return self.process_video_result(ie_result, download=download)
  File "/Library/Frameworks/Python.framework/Versions/3.4/lib/python3.4/site-packages/youtube_dl/YoutubeDL.py", line 1421, in process_video_result
    self.process_info(new_info)
  File "/Library/Frameworks/Python.framework/Versions/3.4/lib/python3.4/site-packages/youtube_dl/YoutubeDL.py", line 1757, in process_info
    self.post_process(filename, info_dict)
  File "/Library/Frameworks/Python.framework/Versions/3.4/lib/python3.4/site-packages/youtube_dl/YoutubeDL.py", line 1821, in post_process
    files_to_delete, info = pp.run(info)
  File "/Library/Frameworks/Python.framework/Versions/3.4/lib/python3.4/site-packages/youtube_dl/postprocessor/embedthumbnail.py", line 36, in run
    thumbnail_filename = info['thumbnails'][-1]['filename']
KeyError: 'filename'
yan12125 commented 8 years ago

Please post the whole script so that we can test it. And please also add 'verbose': True, to ydl_opts so that verbose information is also printed out.

gigalala commented 8 years ago

verbose:

[debug] Encodings: locale US-ASCII, fs utf-8, out us-ascii, pref US-ASCII
[debug] youtube-dl version 2016.07.28
[debug] Python version 3.4.1 - Darwin-15.3.0-x86_64-i386-64bit
[debug] exe versions: avconv 11.4, avprobe 11.4, ffmpeg 3.0.2, ffprobe 3.0.2
[debug] Proxy map: {}
download] Downloading video 13 of 14
[youtube] WZM4iXT3-ic: Downloading webpage
[youtube] WZM4iXT3-ic: Downloading video info webpage
[youtube] WZM4iXT3-ic: Extracting video information
[youtube] {43} signature length 42.43, html5 player en_US-vflVo2R8O
[youtube] {18} signature length 42.43, html5 player en_US-vflVo2R8O
[youtube] {36} signature length 42.43, html5 player en_US-vflVo2R8O
[youtube] {17} signature length 42.43, html5 player en_US-vflVo2R8O
[youtube] {135} signature length 42.43, html5 player en_US-vflVo2R8O
[youtube] {244} signature length 42.43, html5 player en_US-vflVo2R8O
[youtube] {134} signature length 42.43, html5 player en_US-vflVo2R8O
[youtube] {243} signature length 42.43, html5 player en_US-vflVo2R8O
[youtube] {133} signature length 42.43, html5 player en_US-vflVo2R8O
[youtube] {242} signature length 42.43, html5 player en_US-vflVo2R8O
[youtube] {160} signature length 42.43, html5 player en_US-vflVo2R8O
[youtube] {278} signature length 42.43, html5 player en_US-vflVo2R8O
[youtube] {140} signature length 42.43, html5 player en_US-vflVo2R8O
[youtube] {171} signature length 42.43, html5 player en_US-vflVo2R8O
[debug] Invoking downloader on 'https://r15---sn-bvvbax-2ime.googlevideo.com/videoplayback?gir=yes&initcwndbps=2502500&expire=1469822795&mime=audio%2Fwebm&itag=171&nh=EAI&fexp=9416891%2C9419452%2C9422596%2C9428398%2C9429856%2C9431012%2C9433096%2C9433221%2C9433946%2C9435036%2C9435526%2C9435666%2C9435876%2C9437066%2C9437258%2C9437552%2C9438327%2C9438662%2C9438805%2C9439581%2C9439652%2C9439889%2C9440376%2C9440435%2C9440880%2C9441119%2C9441450%2C9441593%2C9442074%2C9442242%2C9442424&ipbits=0&ei=62KbV4j8H8bN-wO5s6yoCg&dur=239.193&sparams=clen%2Cdur%2Cei%2Cgir%2Cid%2Cinitcwndbps%2Cip%2Cipbits%2Citag%2Ckeepalive%2Clmt%2Cmime%2Cmm%2Cmn%2Cms%2Cmv%2Cnh%2Cpl%2Crequiressl%2Csource%2Cupn%2Cexpire&requiressl=yes&mv=m&pl=17&mt=1469800475&ms=au&id=o-ABq8IOxwkMHSy1tTfsOM0SqteEPHeGkk_AQwbpRtqhRV&ip=68.104.199.46&key=yt6&keepalive=yes&mn=sn-bvvbax-2ime&mm=31&source=youtube&sver=3&clen=3565919&upn=K5Ys10SD-FA&lmt=1396634731717119&signature=6C75142D383770A1ACA965568B18D9036446B242.C30BF88A850786FFD8EE4C3CCA6A86C90685B541&ratebypass=yes'
[download] Destination: //Users/Avihai/Music/iTunes/iTunes Media/Automatically Add to iTunes/אריק איינשטיין עטור מצחך זהב שחור Arik Einstein.webm
[K[download] 100% of 3.40MiB in 00:05
Done downloading אריק איינשטיין עטור מצחך זהב שחור Arik Einstein.webm
Exception in thread Thread-1:
Traceback (most recent call last):
  File "/Library/Frameworks/Python.framework/Versions/3.4/lib/python3.4/threading.py", line 920, in _bootstrap_inner
    self.run()
  File "/Library/Frameworks/Python.framework/Versions/3.4/lib/python3.4/threading.py", line 868, in run
    self._target(*self._args, **self._kwargs)
  File "/Users/Avihai/Desktop/Avihai/DEV/YoutubeDownloader/YoutubeDownload.py", line 29, in start_download
    ydl.download([download_list])
  File "/Library/Frameworks/Python.framework/Versions/3.4/lib/python3.4/site-packages/youtube_dl/YoutubeDL.py", line 1775, in download
    url, force_generic_extractor=self.params.get('force_generic_extractor', False))
  File "/Library/Frameworks/Python.framework/Versions/3.4/lib/python3.4/site-packages/youtube_dl/YoutubeDL.py", line 693, in extract_info
    return self.process_ie_result(ie_result, download, extra_info)
  File "/Library/Frameworks/Python.framework/Versions/3.4/lib/python3.4/site-packages/youtube_dl/YoutubeDL.py", line 854, in process_ie_result
    extra_info=extra)
  File "/Library/Frameworks/Python.framework/Versions/3.4/lib/python3.4/site-packages/youtube_dl/YoutubeDL.py", line 746, in process_ie_result
    extra_info=extra_info)
  File "/Library/Frameworks/Python.framework/Versions/3.4/lib/python3.4/site-packages/youtube_dl/YoutubeDL.py", line 693, in extract_info
    return self.process_ie_result(ie_result, download, extra_info)
  File "/Library/Frameworks/Python.framework/Versions/3.4/lib/python3.4/site-packages/youtube_dl/YoutubeDL.py", line 739, in process_ie_result
    return self.process_video_result(ie_result, download=download)
  File "/Library/Frameworks/Python.framework/Versions/3.4/lib/python3.4/site-packages/youtube_dl/YoutubeDL.py", line 1421, in process_video_result
    self.process_info(new_info)
  File "/Library/Frameworks/Python.framework/Versions/3.4/lib/python3.4/site-packages/youtube_dl/YoutubeDL.py", line 1757, in process_info
    self.post_process(filename, info_dict)
  File "/Library/Frameworks/Python.framework/Versions/3.4/lib/python3.4/site-packages/youtube_dl/YoutubeDL.py", line 1821, in post_process
    files_to_delete, info = pp.run(info)
  File "/Library/Frameworks/Python.framework/Versions/3.4/lib/python3.4/site-packages/youtube_dl/postprocessor/embedthumbnail.py", line 36, in run
    thumbnail_filename = info['thumbnails'][-1]['filename']
KeyError: 'filename'

script:

from __future__ import unicode_literals
import youtube_dl
import os

class YoutubeDownload:

    def __init__(self, progress):
        os.environ["PATH"] += os.pathsep + "/usr/local/bin"
        self.songs_data = "songs_data.txt"
        self.progress = progress

    def start_download(self,download_path, download_list):

        ydl_opts = {
            'verbose': True,
            'format': 'bestaudio/best',
            'download_archive': self.songs_data,
            'outtmpl': '/'+download_path+'/'+'%(title)s.%(ext)s',
            'progress_hooks': [self.my_hook],
            'postprocessors': [
                {'key': 'EmbedThumbnail',},
                {'key': 'FFmpegExtractAudio',
                'preferredcodec': 'mp3',
                'preferredquality': '192'},]}

        with youtube_dl.YoutubeDL(ydl_opts) as ydl:
            ydl.download([download_list])
        self.progress.put(True)

    def my_hook(self,d):
        if d['status'] == 'finished':
            file_tuple = os.path.split(os.path.abspath(d['filename']))
            print("Done downloading {}".format(file_tuple[1]))
            self.progress.put("Done downloading {}".format(file_tuple[1]))
        if d['status'] == 'downloading':
            print(d['filename'], d['_percent_str'], d['_eta_str'])
            self.progress.put(d['filename'], d['_percent_str'], d['_eta_str'])
dstftw commented 8 years ago

'writethumbnail': True must be added to options.

gigalala commented 8 years ago

Now i am getting this: youtube_dl.utils.DownloadError: ERROR: Only mp3 and m4a/mp4 are supported for thumbnail embedding for now.

script:

        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': 'EmbedThumbnail',},
                {'key': 'FFmpegExtractAudio',
                'preferredcodec': 'mp3',
                'preferredquality': '192'},]}
gigalala commented 8 years ago

Seems like it tries to add the thumbnail before the file is converted to mp3

dstftw commented 8 years ago

Because you've requested it to do so. Change the order of post processors.

gigalala commented 8 years ago

Now it can't find the jpg file, although it exist: youtube_dl.utils.DownloadError: ERROR: file://Users/Avihai/Music/iTunes/iTunes Media/Automatically Add to iTunes/Coldplay - Fix You [HD].jpg: No such file or directory


        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',},]}

thanks for the help