163.class.php 1.98 KB
<?php
class Util_Video_Api_163 extends Util_Video_Api
{
    private $htmlurl = "http://v.163.com/video/{id}.html";
    private $xmlurl = "http://so.v.163.com/flashinfo/vinfo/{sid}.xml";
    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("/var sid=\"(.*)\"/siU", $htmldat, $out, 2))
        {
            $sid = $out[0][1];
        }
        $infourl = str_ireplace("{sid}", $sid, $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('数据解析失败');
        }
        foreach($infodat->videos->video as $video)
        {
            if($video->vid == $this->id)
            {
                $dataobj = new Util_Video_Data($this->id);
                $swfpath = str_replace("http://", '~', $video->imgpath) . '~.swf';
                $dataobj->swf = 'http://img1.cache.netease.com/flvplayer081128/~false~0085_' . $this->id . $swfpath;
                $dataobj->thumb = $video->imgpath . '.jpg';
                $dataobj->time = (string) $video->distime;
                $dataobj->title = (string) $video->title;
                $dataobj->source = '来自于163.com';
                return $dataobj;
                break;
            }
        }
        return '';
    }
    private function getid($url)
    {
        $url = $this->getUrl($url);
        if(!preg_match("/^http:\/\/.*/si", $url))
        {
            $id = $url;
        }
        $url = str_replace('http://v.163.com/video/', '', $url);
        $id = str_replace(strrchr($url, '.'), '', $url);
        $this->id = substr(strrchr($id, '/'), 1);
        return $id;
    }
}

?>