youtube-dl

2021.12.17 · maintenance · verified Thu Apr 16

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.

Common errors

Warnings

Install

Imports

Quickstart

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.

import youtube_dl

ydl_opts = {
    'format': 'bestvideo+bestaudio/best',
    'outtmpl': '%(title)s.%(ext)s',
    'noplaylist': True # Only download single video, not playlist
}

def download_video(url):
    try:
        with youtube_dl.YoutubeDL(ydl_opts) as ydl:
            ydl.download([url])
        print(f"Successfully downloaded: {url}")
    except Exception as e:
        print(f"Error downloading {url}: {e}")

# Replace with your desired video URL
video_url = "https://www.youtube.com/watch?v=dQw4w9WgXcQ" 
download_video(video_url)

view raw JSON →