您好,欢迎访问一九零五行业门户网

用PHP嗅探youku视频的真实地址!

php代码
<?php //--调用方法http://xiaomizhou.net/demo/flv.php?url=http://v.youku.com/v_show/id_xmzg2otq3mjqw.html echo fetch_youku_flv($_get['url']); function fetch_youku_flv($url){ preg_match("#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; }
其它类似信息

推荐信息