Ku6.class.php 3.44 KB
<?php
class Util_Video_Api_Ku6 extends Util_Video_Api
{
    private $jsonurl = "http://vo.ku6.com/fetchVideo4Player/1/{id}.html";
    private $jsonurl_2 = "http://vo.ku6.com/fetchVideo4Player/{id}.html";
    private $htmlurl = "http://v.ku6.com/show/{id}.html";
    //酷六网
    const KU6_VIDEO_PID = 'D13aSslTjemFkeajqwSXqB5IAvOWh5uZ9fIrCjZ7zQ9AVm3-YPi7mLxrcgbOk21mkhSQlw..';
    private static $ku6_video_api = 'http://v.ku6.com/openapi/repaste.htm?t=fetchVideoInfo&pid=%s&id=%s'; //酷六网视频接口
    
    public function getData($url)
    {
        $idandswf = $this->getid_2($url);
        $api_url = sprintf ( self::$ku6_video_api, self::KU6_VIDEO_PID, $this->id );
        $result = Util_Video_ApiConnect::get($api_url);
        $vinfo = ( array ) simplexml_load_string ( $result, 'SimpleXMLElement', LIBXML_NOCDATA );
        if(!empty($vinfo))
        {
            $data = new Util_Video_Data($this->id);
            $data->swf = (string) $vinfo['result']->playswf;
            $data->title = (string) $vinfo['result']->title;
            $data->thumb = (string) $vinfo['result']->picPath;
        }
        else
        {
            $data = $this->getViolentData($url);
        }
        return $data;
    }
    
    /**
     * 暴力破解
     */
    private function getViolentData($url)
    {
        if(preg_match("/^http:\/\/v\.ku6\.com\/show\/.*\.html$/siU", $url))
        {
            $idandswf = $this->getid($url);
            $jsonurl = str_ireplace("{id}", $this->id, $this->jsonurl);
        }
        else if(preg_match("/http:\/\/v\.ku6\.com\/special\/show_.*\/.*\.html$/siU", $url))
        {
            $idandswf = $this->getid_2($url);
            $jsonurl = str_ireplace("{id}", $this->id, $this->jsonurl_2);
        }
        else
        {
            return new Util_Video_ApiException('simplexml_load_file 不存在');
        }
        $dat = Util_Video_ApiConnect::get($jsonurl);
        $jsonobj = json_decode($dat);
        if(!$jsonobj->status)
        {
            throw new Util_Video_ApiException('数据解析失败');
        }
        $dataobj = new Util_Video_Data($this->id);
        $dataobj->swf = $idandswf['swf'];
        $dataobj->thumb = $jsonobj->data->bigpicpath;
        $dataobj->time = $jsonobj->data->vtime;
        $dataobj->title = $jsonobj->data->t;
        $dataobj->source = '来自于ku6.com';
        unset($dat);
        return $dataobj;
    }
    private function getid($url)
    {
        $url = $this->getUrl($url);
        if(!preg_match("/^http:\/\/.*/i", $url))
        {
            $url = str_ireplace("{id}", $url, $this->htmlurl);
        }
        $content = Util_Video_ApiConnect::get($url);
        if(preg_match_all("/outSideSwfCode.*value=\"(.*)\"/siU", $content, $flashurl, 2))
        {
            $swf = $flashurl[0][1];
            $urlid = preg_replace("/\/.*$/si", "", preg_replace("/^.*refer\//si", "", $swf));
        }
        else
        {
            throw new Util_Video_ApiException("数据解析失败");
        }
        $this->id = $urlid;
        return array(
                    "swf" => $swf, 
                    "id" => $urlid
                    );
    }
    private function getid_2($url)
    {
        $url = $this->getUrl($url);
        $id = trim(str_replace(strrchr($url, '.'), '', substr(strrchr($url, '/'), 1)));
        $swfurl = "http://player.ku6.com/refer/$id/v.swf";
        $this->id = $id;
        return array(
            "swf" => $swfurl, 
            "id" => $id
        );
    }
}

?>