Skip to main content
The YoutubeDL class is the central component of yt-dlp’s Python API. It handles video downloading, information extraction, and coordination of extractors and post-processors.

Class Overview

dict
default:"{}"
Dictionary of options to configure the downloader behavior
boolean | string
default:"true"
Whether to load default extractors and print header. Set to ‘no_verbose_header’ to skip header printing

Constructor Parameters

The params dictionary accepts numerous configuration options. Below are the most important ones:

Authentication

string
Username for authentication purposes
string
Password for authentication purposes
string
Password for accessing a video
boolean
default:"false"
Use netrc for authentication instead

Output Options

string | dict
Output filename template. Can be a string or dictionary with keys ‘default’, ‘chapter’, etc.Example: '%(title)s.%(ext)s' or {'default': '%(title)s.%(ext)s'}
boolean
default:"false"
Do not print messages to stdout
boolean
default:"false"
Print additional info to stdout
boolean
default:"false"
Do not print out anything for warnings

Download Control

string | function
Video format code. See format selection documentation. Can also be a function that takes context and returns formats to download.Examples: 'best', 'bestvideo+bestaudio', 'worst[height>=480]'
boolean
default:"false"
Skip the actual download of the video file
boolean
Do not download video files. If unset, simulate only if listing formats/subtitles/thumbnails
boolean | string
default:"false"
Do not stop on download errors. Can be ‘only_download’ to ignore only download errors
boolean | string
default:"false"
Do not resolve URLs further
  • False: Always process (default for API)
  • True: Never process
  • 'in_playlist': Do not process inside playlists
  • 'discard': Always process but don’t return result from playlists
  • 'discard_in_playlist': Same as discard but only for playlists (default for CLI)

Format Selection

list
List of fields by which to sort video formats
boolean
default:"false"
Force the given format_sort
boolean
default:"false"
Allow multiple video streams to be merged into a single file
boolean
default:"false"
Allow multiple audio streams to be merged into a single file

Filesystem Options

dict
Dictionary of output paths. Allowed keys are ‘home’, ‘temp’ and output template types
boolean
default:"false"
Do not allow ”&” and spaces in file names
boolean
Force filenames to be Windows compatible (true) or sanitize minimally (false)
boolean
Overwrite all files if true, overwrite only non-video files if None, don’t overwrite if false

Metadata Options

boolean
default:"false"
Write the video description to a .info.json file
boolean
default:"false"
Write the thumbnail image to a file
boolean
default:"false"
Write the video subtitles to a file
boolean
default:"false"
Write automatically generated subtitles to a file
boolean
default:"false"
Extract video comments (requires writeinfojson to write to disk)

Network Options

string
URL of the proxy server to use
number
Time to wait for unresponsive hosts, in seconds
dict
Dictionary of custom headers to be used for all requests
string
Client-side IP address to bind to
ImpersonateTarget
Client to impersonate for requests

Post-Processing

list
List of post-processor dictionaries. Each must have a ‘key’ field with the post-processor name
boolean
default:"false"
Keep the video file after post-processing
string
Path to the ffmpeg binary or its containing directory

Main Methods

download()

Download videos from a list of URLs.
list[str]
required
List of URLs to download
int
Exit code (0 for success, non-zero for errors)
Example:

extract_info()

Extract and return the information dictionary of a URL.
string
required
URL to extract information from
boolean
default:"true"
Whether to download videos
string
Use only the extractor with this key (e.g., ‘Youtube’, ‘Generic’)
boolean
default:"true"
Whether to resolve all unresolved references (URLs, playlist items). Must be True for download to work
dict
Dictionary containing extra values to add to the info (for internal use)
boolean
default:"false"
Force using the generic extractor (deprecated, use ie_key=‘Generic’)
dict | None
Information dictionary containing video metadata and formats
Example:

add_post_processor()

Add a post-processor to the downloader.
PostProcessor
required
Post-processor instance to add
string
default:"post_process"
When to run the post-processor. Valid values: ‘pre_process’, ‘after_filter’, ‘before_dl’, ‘post_process’, ‘after_move’, ‘after_video’, ‘playlist’
Example:

add_progress_hook()

Add a callback function for download progress updates.
callable
required
Function that receives a dictionary with progress information
The progress hook receives a dictionary with these keys:
  • status: One of “downloading”, “error”, or “finished”
  • filename: Final filename
  • downloaded_bytes: Bytes downloaded so far
  • total_bytes: Total size of the file
  • speed: Download speed in bytes/second
  • eta: Estimated time remaining
Example:

Context Manager

The YoutubeDL class supports context manager protocol:
This ensures proper cleanup of resources like cookies and temporary files.

Class Methods

validate_outtmpl()

Validate an output template string.
Returns an error message if the template is invalid, or None if valid.

Utility Methods

to_screen()

Print a message to the screen output.

report_warning()

Report a warning message.

report_error()

Report an error message.

write_debug()

Write a debug message.

Example: Complete Configuration