在服务器上设置youtube-dl来检索下载链接


Setting up youtube-dl on the server to retrieve just the download link

所以我在服务器上设置youtube-dl有问题。下面是调用YoutubeDL.py的PHP脚本。

<?php
error_reporting(-1);
$command = "usr/bin/python youtube-dl/YoutubeDL.py --get-url  " . "https://www.youtube.com/watch?v=v4kgeyM7j6Y";
header('Content-Type: text/html; charset=utf-8');
$command = escapeshellcmd($command);
$output = shell_exec($command);
echo $output;
?>

我已经将YoutubeDL.py权限设置为777,但是我没有得到任何输出。

youtube-dl/YoutubeDL.py是一个带有主类的内部文件。光跑是不够的。相反,使用以下选项之一正确安装youtube-dl:


安装全系统,例如sudo pip install youtube-dl。之后,运行youtube-dl的命令将简单地变为youtube-dl


安装并运行在其他地方,例如

curl https://yt-dl.org/latest/youtube-dl -o ./youtube-dl
chmod a+rx ./youtube-dl

该命令为./youtube-dl,或者如果省略第二行,则为python ./youtube-dl


如果您想修改源代码,按照开发人员的说明操作。要么下载tarball并解包,要么使用git:

git clone https://github.com/rg3/youtube-dl.git
youtube-dl/youtube_dl/__main__.py  # run youtube-dl

运行youtube-dl/youtube_dl/__main__.py, python -m youtube_dl时,./youtube-dl在你的Python路径,或python youtube-dl/youtube_dl/__main__.py