我正在使用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://github.com/ytdl-org/youtube-dl/blob/d4f53af482cc47b0473a3576da7ad902bea4ac39/youtube_dl/extractor/youtube.py#L1831),但是我没有找到解决此问题的任何解决方案。 先谢谢了我的帮助。
答案 0 :(得分:30)
对于 ubuntu 用户:
sudo apt purge youtube-dl
sudo pip3 install youtube-dl
答案 1 :(得分:10)
更新youtube-dl对我有帮助:youtube-dl --update
答案 2 :(得分:9)
我在 Ubuntu 20.04 上遇到了同样的错误。 我通过从以下位置下载 .deb 来更新 youtube-dl 解决了这个问题: https://packages.debian.org/sid/all/youtube-dl/download
虽然您也可以在 youtube-dl 的官方网站上获得更新。
答案 3 :(得分:7)
在 Ubuntu 上唯一对我有用的是使用 Debian 包/.deb 文件进行安装:
wget http://ftp.de.debian.org/debian/pool/main/y/youtube-dl/youtube-dl_2021.02.04.1-1_all.deb
sudo apt install ./youtube-dl_2021.02.04.1-1_all.deb
答案 4 :(得分:5)
如果您在 MacOsx 上使用 youtube-dl 命令行使用此命令更新:
sudo youtube-dl --update
答案 5 :(得分:3)
如果您安装了 pip,您可以使用它来更新 youtube-dl
这对我有帮助。
sudo pip install --upgrade youtube_dl
答案 6 :(得分:2)
由于某些视频受年龄限制,因此您可以尝试添加Cookie文件。使用此插件Chrome plugin Cookie.txt将cookie下载到txt文件中,然后使用这些--cookies /path/to/cookies/file.txt
标志不要忘记将正确的路径放置到cookies.txt文件中。
示例:
youtube-dl -n --cookies ~/Downloads/cookies.txt https://www.youtube.com/watch\?v\=h7Ii7KKapig
答案 7 :(得分:0)
根据 Manoj D Bhat 的建议,我卸载并重新安装了该程序,然后再次尝试下载 YouTube 链接“A”。这奏效了,正如预期的那样,我下载了完整的视频。超级。
但是,对于第二个视频 - 视频“B” - 它再次失败并出现相同的错误。 有趣的是,我尝试再次下载视频“A” - 使用我之前使用的相同命令 - 现在失败了。
使用新安装的程序下载一个视频后,它似乎停止工作?