Cnlive.class.php 1.64 KB
<?php
/**
 * 
 * 请求:http://www.cnlive.com/programs/12980
 * 
 **/
class Uitl_Video_Api_Cnlive extends Util_Video_Api
{
    private $xmlurl = 'http://new.cnlive.com/play/getVideoCommend.action?mediasId={id}';
    /**
     * @param unknown_type unknown_type $url
     */
    public function getData($url)
    {
        $id = $this->getid($url);
        $infourl = str_ireplace("{id}", $id, $this->xmlurl);
        $infodat = Util_Video_ApiConnect::get($infourl);
        if(!function_exists("simplexml_load_file"))
        {
            throw new Util_Video_ApiException('simplexml_load_file 不存在');
        }
        $infodat = @simplexml_load_string($infodat);
        if($infodat == null)
        {
            throw new Util_Video_ApiException('数据解析失败');
        }
        foreach($infodat->home->image as $image)
        {
            if($image['vd'] == $this->id)
            {
                $dataobj = new Util_Video_Data($this->id);
                $dataobj->swf = "http://www.cnlive.com/images/web/AS3Player.swf?videoURL=" . (string) $image['url'] . "&VD=12980&status=0&coin=0";
                $dataobj->thumb = (string) $image['mes'];
                $dataobj->time = '';
                $dataobj->source = '来自于cnlive.com';
                $dataobj->title = (string) $image['txt'];
                return $dataobj;
            }
        }
        return '';
    }
    
    private function getid($url)
    {
        $url = $this->getUrl($url);
        if(!preg_match("/^http:\/\/.*/si", $url))
        {
            $id = $url;
        }
        $id = substr(strrchr($url, '/'), 1);
        $this->id = $id;
        return $id;
    }

}

?>