芒果解析源码

作者 : King 本文共12个字,预计阅读时间需要1分钟 发布时间: 2024-10-4 共14人阅读

芒果解析源码

芒果解析源码

  1. $ids = Mgtv::parse($url);  
  2. $data = Mgtv::get_PC_B_video($ids);  
  3. echo json_encode($data);  
  4.   
  5. /** 
  6.  
  7. */  
  8. class Mgtv  
  9. {  
  10.     //============================================================================================================================  
  11.     /** 
  12.      * [parse 解析获取视频 ID 和视频专辑 ID] 
  13.      * @param  [type] $url [播放网址] 
  14.      * @return [type]      [description] 
  15.      */  
  16.     public static function parse($url)  
  17.     {  
  18.         $name = “MGTV-“.md5($url);  
  19.   
  20.         if (file_exists(NAME_PATH.$name) && time() – filemtime(NAME_PATH.$name) < 604800) { //文件存在并且知识兔文件创建时间小于7天  
  21.             $data = json_decode(file_get_contents(NAME_PATH.$name),true);  
  22.             $cid = $data['cid’];  
  23.             $vid = $data['vid’];  
  24.             $isIntact = $data['isIntact’];  
  25.         }else{  
  26.             $html = self::curl($url);  
  27.             preg_match('#cid: ([\d]+),#iU’,$html,$cids);  
  28.             preg_match('#vid: ([\d]+),#iU’,$html,$vids);  
  29.             preg_match('#isIntact: ([\d]+),#iU’,$html,$isIntacts);  
  30.             file_put_contents(NAME_PATH.$name, json_encode(array(“cid”=>$cids[1],“vid”=>$vids[1],“isIntact”=>$isIntacts[1])));  
  31.             $cid = $cids[1];  
  32.             $vid = $vids[1];  
  33.             $isIntact = $isIntacts[1];  
  34.   
  35.         }  
  36.   
  37.         return array(“cid”=>$cid,“vid”=>$vid,“url”=>$url,“isIntact”=>$isIntact);  
  38.     }  
  39.   
  40.     /** 
  41.      * [get_video_files 获取视频信息] 
  42.      * @param  [type]  $vid [视频ID] 
  43.      * @param  integer $def [视频清晰度] 
  44.      * @return [type]       [description] 
  45.      */  
  46.     public static function get_PC_B_video($ids//芒果浏览器pc端  
  47.     {  
  48.         $ref = $ids['url’];  
  49.         $ids['re’] = $ids['url’];  
  50.         $ids['ua’] = 'Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/67.0.3396.99 Safari/537.36’;  
  51.         $vid = $ids['vid’];  
  52.         $pno = “1000″;  
  53.         $wpno = “2010″;  
  54.         $ver =  “0.3.0001″;  
  55.         $suuid = self::createuuid(8) . “-“ . self::createuuid(4) . “-“ . self::createuuid(4) . “-“ . self::createuuid(12);  
  56.         $collection_id = “315515″;  
  57.         $_support = “10000000″;  
  58.         $files = [];  
  59.   
  60.         $did = self::createuuid(8) . “-“ . self::createuuid(4) . “-“ . self::createuuid(4) . “-“ . self::createuuid(’12’);  
  61.         $clit = time();  
  62.         $api = “https://pcweb.api.mgtv.com/player/video?video_id={$vid}&suuid={$suuid}&cid={$ids['cid’]}&tk2=”.self::getTK2(array(“did”  => “{$did}”,“ver”  => “{$ver}”,“pno”  => “{$pno}”,“clit” => time())).“&_support={$_support}”;  
  63.         if (isset($_COOKIE['PM_CHKID’])) {  
  64.             $ids['cookie’] = COOKIE_MGTV.“PM_CHKID=”.$_COOKIE['PM_CHKID’].“;”;  
  65.         }   
  66.         $content = self::curl($api,$ids); /* COOKIE_MGTV */  
  67.         //print_r($content);exit;  
  68.         $json = json_decode($content,true);  
  69.         if ($json['code’] == 200 && isset($json['data’]['info’]) && $json['data’]['info’]['paymark’] == '0’) {  
  70.             if (!isset($_COOKIE['PM_CHKID’]) && is_file(COOKIE_PATH.’mgtv.txt’)) {  
  71.                 $cookie = file_get_contents(COOKIE_PATH.’mgtv.txt’);  
  72.                 $cc = explode(“PM_CHKID”,$cookie);  
  73.                 $c1 = “PM_CHKID=”.trim($cc['1’]).“;”;  
  74.                 setcookie(“PM_CHKID”,trim($cc['1’]));  
  75.                 $ids['cookie’] = COOKIE_MGTV.$c1;  
  76.             }  
  77.             $pm2 = $json['data’]['atc’]['pm2’];  
  78.             $g = “https://pstream.api.mgtv.com/player/getSource?tk2=” .self::getTK2(array(“did”  => “{$did}”,“ver”  => “{$ver}”,“pno”  => “{$pno}”,“clit” => time())) . “&pm2=” . $json['data’]['atc’]['pm2’] . “&video_id=” . $vid . “&_support={$_support}&did={$did}&suuid={suuid}&collection_id={$collection_id}”/* &type=pch5 */;  
  79.   
  80.             $g1 = self::curl($g,$ids);  
  81.   
  82.             $k1 = json_decode($g1,true);  
  83.   
  84.             if (isset($k1['data’])) {  
  85.                 $data = $k1['data’];  
  86.                 $info = $data['info’];//视频信息  
  87.                 $points = $json['data’]['points’];  
  88.                 $preview = $json['data’]['frame’];  
  89.   
  90.                 $domain = $data['stream_domain’];//视频域名数组  
  91.                 $stream = $data['stream’];  
  92.                 $count = 0;  
  93.                 if ($points['content’] != null || $points['content’] != ) {  
  94.                     $_a = explode('|’,$points['start’]);  
  95.                     $_b = explode('|’,$points['end']);  
  96.                     foreach ($points['content’] as $k => $v) {  
  97.                         $_a = explode('|’,$v);  
  98.                         $_tmp['words’] .= self::filterGBK_SpecialChars($_a[1]).’,’;  
  99.                         $_tmp['time’] .= (int)$_a[0].’,’;  
  100.                     }  
  101.                     $_tmp['words’] = substr($_tmp['words’],0,strlen($_tmp['words’])-1);  
  102.                     $_tmp['time’] = substr($_tmp['time’],0,strlen($_tmp['time’])-1);  
  103.                     //$videoinfo[“prompt”] = $_tmp;  
  104.                 }  
  105.   
  106.                 $videoinfo[“data”][“poster”] = $json['data’]['info’]['thumb’];  
  107.   
  108.                 foreach ($stream as $key => $value) {  
  109.                     $def = $value['def’];  
  110.                     if ($def==1) {  
  111.                         continue;  
  112.                     }  
  113.                     if ($domain[$key] == null) {  
  114.                         $domain[$key] = $domain[0];  
  115.                     }  
  116.                     //print_r($domain[$key].$value['url’]);exit;  
  117.                     if(!emptyempty($value['url’])){  
  118.                         $vurl = self::get_video_url($domain[$key].$value['url’],$ids);  
  119.                         if ($vurl == 'failed’) {  
  120.                             $vurl = self::get_video_url($domain[$key].$value['url’],$ids);  
  121.                             if ($vurl == 'failed’) {  
  122.                                 $vurl = self::get_video_url($domain[$key].$value['url’],$ids);  
  123.                                 if ($vurl == 'failed’) {  
  124.                                     $vurl = self::get_video_url($domain[$key].$value['url’],$ids);  
  125.                                     if ($vurl == 'failed’) {  
  126.                                         break;    
  127.                                     }  
  128.                                 }  
  129.                             }  
  130.   
  131.                         }  
  132.                         if (GlobalBase::is_ipad()) {  
  133.                             if($def==3 || $def == 2){  
  134.                                 $true_url = $vurl;  
  135.                                 $videoinfo['code’] = 200;  
  136.                                 $videoinfo['play’] = 'hls’;  
  137.                                 $videoinfo['type’] = 'mgtv’;  
  138.                                 $videoinfo[“data”][“url”] = str_replace(“http://”,“https://”,$true_url);  
  139.                                 exit(json_encode($videoinfo));  
  140.                             } else {  
  141.                                 $videoinfo['play’] = 'url’;  
  142.                                 $videoinfo[“url”] = '../yun/?url=’.urlencode($ref);  
  143.                                 exit(json_encode($videoinfo));  
  144.                             }  
  145.                         }else{  
  146.                             $video[0] = $vurl;  
  147.                             $video[1] = “video/m3u8″;  
  148.                             $video[2] = $value['name’];  
  149.                             $video[3] = $def == 3 ? 10: 0;  
  150.                             $videoinfo1[“video”][$count] = str_replace('http://’,’//’,$video);;  
  151.                             $count++;  
  152.                         }  
  153.                     }  
  154.                 }  
  155.                 //print_r(json_encode($videoinfo1));exit;  
  156.                 if (!emptyempty($videoinfo1[“video”]) && $videoinfo1[“video”][count($videoinfo1[“video”])-1][0] != 'busy’) {  
  157.                     $videoinfo['code’] = 200;  
  158.                     $videoinfo['msg’] = '解析成功’;  
  159.                     $mp4url = !emptyempty($videoinfo1[“video”][count($videoinfo1[“video”])-1][0]) ? $videoinfo1[“video”][count($videoinfo1[“video”])-1][0] : $videoinfo1[“video”][0][0];  
  160.                     $videoinfo['data’]['url’] = $mp4url;  
  161.                     if (emptyempty($mp4url)) {  
  162.                         $videoinfo['code’] = 404;  
  163.                         $videoinfo['msg’] = '获取视频地址失败’;  
  164.                     }  
  165.                     $videoinfo['play’] = 'hls’;  
  166.   
  167.                     $imp4url = $videoinfo1[“video”][0][0];  
  168.                 } else {  
  169.                     $videoinfo['code’] = 302;  
  170.                     $videoinfo['msg’] = $json['data’]['info’]['title’].’视频正在加载···请稍后···’;  
  171.                     $videoinfo[“play”] = 'url’;  
  172.                     $videoinfo[“url”] = '../yun/?url=’.urlencode($ref);  
  173.                 }  
  174.   
  175.                 $videoinfo[“data”][“name”] = $json['data’]['info’]['title’];  
  176.                 $videoinfo[“data”][“series”] = $json['data’]['info’]['series’];  
  177.                 $videoinfo[“data”][“desc”] = $json['data’]['info’]['desc’];  
  178.   
  179.                 return $videoinfo;  
  180.             }  
  181.         } else {  
  182.             if (isset($json['data’]['info’]) && $json['data’]['info’]['paymark’] == '1’) {  
  183.                 $_loc1['code’] = 302;  
  184.                 $_loc1['msg’] = '芒果VIP视频’;  
  185.                 $_loc1['url’] = isset($json['url’]) ? $json['url’] : '../yun/?url=’.urlencode($ref);  
  186.             } else if (isset($json['code’]) && $json['code’] == 40001) {  
  187.                 $_loc1['code’] = 302;  
  188.                 $_loc1['msg’] = isset($json['msg’]) ? $json['msg’] : '解析失败!’;  
  189.                 $_loc1['url’] = isset($json['url’]) ? $json['url’] : '../yun/?url=’.urlencode($ref);  
  190.             } else {  
  191.                 $_loc1 = array(  
  192.                     “code” => 302,  
  193.                     “msg” => '解析失败!’,  
  194.                     “url” => '../yun/?url=’.urlencode($ref)  
  195.                 );  
  196.             }  
  197.             return $_loc1;  
  198.         }  
  199.     }  
  200.   
  201.     /* 
  202.       *  
  203.      */  
  204.     public static function get_Phone_C_video($ids//芒果浏览器pc端  
  205.     {  
  206.         $ref = $ids['url’];  
  207.         $ids['re’] = $ids['url’];  
  208.         $ids['ua’] = 'okhttp/imgotv’;  
  209.         $ids['cookie’] = COOKIE_MGTV;  
  210.         $vid = $ids['vid’];  
  211.         $ver =  “0.2.24011″;  
  212.         $suuid = self::createuuid(8) . “-“ . self::createuuid(4) . “-“ . self::createuuid(4) . “-“ . self::createuuid(12);  
  213.         $_support = “10100001″;  
  214.   
  215.         $api = “https://mobile.api.mgtv.com/v8/video/getSource?_support=10100001&device=oppo%20R11&osVersion=4.4.2&appVersion=5.8.6_1&ticket=&userId=0&mac=i352419010176358&osType=android&channel=360dev&uuid=&endType=mgtvapp&androidid=b0359fa2c8301858&imei=352419010176358&macaddress=B2%3A35%3A9F%3AA2%3AC8%3A30&seqId=3cdb503a7f75ab0d54139bf4a92bf380&version=5.2&type=10&abroad=0&src=mgtv&uid=&phonetype=oppo%20R11&videoId={$vid}&isowner=0&clipId=323323&playType=1&dataType=1&keepPlay=0&source=40&localPlayVideoId=4458399&localVideoWatchTime=121&did=i352419010176358&suuid={$suuid}&hdts=h264%2Ch265″;  
  216.   
  217.         $content = self::curl($api,$ids); /* COOKIE_MGTV */  
  218.   
  219.         $json = json_decode($content,true);  
  220.         $_tmp = array();  
  221.   
  222.         if ($json['code’] == 200) {  
  223.             $domains = $json['data’]['videoDomains’];  
  224.             $data = $json['data’]['videoSources’];  
  225.             foreach ($data as $key => $value) {  
  226.                 $def = $value['definition’];  
  227.                 if ($value['url’] == ) {  
  228.                     continue;  
  229.                 }  
  230.   
  231.                 $url = $domains[1].$value['url’].“&ver={$ver}&chk=074a2db93003e523b945509df080ac00&_support={$_support}&did=i352419010176358&suuid={$suuid}”;  
  232.   
  233.                 //print_r($url);exit;  
  234.                 $url = self::get_video_url($url,$ids);  
  235.   
  236.                 if (GlobalBase::is_ipad()) {  
  237.                     if($def==3 || $def == 2 && $url != ){  
  238.                         $true_url = self::get_video_mp4_url($url);  
  239.                         $videoinfo[“video”][“file”] = $true_url;  
  240.                         $videoinfo[“video”][“type”] = “video/mp4″;  
  241.                         exit(json_encode($videoinfo));  
  242.                     } else {  
  243.                         $videoinfo['play’] = 'url’;  
  244.                         $videoinfo[“url”] = '../yun/?url=’.urlencode($ids['url’]);  
  245.                         exit(json_encode($videoinfo));  
  246.                     }  
  247.                 } else {  
  248.                     if ($def == 4 && $url!=) {  
  249.                         $_tmp[4]['def’] = '蓝光’;  
  250.                         $_tmp[4]['url’] = $url;  
  251.                     }  
  252.                     if ($def == 3 && $url!=) {  
  253.   
  254.                         $_tmp[3]['def’] = '超清’;  
  255.                         $_tmp[3]['url’] = $url;  
  256.                     }  
  257.                     if ($def == 2 && $url!=) {  
  258.                         $_tmp[2]['def’] = '高清’;  
  259.                         $_tmp[2]['url’] = $url;  
  260.                     }  
  261.                     if ($def == 1 && $url!=) {  
  262.                         $_tmp[1]['def’] = '标清’;  
  263.                         $_tmp[1]['url’] = self::get_video_mp4_url($url);  
  264.   
  265.                     }  
  266.   
  267.                 }  
  268.   
  269.             }  
  270.             //print(json_encode($_tmp[3]));exit;  
  271.             for ($i=1; $i <= 5 ; $i++) {   
  272.                 if ($_tmp[$i] == ) {  
  273.                     continue;  
  274.                 }  
  275.                 $key_arrays[]=$_tmp[$i];  
  276.             }  
  277.             $videoinfo[“video”][“file”] = $key_arrays[count($key_arrays)-1]['url’];  
  278.             $videoinfo[“video”][“type”] = “video/mp4″;  
  279.             $videoinfo['msg’] = '网站资源’;  
  280.   
  281.         }  
  282.         return $videoinfo;  
  283.   
  284.     }  
  285.   
  286.     /* 
  287.     public getMgtv($ids) 
  288.     { 
  289.         $api = “https://mobile.api.hunantv.com/v6/video/getSource?_support=10100001&device=N5207&src=mgtv&appVersion=5.7.0_1&osVersion=4.2.2&osType=android&version=5.2&type=10&ticket=&userId=0&channel=mgtv3&videoid={$ids['vid’]}”; 
  290.         $data = self::curl($api,$ids); 
  291.         print_r($data); 
  292.     } */  
  293.     /** 
  294.      * [get_video_url 获取视频最终地址] 
  295.      * @param  [type] $url [视频请求链接] 
  296.      * @return [type]      [description] 
  297.      */  
  298.     public static function get_video_url($url,$ids){  
  299.   
  300.         $content = self::curl($url,$ids);  
  301.         //print_r($content);exit;  
  302.         $data = json_decode($content,true);  
  303.         $vurl = $data[“info”];  
  304.         return $vurl;  
  305.     }  
  306.   
  307.     /** 
  308.      * [get_video_mp4_url 获取视频MP4视频] 
  309.      * @param [type] $url [视频请求连接] 
  310.      * @return [type] url [mp4最终地址]   
  311.      */  
  312.     public static function get_video_mp4_url($url){  
  313.         $u1 = explode('?’,$url);  
  314.         $u1 = explode('//’,$u1['0’]);  
  315.         $u1 = explode('/’,$u1['1’]);  
  316.         $f1 = explode('_’,$u1['5’]);  
  317.         $fid = $f1['0’];  
  318.         $file2 = “/”.$u1[1].“/”.$u1[2].“/”.$u1[3].“/”.$u1[4].“/”.$u1[5];  
  319.         if(strstr($file2,’_mp4′)){  
  320.             $filestr_replace('_mp4′,’.mp4′,$file2);  
  321.         }else{  
  322.             $file=$file;  
  323.         }  
  324.         $true_url = “https://disp.titan.mgtv.com/vod.do?fmt=4&pno=1042000&fid=$fid&file=$file”;  
  325.         return $true_url;  
  326.     }  
  327.   
  328.     public static function curl($url,$ids)  
  329.     {  
  330.         $params[“ua”] = !emptyempty($ids['ua’]) ? $ids['ua’] : “Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/63.0.3239.84 Safari/537.36″;  
  331.         $params[“cookie”] = $ids['cookie’];  
  332.         //$params[“proxy”] = PROXY;  
  333.         $params[“ip”] = “14.21.96.129″;//伪装为固定IP,否则会报异地登录,会封号,不要更改  
  334.         return GlobalBase::mgtv_curl($url,$params);  
  335.     }  
  336.   
  337.     /* 
  338.      * 生成0到1随机数 
  339.      */  
  340.     public static function random($min = 0, $max = 1){       
  341.         return $min + mt_rand()/mt_getrandmax()*($max$min);   
  342.     }  
  343.   
  344.     /* 
  345.     * did 生成 
  346.     *  
  347.      */  
  348.     public static function createuuid($b$a=null) {  
  349.         switch ($a) {  
  350.             case 'h’:  
  351.                 $a = “ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789″;  
  352.                 break;  
  353.             case 's’:  
  354.                 $a = “0123456789″;  
  355.                 break;  
  356.             case 'd’:  
  357.                 $a = “ABCDEFGHIJKLMNOPQRSTUVWXYZ”;  
  358.                 break;  
  359.             case 'x’:  
  360.                 $a = “abcdefghijklmnopqrstuvwxyz”;  
  361.                 break;  
  362.             default:  
  363.                 $a = “0123456789abcdef”;  
  364.                 break;  
  365.         }  
  366.         $z = str_split($a);  
  367.         for ($c=,$g=0; $g < $b$g++) {   
  368.             $c .= $z[ceil(100000000 * (self::random())) % count($z)];  
  369.         }  
  370.         return $c;  
  371.     }  
  372.   
  373.     public static function filterGBK_SpecialChars($str)  
  374.     {  
  375.         $str = str_replace('“’,,$str);  
  376.         $str = str_replace('”’,,$str);  
  377.         return $str;  
  378.     }  
  379.   
  380.     public static function charAt($str$index = 0){  
  381.         return substr($str$index, 1);  
  382.     }  
  383.   
  384.     public static function getTK2($param1){  
  385.         $_loc1_ = 0;  
  386.         $_loc2_ = 0;  
  387.         foreach$param1 as $_loc3_ => $_loc4_ ){  
  388.             $_loc5_[] = $_loc3_ . “=” . $_loc4_;  
  389.         }  
  390.         $_loc6_ = join(“|”,$_loc5_);  
  391.         $_loc7_ = base64_encode($_loc6_);  
  392.         $_loc8_ = str_replace(array(“+”,“/”,“=”),array(“_”,“~”,“-“),$_loc7_);  
  393.         $_loc11 = “”;  
  394.         foreachstr_split($_loc8_as $_loc9_ => $_loc10_ ){  
  395.             $_loc11 .= self::charAt($_loc8_,strlen($_loc8_)-$_loc9_-1);  
  396.         }  
  397.         return $_loc11;  
  398.     }  
  399. }  

下载仅供下载体验和测试学习,不得商用和正当使用。

[ppwp passwords=”zhishitu.cn”]

下载体验

应版权要求,禁止分享,敬请谅解,有问题务必找客服哈。

如何获取解压密码

有问题找客服哈,并领取学习福利!

[/ppwp]

点击下载

小鱼网是一个美好的开源学习社区,学习编程,学习WordPress,下载WordPress插件主题,
小鱼网 » 芒果解析源码

常见问题FAQ

发表回复

分享最优质的学习资料

立即查看 了解详情