Smgbb.class.php 3.68 KB
<?php
class Util_Video_Api_Smgbb extends Util_Video_Api
{
    private $wulinxmlurl = 'http://www.kankanews.com/dataservice/InitPlayer.php';
    private $wulinswfurl = 'http://www.kankanews.com/object/kankanewsplayer3.0.swf?autoPlay=true&width=600&height=490&streamType=recorded&
    cid={CategoryId}&vid={ContentId}&server=http://www.kankanews.com/dataservice/';
    private $infoswfurl = 'http://www.smgbb.cn/playxml/nplayer.swf?pid={id}';
    private $infoxmlurl = 'http://www1.smgbb.cn/playxml/statdir/{id_2}/playlist{id}.xml';
    public function getData($url)
    {
        $id = $this->getid($url);
        if(is_array($id))
        {
            $params = 'parameter=' . json_encode($id) . '&method=InitPlayer';
            $infodat = Util_Video_ApiConnect::get($this->wulinxmlurl, array(CURLOPT_POSTFIELDS => $params));
            $infodat = str_replace("<div id=\"main\">\"", '', $infodat);
            $infodat = str_replace("\"</div>", '', $infodat);
            $infodat = str_replace("\\/", '/', $infodat);
            $infodat = '<?xml version="1.0" encoding="utf-8"?>' . $infodat;
            $infodat = @simplexml_load_string($infodat);
            if($infodat == null)
            {
                throw new Util_Video_ApiException('simplexml_load_file 不存在');
            }
            $dataobj = new Util_Video_Data($this->id);
            $swfurl = str_ireplace("{CategoryId}", $id['CategoryId'], $this->wulinswfurl);
            $dataobj->swf = str_ireplace("{ContentId}", $id['ContentId'], $swfurl);
            $dataobj->thumb = (string) $infodat->currentvod->imgurl;
            $dataobj->time = "";
            $title = preg_replace("#\\\u([0-9a-f]{4})#ie", "iconv('UCS-2', 'UTF-8//IGNORE', pack('H4', '\\1'))", (string) $infodat->currentvod->name);
            $dataobj->title = $title;
        }
        else
        {
            $infurl = str_ireplace("{id}", $id, $this->infoxmlurl);
            $infurl = str_ireplace("{id_2}", intval(substr($id, strlen($id) - 2, 2)), $infurl);
            $infodat = Util_Video_ApiConnect::get($infurl);
            $infodat = @simplexml_load_string($infodat);
            if($infodat == null)
            {
                throw new Util_Video_ApiException('数据解析失败');
            }
            $dataobj = new Util_Video_Data($this->id);
            $dataobj->swf = str_ireplace("{id}", $id, $this->infoswfurl);
            $dataobj->thumb = (string) $infodat->playing['image'];
            $dataobj->time = "";
            $dataobj->title = (string) $infodat->playing['title'];
        }
        $dataobj->source = '来自于smgbb.cn';
        return $dataobj;
    }
    
    private function getid($url)
    {
        $url = $this->getUrl($url);
        if(preg_match("@^http:\/\/.*.smgbb.cn@is", $url))
        {
            if(preg_match("@^http:\/\/info.smgbb.cn@is", $url))
            {
                $id = str_replace(strrchr($url, '.'), '', substr(strrchr($url, '/'), 1));
                $this->id = $id;
                return $id;
            }
            else
            {
                $htmldat = Util_Video_ApiConnect::get($url);
                if(preg_match_all("/&cid=(.*)&/isU", $htmldat, $out, 2))
                {
                    $CategoryId = $out[0][1];
                }
                if(preg_match_all("/&vid=(.*)&/isU", $htmldat, $out, 2))
                {
                    $ContentId = $out[0][1];
                }
                $this->id = $CategoryId;
                return array(
                    'CategoryId' => $CategoryId, 
                    'ContentId' => $ContentId
                );
            }
        }
        else
        {
            throw new Util_Video_ApiException('数据解析失败');
        }
    
    }
}

?>