我已经在服务器上成功安装了youtube-dl,并且从命令行开始,一切正常运行。
现在,我希望能够从Web浏览器中调用网站上的链接,该链接可直接启动文件的下载。因此,按此顺序:
我对此并不十分有经验,但是仍然需要解决此问题。
最佳答案
也许有更好的方法可以做到,但是我很乐意看到它,但是,这是我解决的方法:
<?php
ignore_user_abort(true);
//getting ID from URL
$youtubeID = $_GET['videoID'] ;
//getting audio file from youtube video via youtube-dl
exec('~/bin/youtube-dl --verbose --extract-audio -o "~/html/YouTubeDownloader/%(id)s.%(ext)s" '.$youtubeID);
//downloading file to client/browser
$filename = $youtubeID.".m4a";
header("Content-disposition: attachment;filename=$filename");
header("Content-type: audio/m4a");
readfile($filename);
//deleting file again
unlink($filename);?>
关于php - YouTube-dl服务器直接文件下载,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30005667/