Btjson博客 Btjson博客

乐视解析源码(参考)

in 技术文章 read (504) 文章转载请注明来源!

只提供参考,自行测试更多资源交流群516722628

<?php
$id = Le::parse($url);
$video_info = Le::parseVideoUrl($id);
echo json_encode($video_info);
/**
* 
*/
class Le
{
    public static function parse($url)
    {
        preg_match('#vplay/(.*?).htm#',$url,$ids);
        if ($ids[1]) {
            $name = "LE-".md5($ids[1]);
        }else{
            $name = "LE-".md5($url);
        }

        if (file_exists(NAME_PATH.$name)) {
            $data = json_decode(file_get_contents(NAME_PATH.$name),true);
            $pay = $data['pay'];
            $vid = $data['vid'];
            $title = $data['title'];
            $poster = $data['poster'];
        }else{
            $content = self::curl($url);
            preg_match('#vid: (.*?),#',$content,$vids);
            preg_match('#title:"(.*?)",#',$content,$titles);
            preg_match('#videoPic:"(.*?)",#',$content,$pics);
            preg_match('#isPay: (.*?),#',$content,$isPay);
            $vid = $vids[1];
            $title = $titles[1];
            $poster = !empty($pics[1]) ? str_replace('320_200','640_320',$pics[1]) : '';
            $pay = $isPay[1];//是否付费
            file_put_contents(NAME_PATH.$name, json_encode(array("vid"=>$vid,"pay"=>$pay,"title"=>$title,"poster"=>$poster)));
        }
        return $vid;
    }
    public static function parseVideoUrl($vid){
        $time = number_format(microtime(true),3,'.',''); 
        $tkey = self::getMmsKey($time);
        $tss = GlobalBase::is_ipad() ? "no" : "ios";
        $splatid = GlobalBase::is_ipad() ? 107 : 105;
        $domain = GlobalBase::is_ipad() ? 'm.le.com' : 'www.le.com';
        $source = GlobalBase::is_ipad() ? '1001' : '1000';
        //$url = "http://player-pc.le.com/mms/out/video/playJson?id={$vid}&format=1&tkey={$tkey}&domain=www.le.com&dvtype=1000&region=cn&accessyx=1&platid=3&splatid=304&source=1000&tss=no";
        $url = "http://player-pc.le.com/mms/out/video/playJson?id={$vid}&platid=1&splatid={$splatid}&format=1&tkey={$tkey}&domain={$domain}&dvtype=720p&devid=70A6E0A1FB93DA437B79DA594B3C9D03B428043B&region=cn&source={$source}&accessyx=1&tss={$tss}";//&tss=tvts

        $data = self::curl($url);
        //print_r($data);exit;
        $content = json_decode($data,true);
        $playurl = $content["msgs"]["playurl"];
        $point = $content["msgs"]["point"];
        $hot = $point["hot"];
        $seek = $point["skip"][0];

        $pic = $playurl["picAll"]["640*320"];
        $domains = array("http://play.g3proxy.lecloud.com","http://bplay.g3proxy.lecloud.com","http://g3.letv.com");
        $domain = $domains[0];//$domains[mt_rand(0,count($domains)-1)];
        $dispatch = $playurl["dispatch"];
        $duration = $playurl["duration"];
        foreach ($dispatch as $key => $value) {
            switch ($key) {
                case '350':$def = "流畅";break;
                case '1000':$def = "超清";break;
                case '1300':$def = "原画";break;
                case '720p':$def = "720P";break;
                case '1080p':$def = "1080P";break;
            }
            $vurl = $domain.$value[0];//self::getVideoUrl($domain.$value[0]."&format=1&expect=3&sign=letv"); //&format=1为json &format=1为xml  preg_replace("#/vod/v2/#","/

            if (GlobalBase::is_ipad()) {
                if($key =="1000"){
                    $videoinfo['code'] = 200;
                    //$videoinfo['type'] = 'le';
                    //$videoinfo['play'] = 'h5mp4';
                    $videoinfo["data"]["url"] = $vurl;
                    return $videoinfo;exit;
                }
            }else{
                if ($key == '1300' && $vurl != '') {
                    $fdata[0]['url'] = $vurl;
                    $fdata[0]['def'] = '原画';
                } 
                if ($key == '1080p' && $vurl != '') {
                    $fdata[1]['url'] = $vurl;
                    $fdata[1]['def'] = '1080P';
                }
                if ($key == '1000' && $vurl != '') {
                    $fdata[2]['url'] = $vurl;
                    $fdata[2]['def'] = '超清';
                }
                if ($key == '720p' && $vurl != '') {
                    $fdata[3]['url'] = $vurl;
                    $fdata[3]['def'] = '720P';
                }
                if ($key == '350' && $vurl != '') {
                    $fdata[4]['url'] = $vurl;
                    $fdata[4]['def'] = '流畅';
                }
            }
        }
        for ($i=0; $i <= 10 ; $i++) { 
            if ($fdata[$i] == '') {continue;}
            $key_arrays[]=$fdata[$i];
        }
        $videoinfo['code'] = 200;
        $videoinfo['poster'] = $img;
        $videoinfo['name'] = $video_info["coreVideoInfo"]["videoName"];
        $videoinfo['play'] = '';
        $videoinfo["data"]["video"]["file"] = $key_arrays[0]['url'];
        $videoinfo["data"]["video"]["type"] = "video/m3u8";
        return $videoinfo;
    }
    public static function curl($url,$cookie="")
    {
        $params["ua"] = "Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/63.0.3239.84 Safari/537.36";
        $params["cookie"] = $cookie;
        return GlobalBase::curl($url,$params);
    }
    //==================================================以下代码不需要修改==========================================================
    /**
     * [getVideoUrl 获取视频最终地址]
     * @param  [type] $url [description]
     * @return [type]      [description]
     */
    private static function getVideoUrl($url){
        $data = GlobalBase::curl($url);
        $content = json_decode($data,true);
        $location = $content["location"];
        $nodelist = $content["nodelist"];
        $vurl = $nodelist[mt_rand(0,count($nodelist)-1)]["location"];
        return $location;
    }
    //========================================= 方式二 =================================================
    /**
     * [getMmsKey 获取tkey]
     * @param  [type] $e [时间]
     * @return [type]    [description]
     */
    private static function getMmsKey($e)
    {
        $t = 185025305;
        $r = 8;
        $n = $e;
        $n = self::rotateRight($n, $r);
        $o = self::s2v("O",$n, $t);
        return $o;
    }
    private static function rotateRight($e, $t)
    {
        for ($r, $n = 0; self::s2v("g",$t, $n); $n++){
            $r = self::s2v("o",1,$e);
            $e >>= 1;
            $r <<= 31;
            $e += $r;
        }
        return $e;
    }
    private static function s2v($k,$y,$r){
        switch ($k) {
            case 'D':return $y | $r;break;
            case 'd':return $y % $r;break;
            case 'O':return $y ^ $r;break;
            case 'k':return $y < $r;break;
            case 'J':return $y >> $r;break;
            case 'R':return $y === $r;break;
            case 'g':return $y > $r;break;
            case 'o':return $y & $r;break;
            case 'l':return $y !== $r;break;
            case 'L':return $y != $r;break;
            case 'a':return $y - $r;break;
            case 'u':return $y == $r;break;
            case 'e':return $y << $r;break;
        }
    }
}
?>
jrotty WeChat Pay

微信打赏

jrotty Alipay

支付宝打赏

文章二维码

扫描二维码,在手机上阅读!

本文基于《署名-非商业性使用-相同方式共享 4.0 国际 (CC BY-NC-SA 4.0)》许可协议授权
文章链接:https://www.pohaier.com/2018/12/04/133.html (转载时请注明本文出处及文章链接)

技术文章
发表新评论
博客已萌萌哒运行
© 2019 由 Typecho 强力驱动.Theme by btjson
PREVIOUS NEXT
雷姆
拉姆