下载视频未播放后,收到错误“此文件无法播放。这可能是因为文件类型不受支持,文件扩展名不正确或文件已损坏。”
$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;
}