我正在使用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
我在这里看到说这是因为找不到任何视频信息,我该如何解决这个问题?
https
(你写成了htps
),其次应该是/watch
而不是?watch
,所以你的操作调用行将变为operation("https://youtube.com/watch?v=...")
。我想这只是一个问题的笔误,但我希望这能解决它(我无法重现你的错误)。 - Minion Jim