PHP脚本强制下载YouTube视频 [英] php script to force download youtube video

查看:107
本文介绍了PHP脚本强制下载YouTube视频的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有Youtube视频下载脚本,它提供视频的url但不下载,它在浏览器中打开视频并播放。

I have Youtube video download script it give url of video but do not downloads, it opens the video in browser and plays.

    $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
        */
    }

我尝试了很多方法,但没有人能按我的意愿工作,我想显示一些按钮,用户可以在其中将自己选择的视频格式(例如mp4、3gp)下载到PC上。

我编写了一个脚本正在在服务器上下载0KB文件。

如果don也可以

I tried many methods but no one worked as I wanted, I want to display buttons where user can download his choice of video format like mp4, 3gp on his PC.
I wrote a script which was downloading 0KB file on server.
It will also be ok if done by jquery.

推荐答案

创建另一个文件 download.php 发送网址,文件格式为该文件

create another file download.php send url,file_format to that file

使您的链接= download.php?video_url = https:// that_lengthy_url& format = mp4-OR-3gp

download.php

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;

这篇关于PHP脚本强制下载YouTube视频的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆