V1.class.php 2.26 KB
<?php
class Util_Video_Api_V1 extends Util_Video_Api
{
    private $tvxmlurl = 'http://www.v1.cn/gqxml/{id}.xml';
    private $xmlurl = 'http://www.v1.cn/xml/video/{id}.xml';
    /**
     * @param unknown_type $url
     */
    public function getData($url)
    {
        $id = $this->getid($url);
        if(preg_match('/^http:\/\/tv.v1.cn/is', $url))
        {
            $id = str_replace(',', '/', $id);
            $infourl = str_ireplace('{id}', $id, $this->tvxmlurl);
        }
        else
        {
            $infourl = str_ireplace('{id}', $id, $this->xmlurl);
        }
        $this->id = $id;
        $infodat = Util_Video_ApiConnect::get($infourl);
        if(!function_exists("simplexml_load_file"))
        {
            throw new Util_Video_ApiException('simplexml_load_file 不存在');
        }
        $infodat = str_replace("<![CDATA[", '', $infodat);
        $infodat = str_replace("]]>", '', $infodat);
        $infodat = @simplexml_load_string($infodat);
        if($infodat == null)
        {
            throw new Util_Video_ApiException('数据解析失败');
        }
        $dataobj = new Util_Video_Data($this->id);
        if(is_object($infodat->items->item))
        {
            $dataobj->swf = (string) $infodat->items->item->flv;
            $dataobj->thumb = (string) $infodat->items->item->image;
            $dataobj->time = (string) $infodat->items->item->publishdate;
            $dataobj->title = (string) $infodat->items->item->title;
        }
        else
        {
            $dataobj->swf = (string) $infodat->videoInfo->url;
            $dataobj->thumb = (string) $infodat->videoInfo->image;
            $dataobj->time = "";
            $dataobj->title = (string) $infodat->videoInfo->title;
        }
        $dataobj->source = '来自于v1.cn';
        return $dataobj;
    }
    
    private function getid($url)
    {
        $url = $this->getUrl($url);
        if(preg_match("@^http:\/\/.*.v1.cn@is", $url))
        {
            $htmldat = Util_Video_ApiConnect::get($url);
            if(preg_match_all('/{id:\"(.*)\"}/isU', $htmldat, $out, 2))
            {
                $id = $out[0][1];
            }
            return $id;
        }
        else
        {
            throw new VideoApiException('url地址不正确');
        }
    }

}

?>