Kankanews.class.php 1.86 KB
<?php
class Util_Video_Api_Kankanews extends Util_Video_Api
{
    private $xmlurl = 'http://www.kankanews.com/dataservice/InitPlayer.php';
    private $swfurl = 'http://www.kankanews.com/object/kankanewsplayer3.0.swf?autoPlay=true&width=600&height=490&streamType=recorded&
    cid={CategoryId}&vid={ContentId}&server=http://www.kankanews.com/dataservice/';
    public function getData($url)
    {
        $id = $this->getid($url);
        $params = 'parameter=' . json_encode($id) . '&method=InitPlayer';
        $infodat = Util_Video_ApiConnect::get($this->xmlurl, array(CURLOPT_POSTFIELDS => $params));
        $infodat = str_replace("<div id=\"main\">\"", '', $infodat);
        $infodat = str_replace("\"</div>", '', $infodat);
        $infodat = str_replace("\\/", '/', $infodat);
        $infodat = '<?xml version="1.0" encoding="utf-8"?>' . $infodat;
        $infodat = @simplexml_load_string($infodat);
        if($infodat == null)
        {
            throw new Util_Video_ApiException('simplexml_load_file 不存在');
        }
        $dataobj = new Util_Video_Data($this->id);
        $swfurl = str_ireplace("{CategoryId}", $id['CategoryId'], $this->swfurl);
        $dataobj->swf = str_ireplace("{ContentId}", $id['ContentId'], $swfurl);
        $dataobj->thumb = (string) $infodat->currentvod->imgurl;
        $dataobj->time = "";
        $title = preg_replace("#\\\u([0-9a-f]{4})#ie", "iconv('UCS-2', 'UTF-8//IGNORE', pack('H4', '\\1'))", (string) $infodat->currentvod->name);
        $dataobj->title = $title;
        $dataobj->source = '来自于kankanews.com';
        return $dataobj;
    }
    private function getid($url)
    {
        $url = $this->getUrl($url);
        $ids = str_replace("vods/", '', strstr($url, "vods/"));
        $ids = explode('/', $ids);
        return array(
            'CategoryId' => $ids[0], 
            'ContentId' => $ids[1]
        );
    }
}

?>