You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

使用Python嵌入youtube-dl 2020.3.24下载YouTube视频时遭遇“Unable to extract video data”错误求助

Why You're Getting "Unable to extract video data" Error & How to Fix It

Hey there, let's break down what's going wrong here:

The Root Cause

Your youtube-dl version (2020.3.24) is way out of date—and here's why that matters:

  • youtube-dl stopped active development back in 2021. Since then, YouTube has repeatedly updated its page structure, anti-scraping mechanisms, and video data APIs.
  • Old versions like 2020.3.24 simply don't know how to parse YouTube's current webpage layout, hence the "Unable to extract video data" error.

The Fix: Switch to yt-dlp

The best solution is to use yt-dlp—an actively maintained fork of youtube-dl that keeps up with YouTube's constant changes. Here's how to make the switch:

  1. Uninstall the outdated youtube-dl
    Run this command in your terminal:

    pip3 uninstall youtube-dl
    
  2. Install yt-dlp
    Use pip to install the latest version:

    pip3 install yt-dlp
    
  3. Update your code
    The API is almost identical to youtube-dl, so you only need to change the import line. Here's your modified script:

    # ydl1.py
    from __future__ import unicode_literals
    import yt_dlp
    
    ydl_opts = {}
    with yt_dlp.YoutubeDL(ydl_opts) as ydl:
        ydl.download(['https://www.youtube.com/watch?v=dP15zlyra3c'])
    
  4. Run the script again
    Execute your updated ydl1.py—it should now download the video without issues.

Bonus: Customize Your Downloads (Optional)

yt-dlp supports all the old youtube-dl options plus tons more. For example, to download the highest quality combined audio+video, you could update ydl_opts like this:

ydl_opts = {
    'format': 'bestvideo+bestaudio/best',
}

内容的提问来源于stack exchange,提问作者Tiel

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.04.29 16:04:07