我正在用Python 3制作一个小的图形界面,它应该下载一个带有URL的youtube视频.

import youtube_dl # Youtube_dl is used for download the video

ydl_opt = {"outtmpl" : "/videos/%(title)s.%(ext)s", "format": "bestaudio/best"} # Here we give some advanced settings. outtmpl is used to define the path of the video that we are going to download

def operation(link):
    """
    Start the download operation
    """
    try:
        with youtube_dl.YoutubeDL(ydl_opt) as yd: # The method YoutubeDL() take one argument which is a dictionary for changing default settings
            video = yd.download([link]) # Start the download
        result.set("Your video has been downloaded !")
    except Exception:
        result.set("Sorry, we got an error.")

operation("https://youtube.com/watch?v=...")

当我执行代码时,会出现以下错误:

ERROR: YouTube said: Unable to extract video data

我看到了here,因为它找不到任何视频信息,我如何解决这个问题?

推荐答案

更新youtube dl帮助了我.根据安装方式,以下是命令:

  • youtube-dl --update(self 更新)
  • pip install -U youtube-dl(通过python)
  • brew upgrade youtube-dl(macOS+brew )
  • choco upgrade youtube-dl(Windows+chocolatey )

Python-3.x相关问答推荐

根据其他数据框架的列顺序从数据框架中进行 Select

Python网页抓取:代码输出:汤未定义

为什么我必须在绘制椭圆时代码等于两次?''

只有在Chrome尚未打开的情况下,打开Chrome后,PySimpleGUI窗口才会崩溃

这是重命名极地df列的最好方式吗?

Python3和请求-超文本标记语言:试图抓取一个网站-没有取回真正的超文本标记语言代码

如何使用PySide6创建切换框架?

While循环不停止地等待,直到时间.睡眠结束

提取图像中的背景并保存

如何确保 GCP Document AI 模型输出与输入文件同名的 JSON?

使用 multiprocessing 处理图像

如何将列表和字典逐行组合在一起

是否可以将多个 if 转换为数组?

如何将虚拟变量列转换为多列?

在python中循环处理时并行写入文件

`pyspark mllib` 与 `pyspark ml` 包

Python 解包运算符 (*)

如何在多核上运行 Keras?

如何使用 python http.server 运行 CGI hello world

python中的绝对导入是什么?