Forivin
Forivin

Reputation: 15508

youtube-dl: What are the names of the config parameters when importing it as a library in Python?

There seems to be almost no documentation on the youtube-dl python library and the parameters for the cli tool don't translate 1:1... I was able to find some parameters in the YoutubeDL.py that is linked in the Readme, but definitely not all of them.

For instance, it is not clear to me how I can embed the video thumbnail into the video file I'm downloading. With the cli tool, I can use --embed-thumbnail, but when I try to use it in the config object it doesn't work. I don't even get an error

 ydl_opts = {
     'format': 'bestvideo[height<=480]+bestaudio[ext=m4a]/best', # works
     'embed-thumbnail': True, # not working
     'embedthumbnail': True, # not working
     'updatetime': False # works
 }
 youtube_dl.YoutubeDL(ydl_opts)

Here is a cli example that worked for me:

youtube-dl --format "bestvideo[height<=480]+bestaudio[ext=m4a]/best" --embed-thumbnail https://www.youtube.com/watch?v=Co2KIYmaeTY

I verified it by running this on the resulting .mp4 file to extract the thumbnail:

AtomicParsley "thumbnail test-Co2KIYmaeTY.mp4" -E

This file is the closest I got: https://github.com/rg3/youtube-dl/blob/master/youtube_dl/postprocessor/embedthumbnail.py

But I'm not sure what to make out of it...

Upvotes: 0

Views: 2375

Answers (1)

anon
anon

Reputation:

YoutubeDL.py does list all parameters to youtube-dl. embed-thumbnail and embedthumbnail don't work because they are not valid options for a YoutubeDL, and hence not listed in the list of options. However, these options cover "just" the download.

Many effects are implemented by postprocessors, i.e. code that runs after the download has been completed. Postprocessors can be composited in new ways, but if you just want to replicate an existing command-line invocation, have a look at the main function to find out how command-line options map to postprocessors and YoutubeDL API options. For instance, to write thumbnails into video files, you can use

from __future__ import unicode_literals
import youtube_dl

ydl_opts = {
    'format': 'bestvideo[height<=480]+bestaudio[ext=m4a]/best',
    'updatetime': False,
    'writethumbnail': True,
    'postprocessors': [{
        'key': 'EmbedThumbnail',
        'already_have_thumbnail': False,
    }],
}

with youtube_dl.YoutubeDL(ydl_opts) as ydl:
    ydl.download(['https://www.youtube.com/watch?v=BaW_jenozKc'])

Upvotes: 3

Related Questions