Rbc.class.php 1.57 KB
<?php
class Util_Video_Api_Rbc extends Util_Video_Api
{
    private $htmlurl = 'http://v.rbc.cn/play--s-/play_id_{id}.html';
    private $xmlurl = 'http://v.rbc.cn/ad/xmlInfo?id={id}';
    /**
     * @param unknown_type $url
     */
    public function getData($url)
    {
        $id = $this->getid($url);
        $htmlurl = str_ireplace("{id}", $id, $this->htmlurl);
        $htmldat = Util_Video_ApiConnect::get($htmlurl);
        if(preg_match_all("@<em class=\"f03\">(.*)<\/em>@siU", $htmldat, $out, 2))
        {
            $title = $out[0][1];
        }
        $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('数据解析失败');
        }
        $dataobj = new Util_Video_Data($this->id);
        $dataobj->swf = (string) $infodat->file;
        $dataobj->thumb = (string) $infodat->thumb;
        $dataobj->time = "";
        $dataobj->source = '来自于rbc.cn';
        $dataobj->title = $title;
        return $dataobj;
    }
    private function getid($url)
    {
        $url = $this->getUrl($url);
        if(!preg_match("/^http:\/\/.*/si", $url))
        {
            $id = $url;
        }
        $id = str_replace(strrchr($url, '.'), '', substr(strrchr($url, '_'), 1));
        $this->id = $id;
        return $id;
    }

}

?>