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

使用youtube_dl下载YouTube视频报错:Unable to extract uploader_id

问题:YouTube视频下载报错“Unable to extract uploader id”

我编写了如下Python代码用于下载YouTube视频:

import youtube_dl

def download_youtube_video(url):
    ydl_opts = {
        'format': 'bestvideo+bestaudio/best',
        'outtmpl': '%(title)s.%(ext)s',
    }
    with youtube_dl.YoutubeDL(ydl_opts) as ydl:
        try:
            info_dict = ydl.extract_info(url, download=True)
            video_title = info_dict.get('title', None)
            print(f"Downloaded '{video_title}' successfully!")
        except Exception as e:
            print("An error occurred during the download:")
            print(str(e))

video_url = 'https://www.youtube.com/watch?v=nWxB9yiYAgo'
download_youtube_video(video_url)

运行后返回错误:

ERROR: Unable to extract uploader id; please report this issue on https://yt-dl.org/bug . Make sure you are using the latest version; see https://yt-dl.org/update on how to update. Be sure to call youtube-dl with the --verbose flag and include its complete output.

我尝试调整代码结构,但问题依旧,请问我遗漏了什么?


解决方案

核心原因

youtube-dl已经停止维护,YouTube页面结构更新后,旧版本的youtube-dl无法适配新的解析规则,导致提取上传者ID失败。

具体解决步骤

  • 推荐方案:替换为yt-dlp(youtube-dl的活跃维护分支,持续适配YouTube的更新)

    1. 安装yt-dlp:
      pip install yt-dlp
      
    2. 修改代码,仅替换依赖库相关部分,其余逻辑不变:
      import yt_dlp
      
      def download_youtube_video(url):
          ydl_opts = {
              'format': 'bestvideo+bestaudio/best',
              'outtmpl': '%(title)s.%(ext)s',
          }
          with yt_dlp.YoutubeDL(ydl_opts) as ydl:
              try:
                  info_dict = ydl.extract_info(url, download=True)
                  video_title = info_dict.get('title', None)
                  print(f"Downloaded '{video_title}' successfully!")
              except Exception as e:
                  print("An error occurred during the download:")
                  print(str(e))
      
      video_url = 'https://www.youtube.com/watch?v=nWxB9yiYAgo'
      download_youtube_video(video_url)
      
  • 备选方案:升级到youtube-dl开发版(不推荐)
    若坚持使用youtube-dl,可安装最新的开发版本,但后续仍可能因YouTube更新再次失效:

    pip install --upgrade git+https://github.com/ytdl-org/youtube-dl.git
    

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.07.17 17:20:13