Letv.class.php 1.78 KB
<?php
class Util_Video_Api_Letv extends Util_Video_Api
{
    private $htmlurl = 'http://www.letv.com/ptv/{link}.html';
    private $jsonurl = 'http://app.letv.com/ajax/getFocusVideo.php?pid={pid}&p=2&top=0&max=1';
    private $swfurl = 'http://img1.c0.letv.com/ptv/player/swfPlayer.swf?id={vid}&host=app.letv.com&vstatus=4&AP=1&logoMask=0&isShowP2p=0&autoplay=true';
    public function getData($url)
    {
        $id = $this->getid($url);
        $infourl = str_ireplace("{pid}", $id['pid'], $this->jsonurl);
        $infodat = Util_Video_ApiConnect::get($infourl);
        $infodat = str_replace("([", '', $infodat);
        $infodat = str_replace("])", '', $infodat);
        $infodat = json_decode($infodat);
        if($infodat == null)
        {
            throw new Util_Video_ApiException('数据解析失败');
        }
        $dataobj = new Util_Video_Data($id['pid']);
        $dataobj->swf = str_ireplace("{vid}", $id['vid'], $this->swfurl);
        ;
        $dataobj->thumb = $infodat->pic;
        $dataobj->time = "";
        $dataobj->title = $infodat->title;
        $dataobj->source = '来自于letv.com';
        return $dataobj;
    
    }
    private function getid($url)
    {
        $url = $this->getUrl($url);
        $link = str_replace("http://www.letv.com/ptv/", "", $url);
        $link = str_replace(strrchr($url, '.'), '', $link);
        $htmlurl = str_ireplace("{link}", $link, $this->htmlurl);
        $htmldat = Util_Video_ApiConnect::get($htmlurl);
        if(preg_match_all("/vid:(.*),/siU", $htmldat, $out, 2))
        {
            $vid = $out[0][1];
        }
        if(preg_match_all("/pid:(.*),/siU", $htmldat, $out, 2))
        {
            $pid = $out[0][1];
        }
        return array(
            'vid' => $vid, 
            'pid' => $pid
        );
    }

}

?>