3

How to add post-processing options equivalent of --embed-thumbnails and --add-metadata when using youtube-dl in a python script?

I read the following documentation, but couldn't find post processing 'key value' options. https://github.com/rg3/youtube-dl/blob/master/README.md#embedding-youtube-dl

1 Answer 1

6

The full list of options is documented in YoutubeDL.py. If you only want to replicate command-line options, you can also have a look in __init__.py.

To replicate --embed-thumbnail and --add-metadata, use the following:

from __future__ import unicode_literals
import youtube_dl

ydl_opts = {
    'writethumbnail': True,
    'postprocessors': [{
        'key': 'FFmpegMetadata'
    }, {
        'key': 'EmbedThumbnail',
        'already_have_thumbnail': True,  # overwrite any thumbnails already present
    }],
}

with youtube_dl.YoutubeDL(ydl_opts) as ydl:
    ydl.download(['https://www.youtube.com/watch?v=BaW_jenozKc'])
Sign up to request clarification or add additional context in comments.

13 Comments

I need to add metadata not subtitles, so I used code ydl_opts = { 'format': '140', 'postprocessors': [ {'key': 'FFmpegMetadata',}, {'key': 'EmbedThumbnail', 'already_have_thumbnail': True,}], 'outtmpl': '%(playlist_index)s - %(title)s.%(ext)s', 'logger': MyLogger(), 'progress_hooks': [my_hook], } code but it gives following error youtube_dl\postprocessor\embedthumbnail.py", line 36, in run thumbnail_filename = info['thumbnails'][-1]['filename']
KeyError: u'filename` missed this line in my above comment
Oops, changed to use metadata, not thumbnails. Does the new code work for you? It runs for me without any problem. Your error seems to be related to thumbnail embedding, which you don't want, or do you after all?
Still your code is for subtitle, isn't it? I need metadata and thumbnail (no subtitle required)
Oh, I'm sorry. Updated again. You'll get an error if you enable just the postprocessor but do not the actual thumbnail extraction.
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.