PHP获取youku视频真实flv文件地址的方法
网络编程 2021-07-05 09:50www.168986.cn编程入门
这篇文章主要介绍了PHP获取youku视频真实flv文件地址的方法,可实现针对youku视频真实地址的解析功能,非常具有实用价值,需要的朋友可以参考下
本文实例讲述了PHP获取youku视频真实flv文件地址的方法。分享给大家供大家参考。具体分析如下
有一站长要我帮助它做一个可以自动测试出youku视频网站的flv真实地址,狼蚁网站SEO优化我整理了一下午解决了此问题非常的不错,大家可参考一下.
这个是借力打力,只是抓去朋友网的内容,不过相当好用,代码如下:
代码如下:
<?php
$videourl='http://v.youku./v_show/id_XMjA5MjQ0OTQ0.html';
function get_content($url ,$data){
if(is_array($data)){
$data = http_build_query($data, '', '&');
}
$ch = curl_init();
curl_set($ch, CURLOPT_RETURNTRANSFER, true );
curl_set($ch, CURLOPT_POST, 1);
curl_set($ch, CURLOPT_HEADER, 0);
curl_set($ch, CURLOPT_URL,$url);
curl_set($ch, CURLOPT_POSTFIELDS, $data);
$result = curl_exec($ch);
return $result;
}
$str = get_content('http://share.pengyou./json.php?mod=usershare&act=geturlinfo',array('url'=>$videourl));
$str=json_decode($str);
var_dump($str);
?>
$videourl='http://v.youku./v_show/id_XMjA5MjQ0OTQ0.html';
function get_content($url ,$data){
if(is_array($data)){
$data = http_build_query($data, '', '&');
}
$ch = curl_init();
curl_set($ch, CURLOPT_RETURNTRANSFER, true );
curl_set($ch, CURLOPT_POST, 1);
curl_set($ch, CURLOPT_HEADER, 0);
curl_set($ch, CURLOPT_URL,$url);
curl_set($ch, CURLOPT_POSTFIELDS, $data);
$result = curl_exec($ch);
return $result;
}
$str = get_content('http://share.pengyou./json.php?mod=usershare&act=geturlinfo',array('url'=>$videourl));
$str=json_decode($str);
var_dump($str);
?>
这个测试出来的只是swf文件并不是我们要的flv文件了,后来参考一站长的写法进行了改进,核心代码如下:
代码如下:
<?php
function fetch_youku_flv($url){
preg_match("#id_(.?).html#",$url,$out);
$id=$out[1];
$content=get_curl_contents('http://v.youku./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./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_set($c,CURLOPT_URL,$url);
$UserAgent=$_SERVER['HTTP_USER_AGENT'];
curl_set($c,CURLOPT_USERAGENT,$UserAgent);
curl_set($c,CURLOPT_HEADER,0);
curl_set($c,CURLOPT_TIMEOUT,$second);
curl_set($c,CURLOPT_RETURNTRANSFER, true);
$t = curl_exec($c);
$t=mb_check_encoding($t,'utf-8')?iconv('gbk','utf-8//IGNORE',$t):$t; //字符编码转换
curl_close($c);
return $t;
}
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;
}
?>
function fetch_youku_flv($url){
preg_match("#id_(.?).html#",$url,$out);
$id=$out[1];
$content=get_curl_contents('http://v.youku./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./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_set($c,CURLOPT_URL,$url);
$UserAgent=$_SERVER['HTTP_USER_AGENT'];
curl_set($c,CURLOPT_USERAGENT,$UserAgent);
curl_set($c,CURLOPT_HEADER,0);
curl_set($c,CURLOPT_TIMEOUT,$second);
curl_set($c,CURLOPT_RETURNTRANSFER, true);
$t = curl_exec($c);
$t=mb_check_encoding($t,'utf-8')?iconv('gbk','utf-8//IGNORE',$t):$t; //字符编码转换
curl_close($c);
return $t;
}
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;
}
?>
调用方法,代码如下:
代码如下:
$url='http://v.youku./v_show/id_XMzg2OTQ3MjQw.html';
echo fetch_youku_flv($url);
echo fetch_youku_flv($url);
访问:
代码如下:
http://xiaomizhou./demo/flv.php?url=http://v.youku./v_show/id_XMzg2OTQ3MjQw.html
输出的结果是:
代码如下:
http://f.youku./player/getFlvPath/sid/138035737110468_00/st/flv/fileid/03000201004F97EF4A2E350467A09DB266E872-5522-225F-DC45-40B4E1F9BE49?K=c2a4327df2bb5a65261d40ea
这个是可以直接下载的.
希望本文所述对大家的php程序设计有所帮助。
编程语言
- 如何快速学会编程 如何快速学会ug编程
- 免费学编程的app 推荐12个免费学编程的好网站
- 电脑怎么编程:电脑怎么编程网咯游戏菜单图标
- 如何写代码新手教学 如何写代码新手教学手机
- 基础编程入门教程视频 基础编程入门教程视频华
- 编程演示:编程演示浦丰投针过程
- 乐高编程加盟 乐高积木编程加盟
- 跟我学plc编程 plc编程自学入门视频教程
- ug编程成航林总 ug编程实战视频
- 孩子学编程的好处和坏处
- 初学者学编程该从哪里开始 新手学编程从哪里入
- 慢走丝编程 慢走丝编程难学吗
- 国内十强少儿编程机构 中国少儿编程机构十强有
- 成人计算机速成培训班 成人计算机速成培训班办
- 孩子学编程网上课程哪家好 儿童学编程比较好的
- 代码编程教学入门软件 代码编程教程