Xunlei.class.php 2.24 KB
<?php
class Util_Video_Api_Xunlei extends Util_Video_Api
{
    private $swfurl = 'http://video.xunlei.com/dt/swf/v.swf?fullscreenbtn=1&id={id}&channel=newauto&url={flvurl}&width=440&height=357';
    private $imgurl = 'http://images.video.xunlei.com/section/{imgID}.jpg';
    public function getData($url)
    {
        $id = $this->getid($url);
        $infodat = Util_Video_ApiConnect::get($url);
        if(preg_match_all("/var G_PLAY_URL='(.*)';/isU", $infodat, $out, 2))
        {
            $flvurl = $out[0][1];
        }
        if(empty($flvurl))
        {
            throw new Util_Video_ApiException("没有flvurl");
        }
        if(preg_match_all("/var G_TITLE='(.*)';/isU", $infodat, $out, 2))
        {
            $title = $out[0][1];
        
        }
        if(empty($title))
        {
            throw new Util_Video_ApiException("没有标题");
        }
        $imgID = str_replace('_1.flv', '', substr(strrchr($flvurl, '/'), 1));
        $imgIDPath = substr($imgID, 0, 2) . '/' . substr($imgID, strlen($imgID) - 2, 2) . '/' . $imgID;
        $imgpath = str_ireplace('{imgID}', $imgIDPath . '_0', $this->imgurl);
        $dataobj = new Util_Video_Data($this->id);
        $imgdat = Util_Video_ApiConnect::get($imgpath);
        if(strlen($imgdat) > 500)
        {
            $dataobj->thumb = $imgpath;
        }
        else
        {
            $imgpath = str_ireplace('{imgID}', $imgIDPath . '_30', $this->imgurl);
            $imgdat = Util_Video_ApiConnect::get($imgpath);
            if(strlen($imgdat) > 500)
            {
                $dataobj->thumb = $imgpath;
            }
            else
            {
                $dataobj->thumb = '';
            }
        }
        $dataobj->time = '';
        $dataobj->title = $title;
        $swfpath = str_ireplace("{id}", $this->id, $this->swfurl);
        $dataobj->swf = str_ireplace("{flvurl}", $flvurl, $swfpath);
        $dataobj->source = '来自于xunlei.com';
        return $dataobj;
    }
    private function getid($url)
    {
        $url = $this->getUrl($url);
        if(!preg_match("/^http:\/\/.*/si", $url))
        {
            $id = $url;
        }
        $this->id = $id = str_replace(strrchr($url, '.'), '', substr(strrchr($url, '/'), 1));
        return $id;
    }

}


?>