【发布时间】:2020-12-28 04:33:57
【问题描述】:
我正在用 Python 3 制作一个小图形界面,它应该下载一个带有 URL 的 youtube 视频。
我为此使用了youtube_dl 模块。
这是我的代码:
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是因为没有找到任何视频信息,我该如何解决这个问题?
【问题讨论】:
-
如果您能够将其归结为引发此错误的特定部分,您将获得更多的牵引力。我经常担心没有包含足够的数据,但如果它是一个简单的问题,人们通常更有可能参与,而不是乍一看看起来像“为我做这个”的问题。我不会对你进行任何诽谤,但人们会经常点击、浏览和回击这些内容。
-
是针对任何视频还是特定视频引发了错误? (我想我在 Reddit 上的某个地方读到,这可能是由于年龄限制而发生的)
-
@SolebaySharp 抱歉,只是因为我不确定 youtube_db 外部的东西是否会阻止我的程序
-
@MinionJim 我用多个视频测试了我的程序,但总是遇到同样的错误
-
我刚刚测试了您的代码,除了网址错误之外,它可以正常工作。首先,你拼错了
https(你有htps),其次它应该是/watch而不是?watch,所以你的操作调用线会变成operation("https://youtube.com/watch?v=...")。我认为这只是问题的一个错字,但我希望这能解决它(我无法重现你的错误)
标签: python python-3.x download youtube youtube-dl