6.class.php 1.84 KB
<?php
class Util_Video_Api_6 extends Util_Video_Api
{
    private $htmlurl = ' http://6.cn/watch/{id}.html';
    private $xmlurl = 'http://6.cn/v72.php?vid={vid}';
    protected function get_domain()
    {
        return array(
                        "6.cn"
                     );
    }
    public function getData($url)
    {
        $idandswf = $this->getid($url);
        $infourl = str_ireplace("{vid}", $idandswf['vid'], $this->xmlurl);
        $infodat = Util_Video_ApiConnect::get($infourl, array(CURLOPT_ENCODING => "gzip"));
        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 = $idandswf['swf'];
        $dataobj->thumb = (string) $infodat->VIDEO->pic;
        $dataobj->time = "";
        $dataobj->title = (string) $infodat->VIDEO->title;
        $dataobj->user = '';
        return $dataobj;
    }
    private function getid($url)
    {
        $url = $this->getUrl($url);
        if(!preg_match("/^http:\/\/.*/si", $url))
        {
            $url = str_ireplace("{id}", $url, $this->htmlurl);
        }
        $htmldat = Util_Video_ApiConnect::get($url);
        if(preg_match_all("/embed\s*src=&quot;(.*)&quot;/siU", $htmldat, $out, 2))
        {
            $swf = $out[0][1];
            $vid = preg_replace("/\..*$/", "", preg_replace("/^.*cn\/p\//si", "", $swf));
        }
        else
        {
            throw new Util_Video_ApiException('数据解析失败');
        }
        $this->id = $url;
        return array(
            "swf" => $swf, 
            "vid" => $vid
        );
    }
}        
?>