cntv.class.php 1.59 KB
<?php
class Util_Video_Api_Cntv extends Util_Video_Api
{
    private $jsonurl = 'http://vdd.player.cntv.cn/index.php?pid={pid}';
    /**
     * @param unknown_type $url
     */
    public function getData($url)
    {
        $id = $this->getid($url);
        $infourl = str_ireplace("{pid}", $id, $this->jsonurl);
        $infodat = Util_Video_ApiConnect::get($infourl);
        $infodat = json_decode($infodat);
        if($infodat == null)
        {
            throw new Util_Video_ApiException('数据解析失败');
        }
        $dataobj = new Util_Video_Data($this->id);
        if(is_object($infodat->video->chapters[0]))
        {
            $dataobj->swf = $infodat->video->chapters[0]->url;
            $dataobj->thumb = $infodat->video->chapters[0]->image;
        }
        else
        {
            $dataobj->swf = str_ireplace("mp4:", 'http://', $infodat->video->streams[0]->streamName);
        }
        $dataobj->time = "";
        $dataobj->source = '来自于cntv.cn';
        $dataobj->title = $infodat->title;
        return $dataobj;
    }
    private function getid($url)
    {
        $url = $this->getUrl($url);
        if(preg_match("/^http:\/\/(.*).cntv.cn/is", $url))
        {
            $htmldat = Util_Video_ApiConnect::get($url);
            if(preg_match_all("/<!--repaste.video.code.begin-->(.*)<!--repaste.video.code.end-->/siU", $htmldat, $out, 2))
            {
                $pid = $out[0][1];
            }
        }
        if(empty($pid))
        {
            throw new VideoApiException('没有数据');
        }
        $this->id = $pid;
        return $pid;
    }

}

?>