youtube视频问题,使用php脚本下载后

时间:2018-05-04 12:11:32

标签: php download youtube

下载视频未播放后,收到错误“此文件无法播放。这可能是因为文件类型不受支持,文件扩展名不正确或文件已损坏。”

https://r1---sn-n4v7sne7.googlevideo.com/videoplayback?mm=31%2C26&mn=sn-n4v7sne7%2Csn-a5mlrn7r&id=o-AESqnRG-D_kBvnItpMhmc7wJvzd04UFgM2drxtqdRVlg&sparams=clen%2Cdur%2Cei%2Cgir%2Cid%2Cip%2Cipbits%2Citag%2Clmt%2Cmime%2Cmm%2Cmn%2Cms%2Cmv%2Cpl%2Cratebypass%2Crequiressl%2Csource%2Cexpire&ip=52.8.2.36&key=yt6&mt=1525433022&gir=yes&mv=u&ms=au%2Conr&clen=1030808&ipbits=0&fexp=23724337&signature=5B6D288692FE64C9045316DB49F44ED7A9B2B125.79F5C487797F95E2D417806D179410FF55309C5F&ratebypass=yes&c=WEB&expire=1525455044&mime=video%2Fmp4&dur=23.080&itag=18&pl=23&source=youtube&requiressl=yes&lmt=1511505645615082&ei=ZETsWoCpIpDv_APaqpPYCg&fvip=1

        $vformat = 'video/mp4'; // The MIME type of the video. e.g. video/mp4, video/webm, etc.
        parse_str(file_get_contents('http://www.youtube.com/get_video_info?video_id=T74O9LGSR-M', $video_data);
        $streams = $video_data['url_encoded_fmt_stream_map'];
        $streams = explode(',',$streams);
        foreach($streams as $stream){
        parse_str($stream,$data); //Now decode the stream
        if(stripos($data['type'],$vformat) !== false){
            $url = $data['url'].'&asv=2';
            $format = '.mp4';
            $filename = 'video1'.$format;

            header('Content-Type: application/octet-stream');
            header("Content-Transfer-Encoding: Binary");
            header("Content-disposition: attachment; filename=\"".$filename."\"");

            readfile($url);
            exit;
         }

0 个答案:

没有答案