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.16

    10个Web2.0配色方案网站

    这10个网站有的可以在线配色,有的是提供一些…

  2. 没有图片

    2010.05.18

    改变人生的32句励志名言(转载)

    1、大多数人想要改造这个世界,但却罕有人想改…

  3. 没有图片

    2011.03.11

    WordPress 自定义字段插件 Roban metabox

    用了很多WordPress的自定义字段功能,…

  4. 没有图片

    2019.04.21

    寻找那些不能够被满足的深层兴趣,比如爱、成长…

  5. 没有图片

    2010.05.12

    关闭WordPress自动修订和自动保存功能

    蓦然已经写了几篇日志了,结果回过头来发现各日…

  6. 没有图片

    2011.03.10

    15款 WordPress 移动设备主题

    随着科技的发展,广大网友除了用计算机上网外,…

评论

还没有评论。