解析取得優(yōu)酷視頻真實下載地址的PHP源代碼_php指南
發(fā)表時間:2023-04-08 來源:本站整理相關(guān)軟件相關(guān)文章人氣:
優(yōu)酷作為中國最大的數(shù)字娛樂平臺,優(yōu)酷的內(nèi)容體系由劇集、綜藝、電影、動漫四大頭部內(nèi)容矩陣和資訊、紀(jì)實、文化財經(jīng)、時尚生活、音樂、體育、游戲、自頻道八大垂直內(nèi)容群構(gòu)成,擁有國內(nèi)最大內(nèi)容庫。
代碼如下:
<?php
//--調(diào)用方法/demo.php?url=http://v.youku.com/v_show/id_XMzkyODA2NTEy.html
echo getYoukuFlv($_GET['url']);
function getYoukuFlv($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; //字符編碼轉(zhuǎn)換
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;
}
?>
優(yōu)酷網(wǎng)本著“世界都在看”的目標(biāo)以及“快者為王”的產(chǎn)品理念,打造出最全、最快、最好的視頻數(shù)據(jù)庫,引領(lǐng)互聯(lián)網(wǎng)視頻時代文化潮流。讓用戶在第一時間了解視頻文化走勢,凝聚超人氣視頻榜打造海量精品庫。