使用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的更新)
- 安装yt-dlp:
pip install yt-dlp - 修改代码,仅替换依赖库相关部分,其余逻辑不变:
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)
- 安装yt-dlp:
备选方案:升级到youtube-dl开发版(不推荐)
若坚持使用youtube-dl,可安装最新的开发版本,但后续仍可能因YouTube更新再次失效:pip install --upgrade git+https://github.com/ytdl-org/youtube-dl.git
内容的提问来源于stack exchange,提问作者FMJUKE
相关产品推荐
相关产品推荐

