YouTube-dl
error
video extraction
troubleshooting
YouTube video download

Youtube_dl ERROR YouTube said Unable to extract video data

Interview Questions practice on Codemia

Over 8,000 real interview questions from top companies, searchable by company and role.

Browse interview questions

Introduction

The youtube-dl ERROR: YouTube said: Unable to extract video data error occurs because YouTube frequently changes its page structure and API, breaking the parser in older versions of youtube-dl. The primary fix is updating to the latest version. If youtube-dl is no longer maintained or the update does not help, switch to yt-dlp, an actively maintained fork that tracks YouTube's changes more quickly.

The Error

bash
youtube-dl "https://www.youtube.com/watch?v=dQw4w9WgXcQ"

ERROR: YouTube said: Unable to extract video data

This error means youtube-dl could not parse the YouTube page to find the video stream URL. YouTube changes its front-end code regularly, and older extractors cannot parse the new format.

Fix 1: Update youtube-dl

bash
1# Update via pip
2pip install --upgrade youtube-dl
3
4# Or update the standalone binary
5youtube-dl -U
6
7# Verify the version
8youtube-dl --version

If the latest version still fails, the project may not have a fix yet for the latest YouTube changes.

yt-dlp is an actively maintained fork of youtube-dl with faster updates and additional features:

bash
1# Install yt-dlp
2pip install yt-dlp
3
4# Usage is almost identical to youtube-dl
5yt-dlp "https://www.youtube.com/watch?v=dQw4w9WgXcQ"
6
7# Update yt-dlp
8yt-dlp -U

yt-dlp is a drop-in replacement. Most youtube-dl command-line options work the same way.

Fix 3: Use Cookies for Age-Restricted or Private Videos

Some videos require authentication:

bash
1# Export cookies from your browser (use a browser extension like "Get cookies.txt")
2yt-dlp --cookies cookies.txt "https://www.youtube.com/watch?v=VIDEO_ID"
3
4# Or use browser cookies directly (yt-dlp feature)
5yt-dlp --cookies-from-browser chrome "https://www.youtube.com/watch?v=VIDEO_ID"
6yt-dlp --cookies-from-browser firefox "https://www.youtube.com/watch?v=VIDEO_ID"

Fix 4: Specify a Different Format

The default format may not be available:

bash
1# List available formats
2yt-dlp -F "https://www.youtube.com/watch?v=VIDEO_ID"
3
4# Download a specific format
5yt-dlp -f 22 "https://www.youtube.com/watch?v=VIDEO_ID"
6
7# Best video + best audio (merged)
8yt-dlp -f "bestvideo+bestaudio" "https://www.youtube.com/watch?v=VIDEO_ID"
9
10# Best quality up to 1080p
11yt-dlp -f "bestvideo[height<=1080]+bestaudio/best[height<=1080]" "URL"

Fix 5: Use a Proxy or VPN

Some videos are geo-restricted:

bash
1# Use a proxy
2yt-dlp --proxy socks5://127.0.0.1:1080 "URL"
3yt-dlp --proxy http://user:pass@proxy:8080 "URL"
4
5# Set geo bypass
6yt-dlp --geo-bypass "URL"
7yt-dlp --geo-bypass-country US "URL"

Fix 6: Clear Cache

Cached data from previous YouTube page formats can cause issues:

bash
1# youtube-dl
2youtube-dl --rm-cache-dir
3
4# yt-dlp
5yt-dlp --rm-cache-dir

Common yt-dlp Options

bash
1# Download audio only (MP3)
2yt-dlp -x --audio-format mp3 "URL"
3
4# Download with subtitles
5yt-dlp --write-subs --sub-lang en "URL"
6
7# Download a playlist
8yt-dlp --yes-playlist "PLAYLIST_URL"
9
10# Limit download speed
11yt-dlp --limit-rate 1M "URL"
12
13# Output filename template
14yt-dlp -o "%(title)s.%(ext)s" "URL"
15
16# Download from a file of URLs
17yt-dlp -a urls.txt
18
19# Verbose output for debugging
20yt-dlp -v "URL"

Python API Usage

python
1# Using yt-dlp as a Python library
2import yt_dlp
3
4def download_video(url, output_path='.'):
5    options = {
6        'format': 'bestvideo+bestaudio/best',
7        'outtmpl': f'{output_path}/%(title)s.%(ext)s',
8        'merge_output_format': 'mp4',
9    }
10
11    with yt_dlp.YoutubeDL(options) as ydl:
12        ydl.download([url])
13
14# Extract info without downloading
15def get_video_info(url):
16    with yt_dlp.YoutubeDL({'quiet': True}) as ydl:
17        info = ydl.extract_info(url, download=False)
18        return {
19            'title': info['title'],
20            'duration': info['duration'],
21            'formats': len(info['formats']),
22        }
23
24info = get_video_info("https://www.youtube.com/watch?v=VIDEO_ID")
25print(info)

Migrating from youtube-dl to yt-dlp

bash
1# Uninstall youtube-dl
2pip uninstall youtube-dl
3
4# Install yt-dlp
5pip install yt-dlp
6
7# Create an alias for backward compatibility
8alias youtube-dl='yt-dlp'
9
10# Or in ~/.bashrc / ~/.zshrc
11echo 'alias youtube-dl="yt-dlp"' >> ~/.bashrc

Most scripts that use youtube-dl work with yt-dlp without changes. The command-line interface is intentionally compatible.

Common Pitfalls

  • Using an outdated youtube-dl version: YouTube changes its page structure frequently. A version even a few weeks old may fail. Always update before troubleshooting (pip install --upgrade youtube-dl or yt-dlp -U).
  • youtube-dl is no longer actively maintained: As of late 2024, youtube-dl updates are infrequent. yt-dlp is the actively maintained fork with faster fixes for YouTube changes. Switch to yt-dlp for ongoing reliability.
  • Region-restricted content: Some videos are only available in certain countries. Use --geo-bypass or a VPN. The error message may not clearly indicate this is a geo-restriction issue.
  • Age-restricted content without cookies: Age-restricted videos require an authenticated session. Use --cookies-from-browser chrome (yt-dlp) to pass your browser's logged-in session.
  • Anti-virus or firewall blocking the download: Some security software blocks youtube-dl/yt-dlp because it downloads from video streaming sites. Add an exception in your security software if downloads fail silently or timeout.

Summary

  • Update youtube-dl to the latest version (pip install --upgrade youtube-dl)
  • Switch to yt-dlp for actively maintained YouTube support
  • Use --cookies-from-browser for age-restricted or private videos
  • Use --geo-bypass or a VPN for region-restricted content
  • Clear the cache with --rm-cache-dir if cached data causes parsing issues
  • Use -v (verbose) flag to get detailed error output for debugging

Related reading
Free course
Beginner
7 lessons
2 hours
Tackling System Design Interview Problems

A short course that equips you with the skills to approach system design interviews methodically.

Start the free course
Track what you have practised

A free account saves your progress, solutions and study plan across every problem on Codemia.

Interview Questions practice on Codemia

Over 8,000 real interview questions from top companies, searchable by company and role.

Browse interview questions

All Rights Reserved.