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
Dictionary of options to configure the downloader behavior
Whether to load default extractors and print header. Set to ‘no_verbose_header’ to skip header printing
Constructor Parameters
Theparams dictionary accepts numerous configuration options. Below are the most important ones:
Authentication
Username for authentication purposes
Password for authentication purposes
Password for accessing a video
Use netrc for authentication instead
Output Options
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'}Do not print messages to stdout
Print additional info to stdout
Do not print out anything for warnings
Download Control
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]'Skip the actual download of the video file
Do not download video files. If unset, simulate only if listing formats/subtitles/thumbnails
Do not stop on download errors. Can be ‘only_download’ to ignore only download errors
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 of fields by which to sort video formats
Force the given format_sort
Allow multiple video streams to be merged into a single file
Allow multiple audio streams to be merged into a single file
Filesystem Options
Dictionary of output paths. Allowed keys are ‘home’, ‘temp’ and output template types
Do not allow ”&” and spaces in file names
Force filenames to be Windows compatible (true) or sanitize minimally (false)
Overwrite all files if true, overwrite only non-video files if None, don’t overwrite if false
Metadata Options
Write the video description to a .info.json file
Write the thumbnail image to a file
Write the video subtitles to a file
Write automatically generated subtitles to a file
Extract video comments (requires writeinfojson to write to disk)
Network Options
URL of the proxy server to use
Time to wait for unresponsive hosts, in seconds
Dictionary of custom headers to be used for all requests
Client-side IP address to bind to
Client to impersonate for requests
Post-Processing
List of post-processor dictionaries. Each must have a ‘key’ field with the post-processor name
Keep the video file after post-processing
Path to the ffmpeg binary or its containing directory
Main Methods
download()
Download videos from a list of URLs.List of URLs to download
Exit code (0 for success, non-zero for errors)
extract_info()
Extract and return the information dictionary of a URL.URL to extract information from
Whether to download videos
Use only the extractor with this key (e.g., ‘Youtube’, ‘Generic’)
Whether to resolve all unresolved references (URLs, playlist items). Must be True for download to work
Dictionary containing extra values to add to the info (for internal use)
Force using the generic extractor (deprecated, use ie_key=‘Generic’)
Information dictionary containing video metadata and formats
add_post_processor()
Add a post-processor to the downloader.Post-processor instance to add
When to run the post-processor. Valid values: ‘pre_process’, ‘after_filter’, ‘before_dl’, ‘post_process’, ‘after_move’, ‘after_video’, ‘playlist’
add_progress_hook()
Add a callback function for download progress updates.Function that receives a dictionary with progress information
status: One of “downloading”, “error”, or “finished”filename: Final filenamedownloaded_bytes: Bytes downloaded so fartotal_bytes: Total size of the filespeed: Download speed in bytes/secondeta: Estimated time remaining