56.class.php 1.57 KB
<?php
/**
 * 请求:http://6.cn/watch/13685903.html
 *
 */
class Util_Video_Api_56 extends Util_Video_Api
{
    private $jsonurl = 'http://vxml.56.com/json/{id}/?src=out';
    private $htmlurl = 'http://www.56.com/u74/v_{id}.html';
    private $swfurl = 'http://player.56.com/v_{id}.swf';
    
    /**
     * @param unknown_type $url
     * @return VideoApi_Data
     */
    public function getData($url)
    {
        $idandswf = $this->getid($url);
        $jsonurl = str_ireplace("{id}", $this->id, $this->jsonurl);
        $dat = Util_Video_ApiConnect::get($jsonurl);
        $jsonobj = json_decode($dat);
        if(!$jsonobj->status)
        {
            throw new Util_Video_ApiException('56.cn返回失败');
        }
        $dataobj = new Util_Video_Data($this->id);
        $dataobj->swf = $idandswf['swf'];
        $dataobj->thumb = $jsonobj->info->img;
        $dataobj->time = $jsonobj->info->duration;
        $dataobj->title = $jsonobj->info->Subject;
        $dataobj->user = $jsonobj->info->user_id;
        $dataobj->source = '来自于56.com';
        return $dataobj;
    }
    private function getid($url)
    {
        $url = $this->getUrl($url);
        if(preg_match("/^http:\/\/.*/si", $url))
        {
            $id = preg_replace("/\..*$/si", "", preg_replace("/^.*\/v_/si", "", $url));
        }
        if(empty($id))
        {
            exit();
        }
        $swf = str_ireplace("{id}", $id, $this->swfurl);
        $this->id = $id;
        return array(
                        "swf" => $swf, 
                        "id" => $id
                    );
    }

}

?>