Sohu.class.php 2.88 KB
<?php
class Util_Video_Api_Sohu extends Util_Video_Api
{
    private $htmlurl = 'http://tv.sohu.com/{num}.shtml';
    private $jsonurl = 'http://hot.vrs.sohu.com/vrs_flash.action?vid={id}';
    private $mytvjsonurl = 'http://my.tv.sohu.com/videinfo.jhtml?m=viewtv&vid={id}';
    private $swfurl = 'http://share.vrs.sohu.com/{picid}/v.swf';
    public function getData($url)
    {
        $id = $this->getid($url);
        
        if($id['mytv'])
        {
            $infourl = str_ireplace("{id}", $id['id'], $this->mytvjsonurl);
        }
        else
        {
            $infourl = str_ireplace("{id}", $id['id'], $this->jsonurl);
        }
        $infodat = Util_Video_ApiConnect::get($infourl);
        $infodat = json_decode($infodat);
        $dataobj = new Util_Video_Data($this->id);
        /*$keyurl = 'http://'.$infodat->allot.'?prot='.$infodat->prot.'&file=';
        $keyurl = str_replace('http://data.vod.itc.cn', $keyurl,$infodat->data->clipsURL[0]);
        $keyurl .='&new='.(string)$infodat->data->su[0].'&t='.(1/rand(1,100000));
        $keydat = VideoApiConnect::get($keyurl);*/
        //$keydat = explode('|',$keydat);
        //$swfurl = $keydat[0].substr((string)$infodat->data->su[0],1).'?key='.$keydat[count($keydat)-2];
        //$dataobj->type = 'mp4';
        if(!empty($infodat))
        {
            $dataobj->thumb = $infodat->data->coverImg;
            $picID = explode('_', $dataobj->thumb);
            if(empty($picID[2]))
            {
            	$dataobj->swf = str_ireplace("{picid}", $id['id'], $this->swfurl);
            }
            else
            {
            	$dataobj->swf = str_ireplace("{picid}", $picID[2], $this->swfurl);
            }
            
            $dataobj->thumb = $infodat->data->coverImg;
            $dataobj->time = "";
            $dataobj->source = 'sohu.com';
            $dataobj->title = $infodat->data->tvName;
            
            return $dataobj;
        }
        else
        {
            throw new Util_Video_ApiException('没有数据');
        }
    }
    
    private function getid($url)
    {
        $url = $this->getUrl($url);
        if(preg_match("/^http:\/\/my.tv.sohu.com/is", $url))
        {
            $id = substr(strrchr($url, '/'), 1);
            $this->id = $id;
            return array(
                        'mytv' => 1, 
                        'id' => $id
                        );
        }
        $url = str_replace("http://tv.sohu.com/", '', $url);
        $num = str_replace(strchr($url, '.'), '', $url);
        $url = str_ireplace("{num}", $num, $this->htmlurl);
        $htmldat = Util_Video_ApiConnect::get($url, array(
            CURLOPT_ENCODING => "gzip"
        ));
        if(preg_match_all("/var vid=\"(.*)\"/siU", $htmldat, $out, 2))
        {
            $id = $out[0][1];
        }
        $this->id = $id;
        return array(
            'mytv' => 0, 
            'id' => $id
        );
    
    }

}

?>