我有Youtube视频下载脚本,它提供视频网址但不下载,它在浏览器中打开视频并播放。
$id = 'jNQXAC9IVRw';//$_GET['v'];
parse_str(file_get_contents("http://youtube.com/get_video_info?video_id=".$id),$info);
$streams = $info['url_encoded_fmt_stream_map'];
$streams = explode(',',$streams);
foreach($streams as $stream){
parse_str($stream,$data);
echo '<a href="'.$data['url'].'" class="btn btn-success">'.$data['quality'].'</a> ';
/*echo $data['url'];
*returns url like this
*http://r2---sn-2uja-3ipd.googlevideo.com/videoplayback?mime=video%2Fwebm&upn=wdfTtFFSMNA&source=youtube&mt=1484446843&ms=au&expire=1484468585&initcwndbps=187500&ipbits=0&pl=24&itag=43&sparams=dur%2Cid%2Cinitcwndbps%2Cip%2Cipbits%2Citag%2Clmt%2Cmime%2Cmm%2Cmn%2Cms%2Cmv%2Cpl%2Cratebypass%2Csource%2Cupn%2Cexpire&id=o-AGqBaImYFicQvH1J3Tmt4QGqt817uD_Pw-vF9MF8asMy&dur=0.000&mm=31&key=yt6&mn=sn-2uja-3ipd&signature=C38C1D21BC1B7F4658BCEF30DFC94E1ACBE1FC6D.356305D4012AE391A24283CA46950BBCDE7EB7CE&lmt=1418224509434980&mv=m&ratebypass=yes&ip=119.154.139.153
*/
}
我尝试了很多方法,但没有人按我的意愿工作,我想显示按钮,用户可以在PC上下载他选择的视频格式,如mp4,3gp。
我写了一个在服务器上下载0KB文件的脚本
如果由jquery完成也可以。
答案 0 :(得分:0)
创建另一个文件download.php
将url,file_format发送到该文件
让你的链接= download.php?video_url=https://that_lengthy_url&format=mp4-OR-3gp
的download.php
$format = $_GET['format'];
$filename = 'video.'.$format;
$url = $_GET['video_url'];
header('Content-Type: application/octet-stream');
header("Content-Transfer-Encoding: Binary");
header("Content-disposition: attachment; filename=\"".$filename."\"");
readfile($url);
exit;