PHP獲取youku視頻真實(shí)flv文件地址的方法
本文實(shí)例講述了PHP獲取youku視頻真實(shí)flv文件地址的方法。分享給大家供大家參考。具體分析如下:
有一站長(zhǎng)要我?guī)椭鲆粋€(gè)可以自動(dòng)測(cè)試出youku視頻網(wǎng)站的flv真實(shí)地址,下面我整理了一下午解決了此問題非常的不錯(cuò),大家可參考一下.
這個(gè)是借力打力,只是抓去朋友網(wǎng)的內(nèi)容,不過相當(dāng)好用,代碼如下:
$videourl='http://v.youku.com/v_show/id_XMjA5MjQ0OTQ0.html';
function get_content($url ,$data){
if(is_array($data)){
$data = http_build_query($data, '', '&');
}
$ch = curl_init();
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true );
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_URL,$url);
curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
$result = curl_exec($ch);
return $result;
}
$str = get_content('http://share.pengyou.com/json.php?mod=usershare&act=geturlinfo',array('url'=>$videourl));
$str=json_decode($str);
var_dump($str);
?>
這個(gè)測(cè)試出來(lái)的只是swf文件并不是我們要的flv文件了,后來(lái)參考一站長(zhǎng)的寫法進(jìn)行了改進(jìn),核心代碼如下:
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; //字符編碼轉(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;
}
?>
調(diào)用方法,代碼如下:
echo fetch_youku_flv($url);
訪問:
輸出的結(jié)果是:
這個(gè)是可以直接下載的.
希望本文所述對(duì)大家的php程序設(shè)計(jì)有所幫助。
相關(guān)文章
PHP實(shí)現(xiàn)漢字轉(zhuǎn)拼音類庫(kù)的使用方法
這篇文章主要為大家介紹了PHP實(shí)現(xiàn)漢字轉(zhuǎn)拼音類庫(kù)使用方法詳解,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進(jìn)步,早日升職加薪2023-06-06php 連接mssql數(shù)據(jù)庫(kù) 初學(xué)php筆記
如果實(shí)現(xiàn)了PHP和MySQL鏈接了,PHP和MSSQL的鏈接其實(shí)很簡(jiǎn)單; 支持MSSQL的本地鏈接和遠(yuǎn)程鏈接2010-03-03淺析PHP中的字符串編碼轉(zhuǎn)換(自動(dòng)識(shí)別原編碼)
本篇文章是對(duì)PHP中字符串編碼轉(zhuǎn)換的實(shí)現(xiàn)代碼進(jìn)行了詳細(xì)的分析介紹,需要的朋友參考下2013-07-07PHP中new static() 和 new self() 的區(qū)別介紹
這篇文章主要介紹了PHP中new static() 和 new self() 的區(qū)別介紹,需要的朋友可以參考下2015-01-01用PHP讀取flv文件的播放時(shí)間長(zhǎng)度
用PHP讀取flv文件的播放時(shí)間長(zhǎng)度的代碼,需要用的朋友可以參考下。2009-09-09