M1905.class.php 1.84 KB
<?php
class Util_Video_Api_M1905 extends Util_Video_Api
{
    private $xmlurl = 'http://www.m1905.com/api/video/api_vodplay-p-id-{id}.html';
    private $mp4url = 'http://www.m1905.com/pubfunc/playerV4-p-contentid-{id}.html';
    public function getData($url)
    {
        $id = $this->getid($url);
        $infourl = str_ireplace("{id}", $id, $this->xmlurl);
        $infodat = Util_Video_ApiConnect::get($infourl);
        if(!function_exists("simplexml_load_file"))
        {
            return '';
        }
        $infodat = @simplexml_load_string($infodat);
        if($infodat == null)
        {
            throw new Util_Video_ApiException('数据解析失败');
        }
        if(!empty($infodat->playlist))
        {
            $mp4url = str_ireplace("{id}", $id, $this->mp4url);
            $mp4dat = Util_Video_ApiConnect::get($mp4url);
            if(preg_match_all('/var html5_src = \"(.*)";/isU', $mp4dat, $out, 2))
            {
                $mp4 = $out[0][1];
            }
            if(empty($mp4))
            {
                throw new Util_Video_ApiException('没有数据');
            }
            $dataobj = new Util_Video_Data($this->id);
            $dataobj->swf = $mp4; //(string)$infodat->playlist->item['url'];
            $dataobj->thumb = (string) $infodat->playlist['img'];
            $dataobj->time = "";
            $dataobj->title = (string) $infodat->playlist['title'];
            return $dataobj;
        }
        else
        {
            throw new Util_Video_ApiException('没有数据');
        }
    
    }
    private function getid($url)
    {
        $url = $this->getUrl($url);
        if(!preg_match("/^http:\/\/.*/si", $url))
        {
            $id = $url;
        }
        $id = str_replace(strrchr($url, '.'), '', substr(strrchr($url, '/'), 1));
        
        $this->id = $id;
        return $id;
    }
}

?>