0

我已经在我的服务器上成功安装了 youtube-dl,并且从命令行一切都像魅力一样工作。

现在我希望能够从我的网络浏览器调用我网站上的链接,该链接直接启动文件的下载。所以按照这个顺序:

  1. 在浏览器中打开网站(例如http://example.com/download.php?v=as43asx3

  2. YouTube-dl 处理输入

  3. 网络浏览器下载文件

  4. 临时文件将从服务器中删除

我对此不是很有经验,但仍然需要解决这个问题。

4

1 回答 1

1

可能有更好的方法可以做到这一点,我很高兴看到它,但是,这是我解决它的方法:

<?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);?>
于 2015-05-04T21:03:40.120 回答