Xiyou.class.php 1.31 KB
<?php
/**
 * 请求:
 * http://xiyou.cntv.cn/v-3e971408-b35f-11e0-b140-a4badb469111.html
 */
class Util_Video_Api_Xiyou extends Util_Video_Api
{
    private $jsonurl = 'http://xiyou.cntv.cn/interface/index?videoId={id}';
    public function getData($url)
    {
        $id = str_replace('v-', '', $this->getid($url));
        $infourl = str_ireplace("{id}", $id, $this->jsonurl);
        $infodat = Util_Video_ApiConnect::get($infourl);
        $infodat = json_decode($infodat);
        if($infodat->status != 'success')
        {
            throw new Util_Video_ApiException('数据解析失败');
        }
        $dataobj = new Util_Video_Data($this->id);
        $flv = $infodat->data[0]->videoList[0]->videoFilePath;
        $dataobj->swf = str_replace(strrchr($flv, '#'), '.flv', $flv);
        $dataobj->thumb = $infodat->data[0]->imagePath;
        $dataobj->time = $infodat->data[0]->uploadTime;
        $dataobj->title = (string) $infodat->data[0]->title;
        $dataobj->source = '来自于cntv.cn';
        return $dataobj;
    }
    private function getid($url)
    {
        $url = $this->getUrl($url);
        if(!preg_match("/^http:\/\/.*/si", $url))
        {
            $id = $url;
        }
        $id = str_replace('.html', '', substr(strrchr($url, '/'), 1));
        $this->id = $id;
        return $id;
    }
}

?>