微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

解析获取优酷视频真实下载地址的PHP源代码

<div class="codetitle"><a style="CURSOR: pointer" data="98803" class="copybut" id="copybut98803" onclick="doCopy('code98803')"> 代码如下:

<div class="codebody" id="code98803">
<?PHP
//--调用方法/demo.PHP?url=http://v.youku.com/v_show/id_XMzkyODA2NTEy.html
echo getYoukuFlv($_GET['url']); function getYoukuFlv($url){
pregmatch("#id(.?).html#",$url,$out);
$id=$out[1];
$content=get_curl_contents('http://v.youku.com/player/getPlayList/VideoIDS/'.$id);
$data=json_decode($content);
foreach($data->data[0]->streamfileids AS $k=>$v){
$sid=getSid();
$fileid=getfileid($v,$data->data[0]->seed);
$one=($data->data[0]->segs->$k);
if($k == 'flv' || $k == 'mp4') return "http://f.youku.com/player/getFlvPath/sid/{$sid}_00/st/{$k}/fileid/{$fileid}?K={$one[0]->k}";
continue;
}
}
function get_curl_contents($url,$second = 5){
if(!function_exists('curl_init')) die('PHP.ini未开启php_curl.dll');
$c = curl_init();
curl_setopt($c,CURLOPT_URL,$url);
$UserAgent=$_SERVER['HTTP_USER_AGENT'];
curl_setopt($c,CURLOPT_USERAGENT,$UserAgent);
curl_setopt($c,CURLOPT_HEADER,0);
curl_setopt($c,CURLOPT_TIMEOUT,$second);
curl_setopt($c,CURLOPT_RETURNTRANSFER,true);
$cnt = curl_exec($c);
$cnt=mb_check_encoding($cnt,'utf-8')?iconv('gbk','utf-8//IGnorE',$cnt):$cnt; //字符编码转换
curl_close($c);
return $cnt;
}
function getSid() {
$sid = time().(rand(0,9000)+10000);
return $sid;
}
function getkey($key1,$key2){
$a = hexdec($key1);
$b = $a ^ 0xA55AA5A5;
$b = dechex($b);
return $key2.$b;
}
function getfileid($fileId,$seed) {
$mixed = getMixString($seed);
$ids = explode("
",$fileId);
unset($ids[count($ids)-1]);
$realId = "";
for ($i=0;$i < count($ids);++$i) {
$idx = $ids[$i];
$realId .= substr($mixed,$idx,1);
}
return $realId;
}
function getMixString($seed) {
$mixed = "";
$source = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMnopQRSTUVWXYZ/\:._-1234567890";
$len = strlen($source);
for($i=0;$i< $len;++$i){
$seed = ($seed 211 + 30031) % 65536;
$index = ($seed / 65536
strlen($source));
$c = substr($source,$index,1);
$mixed .= $c;
$source = str_replace($c,"",$source);
}
return $mixed;
}
?>

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。

相关推荐