youtube-dl is a command-line program and Python library designed to download videos from YouTube.com and many other video-hosting sites. The official PyPI package, version `2021.12.17`, is no longer actively maintained and is significantly outdated. For current site compatibility, bug fixes, and new features, users are strongly recommended to use the `yt-dlp` fork or the `youtube-dl` nightly builds, which are built from the main repository's `master` branch.
pip install youtube-dlVerified import paths — ran on the pinned version, not inferred.
This quickstart demonstrates how to programmatically download a video using the `youtube-dl` library. It configures the downloader to select the best available video and audio quality, merge them, and save the file with the video's title.
Install `yt-dlp` (`pip install yt-dlp`) or `youtube-dl-nightly` (`pip install youtube-dl-nightly`).
Regularly update the library (e.g., `pip install -U yt-dlp` or `youtube-dl -U` for manual installations) or switch to a more actively maintained fork/build.
Implement `--sleep-interval` and `--max-sleep-interval` options to add delays between downloads. Consider using cookies with `--cookies-from-browser` to mimic legitimate browsing sessions.
Ensure you are using Python 3.6 or newer. For `yt-dlp`, Python 3.10+ is recommended.
Install the Python package: `pip install youtube-dl` (or `pip install yt-dlp` for the recommended fork).
Try updating the library (`youtube-dl -U` or `pip install -U yt-dlp`). If the issue persists, try a proxy (`--proxy`), provide cookies (`--cookies-from-browser`), or check if the video is truly available and not region-locked/private.
Update `youtube-dl` or `yt-dlp` to the latest version. For `yt-dlp` especially, ensure `yt-dlp-ejs` and a JavaScript runtime (e.g., `deno` or `node.js`) are installed and accessible.
Set your system's console or terminal to use UTF-8 encoding (e.g., `chcp 65001` on Windows CMD). Alternatively, use the `--restrict-filenames` option to only allow ASCII characters, or a custom `outtmpl` that sanitizes names.
No resource links recorded.