我已经在PHP中创建了一个脚本来将youtube视频最近流到clinets,并且我认为通过修改一些我的脚本可以适合您的目的。
这里是我的PHP脚本:
<?php
@set_time_limit(0); //disable time limit to make sure the whole video is streamed to the client
$id = $_GET['id']; //the youtube video ID
$type = $_GET['type']; //the MIME type of the desired format
parse_str(file_get_contents('http://www.youtube.com/get_video_info?video_id='.$id),$info); //get video info
$streams = explode(',',$info['url_encoded_fmt_stream_map']); //split the stream map into streams
foreach($streams as $stream){
parse_str($stream,$real_stream); //parse the splitted stream
$stype = $real_stream['type']; //the MIME type of the stream
if(strpos($real_stream['type'],';') !== false){ //if a semicolon exists, that means the MIME type has a codec in it
$tmp = explode(';',$real_stream['type']); //get rid of the codec
$stype = $tmp[0];
unset($tmp);
}
if($stype == $type && ($real_stream['quality'] == 'large' || $real_stream['quality'] == 'medium' || $real_stream['quality'] == 'small')){ //check whether the format is the desired format
header('Content-type: '.$stype); //send the HTTP headers
header('Transfer-encoding: chunked'); //necessary for streaming
@readfile($real_stream['url'].'&signature='.$real_stream['sig']); //send the content to the client
ob_flush(); //disable PHP caching
flush(); //flush the content out
break;
}
}
?>
我希望它可以帮助你。
P.S.您需要从服务器发送内容,因为视频URL因ISP而异。
既然你得到404,使用的是什么网址?你可以发布一些示例代码来获取信息和匹配数据吗? – drew010
YouTube不允许你这样做吗? –
它实际上是一个403,你可以在这个URL中看到它:http://oo.preferred.iad09s12.v5.lscache8.c.youtube.com/videoplayback?sparams=id,expire,ip,ipbits,itag,source ,ratebypass,CP&FEXP = 907911,914060,916201&ITAG = 43&IP = 208.0.0.0&签名= 1810EA75ADD7E30581426A5262C030CF82348A98。5C2D5385C0DD8FCFCF46EF43BD7223C894825DB6&sver = 3&ratebypass = YES&源= YouTube和到期= 1322629200&键= YT1&ipbits = 8&CP = U0hRR1ZNV19FSkNOMV9OR0FDOlBIZnZ0Zl9jdXNF&ID = 1c8acc21e379b6d1和质量=培养基fallback_host = tc.v5.cache8.c.youtube.com&类型=视频/ WEBM – iwek