PHP解析 KU6视频真实地址

虽然KU6提供视频下载,但需要安装他们的极速酷6软件,大家肯定不会因为要下载一个视频而去付出安装一个软件的代价,如果能直接提取出KU6的视频的真实地址,用个下载工具不就解决,本文就与大家分享一段提取KU6视频真实地址的代码。

目前支持下面两种地址的解析:

http://v.ku6.com/show/NAmo8ZmiXq20MbBY.html

http://hd.ku6.com/show/m0OTTkGVDwbwSk6w.html

下面是详细代码,复制到ku6.php文件,即可使用。

<?php
/*
* CheonNii(泉泉)
* http://cheon.info
*/
function curl_get_contents($url)
{
if(!function_exists(‘curl_init’)) {
return false;
} else {
$user_agent = $_SERVER[‘HTTP_USER_AGENT’];
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_USERAGENT, $user_agent);
$content = curl_exec($ch);
$errormsg = curl_error($ch);
curl_close($ch);
if($errormsg != ”) {
echo $errormsg;
return false;
}
return $content;
}
}

function fsock_get_contents($url)
{
if(!function_exists(‘fsockopen’)) {
return false;
} else {
$user_agent = $_SERVER[‘HTTP_USER_AGENT’];
$url = eregi_replace(‘^http://’, ”, $url);
$temp = explode(‘/’, $url);
$host = array_shift($temp);
$path = ‘/’.implode(‘/’, $temp);
$temp = explode(‘:’, $host);
$host = $temp[0];
$port = isset($temp[1]) ? $temp[1] : 80;
$fp = @fsockopen($host, $port, $errno, $errstr, 30);
if ($fp){
@fputs($fp, “GET $path HTTP/1.1rnHost: $hostrnAccept: */*rnReferer:$urlrnUser-Agent: $user_agentrnConnection: Closernrn”);
}
$content = ”;
while ($str = @fread($fp, 4096)){
$content .= $str;
}
@fclose($fp);
//Redirect
if(preg_match(“/^HTTP/d.d 301 Moved Permanently/is”, $content)){
if(preg_match(“/Location:(.*?)rn/is”, $content, $murl)){
return fsock_get_contents($murl[1]);
}
}
//Read contents
if(preg_match(“/^HTTP/d.d 200 OK/is”, $content)){
preg_match(“/Content-Type:(.*?)rn/is”, $content, $murl);
$contentType = trim($murl[1]);
$content = explode(“rnrn”, $content, 2);
$content = $content[1];
}
return $content;
}
}

function get_page_contents($url)
{
$content = ”;
if(function_exists(‘curl_init’)) {
$content = curl_get_contents($url);
} elseif (function_exists(‘fsockopen’)) {
$content = curl_get_contents($url);
} else echo “函数 curl_init 和 fsockopen 都为关闭,请至少打开一个.”;
return $content;
}

function uni_decode($s) {
preg_match_all(‘/&#([0-9]{5});/’, $s, $html_uni);
preg_match_all(‘/\u([0-9a-f]{4})/ie’, $s, $js_uni);
$source = array_merge($html_uni[0], $js_uni[0]);
$js = array();
for($i=0;$i<count($js_uni[1]);$i++) {
$js[] = hexdec($js_uni[1][$i]);
}
$utf8 = array_merge($html_uni[1], $js);
$code = $s;
for($j=0;$j<count($utf8);$j++) {
$code = str_replace($source[$j], unicode2utf8($utf8[$j]), $code);
}
return $code;//$s;//preg_replace(‘/\u([0-9a-f]{4})/ie’, “chr(hexdec(‘\1’))”,  $s);
}

function unicode2utf8($c) {
$str=””;
if ($c < 0x80) {
$str.=chr($c);
} else if ($c < 0x800) {
$str.=chr(0xc0 | $c>>6);
$str.=chr(0x80 | $c & 0x3f);
} else if ($c < 0x10000) {
$str.=chr(0xe0 | $c>>12);
$str.=chr(0x80 | $c>>6 & 0x3f);
$str.=chr(0x80 | $c & 0x3f);
} else if ($c < 0x200000) {
$str.=chr(0xf0 | $c>>18);
$str.=chr(0x80 | $c>>12 & 0x3f);
$str.=chr(0x80 | $c>>6 & 0x3f);
$str.=chr(0x80 | $c & 0x3f);
}
return $str;
}

function get_mp4($url)
{
$mp4_info = array();
$video_data = get_page_contents($url);

preg_match(‘/title: “(.*?)”/’, $video_data, $match_title);
preg_match(‘/”f”:”(.*?)”/’, $video_data, $match_file);
$mp4_info[‘title’] = uni_decode($match_title[1]);
$mp4_info[‘file’] = uni_decode($match_file[1]);
return $mp4_info;
}
?>
<!DOCTYPE html PUBLIC “-//W3C//DTD XHTML 1.0 Transitional//EN” “http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd”>
<html xmlns=”http://www.w3.org/1999/xhtml”>
<head>
<meta http-equiv=”Content-Type” content=”text/html; charset=utf-8″ />
<title>PHP解析酷6视频mp4真实地址</title>
</head>

<body>
支持以下两种格式
<a href=”javascript://” onclick=”document.getElementById(‘url’).value = this.title;” title=”http://v.ku6.com/show/kyaZJccsLKAsgyVw.html”>http://v.ku6.com/show/kyaZJccsLKAsgyVw.html</a>
<a href=”javascript://” onclick=”document.getElementById(‘url’).value = this.title;” title=”http://hd.ku6.com/show/m0OTTkGVDwbwSk6w.html”>http://hd.ku6.com/show/m0OTTkGVDwbwSk6w.html</a>
<form action=”<?php echo $_SERVER[‘PHP_SELF’]; ?>” method=”post”>
<label>URL
<input type=”text” name=”url” id=”url” style=”width:300px;” />
</label>
<label>
<input type=”submit” name=”button” id=”button” value=”解析” />
</label>
</form>
<div style=”clear:both;”></div>
<?php
if($_POST) {
$mp4 = get_mp4($_POST[‘url’]);
echo ‘视频标题:’.$mp4[‘title’].’
‘;
$file = explode(‘,’, $mp4[‘file’]);
$s = count($file);
if($s > 1) {
echo ‘该视频由’.$s.’段组成,下载地址如下:’;
} else echo ‘视频真实地址:’;
foreach($file as $v) {
echo “<br /><a href=”$v”>$v</a>”;
}
}
?>

</body>
</html>

点击直接在线使用:KU6.PHP

下篇文章将给大家介绍:PHP解析土豆FLV真实地址

本文代码转自:http://cheon.info

思章老师

认准了方向,就要勇敢地走下去,十年磨一剑,我相信,只要坚持,一切都有可能。

相关日志

  1. 没有图片

    2010.06.04

    WordPress 3.0 RC2 发布

    小百度每都在跟进WordPress官方的更新…

  2. 没有图片

    2010.11.02

    PSD to HTML工作标准

    一.每个psd源图都有三种配色方案,要求按照…

  3. 没有图片

    2010.05.08

    与交通有关的几个值得一笑的标语

    群里618分享的几句话,觉得挺有意思,转发到…

  4. 没有图片

    2010.05.07

    绩效工资童话版

    从前有只羊,一天得干10个小时的活。有一天,…

  5. 没有图片

    2010.05.07

    学问 诗歌 男人 女人

    学问之美,在于使人一头雾水; 诗歌之美,在于…

  6. 没有图片

    2010.05.07

    从小到大

    上幼儿园,要小心被50岁老人砍;上小学,要小…

评论

还没有评论。