如何修复 youtube-dl:运行它时出现语法错误的错误消息

如何修复 youtube-dl:运行它时出现语法错误的错误消息

我最近从头开始安装了 22.04。刚才我按照说明使用 wget(来自 github.com)安装了 youtube-dl:

sudo wget https://yt-dl.org/downloads/latest/youtube-dl -O /usr/local/bin/youtube-dl
sudo chmod a+rx /usr/local/bin/youtube-dl

它似乎已下载,但使用后却显示以下内容:

$ youtube-dl https://www.youtube.com/watch?v=xSyDTIAX_oE
/usr/local/bin/youtube-dl: line 1: --2023-03-05: command not found
/usr/local/bin/youtube-dl: line 2: syntax error near unexpected token `('
/usr/local/bin/youtube-dl: line 2: `Resolving yt-dl.org (yt-dl.org)... 95.143.172.170, 2001:1a50:11:0:5f:8f:acaa:177'

我不确定我是否提供了足够/适当的信息来提出我的问题。如果我需要解释其他内容,请告诉我。显然 youtube-dl 有一段时间无法正常工作,但网站说它又恢复正常了。我不知道这是否是问题的一部分?

我按照建议尝试了以下命令:

file /usr/local/bin/youtube-dl
/usr/local/bin/youtube-dl: Unicode text, UTF-8 text, with very long lines (564)

head /usr/local/bin/youtube-dl
--2023-03-05 12:38:51--  https://yt-dl.org/downloads/latest/youtube-dl
Resolving yt-dl.org (yt-dl.org)... 95.143.172.170, 2001:1a50:11:0:5f:8f:acaa:177
Connecting to yt-dl.org (yt-dl.org)|95.143.172.170|:443... connected.
HTTP request sent, awaiting response... 302 Found
Location: https://yt-dl.org/downloads/2021.12.17/youtube-dl [following]
--2023-03-05 12:38:52--  https://yt-dl.org/downloads/2021.12.17/youtube-dl
Reusing existing connection to yt-dl.org:443.
HTTP request sent, awaiting response... 302 Found
Location: https://github.com/ytdl-org/youtube-dl/releases/download/2021.12.17/youtube-dl [following]
--2023-03-05 12:38:52--  https://github.com/ytdl-org/youtube-dl/releases/download/2021.12.17/youtube-dl

答案1

我发现 youtube-dl 已经过时了,因此我找到了解决方案:

https://www.linuxbabe.com/desktop-linux/install-youtube-dl-linux-use

我安装了:

pip3 install yt-dlp

运行正常:

yt-dlphttps://www.youtube.com/watch?v=youtube-dl_has_made_the_world_better

答案2

尝试这个

pip install --upgrade --force-reinstall "git+https://github.com/ytdl-org/youtube-dl.git"

来源: https://github.com/ytdl-org/youtube-dl/issues/31530#issuecomment-1435477247

答案3

您的 youtube-dl 下载似乎不完整,其中/usr/local/bin/youtube-dl包含错误消息而不是实际的二进制文件。首先,将其删除。

sudo rm /usr/local/bin/youtube-dl

然后,使用 python3-pip 安装它。

sudo apt install python3-pip
pip3 install --user youtube-dl

最后,您可能必须运行source .bashrc,以便 youtube-dl 可执行文件在里面$PATH

相关内容