正文

龙珠解析源码

龙珠解析源码

  1. <?php
  2. echo json_encode(LongZhu::parse($url));
  3. /**
  4. */
  5. class LongZhu
  6. {
  7.     public static function parse($url)
  8.     {
  9.         $vid = explode(“?”basename($url))[0];
  10.         $data = self::get_video_url($vid);
  11.         if(!emptyempty($data)){
  12.             return $data;
  13.         }else{
  14.             $content = self::curl($url);
  15.             preg_match(‘#“RoomId”:(.*?),#’,$content,$_rid);
  16.             if(!emptyempty($_rid[1])){
  17.                 $rid = $_rid[1];
  18.             }else{
  19.                 preg_match(“#ROOMID\s*=\s*'(.*?)’;#”,$content,$__rid);
  20.                 $rid = $__rid[1];
  21.             }
  22.             return self::get_live_url($rid);
  23.         }
  24.     }
  25.     public static function get_video_url($mid)
  26.     {
  27.         $api = “http://api.v.plu.cn/CloudMedia/GetInfoForPlayer?mediaId={$mid}”;
  28.         $content = self::curl($api);
  29.         $data = json_decode($content,true);
  30.         if(!emptyempty($data[“urls”])){
  31.             $urls = $data[“urls”];
  32.             foreach ($urls as $key => $value) {
  33.                 $level = $value[“RateLevel”];
  34.                 $ext = $value[“Ext”];
  35.                 $vurl = $value[“SecurityUrl”];
  36.                 switch ($level) {
  37.                     case 1:$def=“标清”;break;
  38.                     case 2:$def=“高清”;break;
  39.                     case 3:$def=“超清”;break;
  40.                     case 4:$def=“原画”;break;
  41.                     default:$def=“自动”;break;
  42.                 }
  43.                 switch ($ext) {
  44.                     case ‘flv’:$type = “flv”;break;
  45.                     case ‘mp4’:$type = “mp4″;break;
  46.                     case ‘m3u8’:$type = “m3u8″;break;
  47.                 }
  48.                 if (GlobalBase::is_ipad()) {
  49.                     if($ext==’m3u8′){
  50.                         $videoinfo[‘code’] = 200;
  51.                         $videoinfo[“data”][“video”][“file”] = $vurl;
  52.                         $videoinfo[“data”][“video”][“type”] = “video/m3u8″;
  53.                         break;
  54.                     }
  55.                 }else{
  56.                     $video[0] = $vurl;
  57.                     $video[1] = $type;
  58.                     $video[2] = $type.$def;
  59.                     $video[3] =  $level != 2 ? 0 : 10;
  60.                     $videoinfo[“code”] = 200;
  61.                     $videoinfo[“data”][“video”][$key] = $video;
  62.                     $videoinfo[“data”][“flashplayer”] = true;
  63.                 }
  64.             }
  65.             return $videoinfo;
  66.         }else{
  67.             return “”;
  68.         }
  69.     }
  70.     public static function get_live_url($rid)
  71.     {
  72.         $api = “http://liveapi.plu.cn/liveapp/roomstatus?roomId={$rid}”;
  73.         $content = self::curl($api);
  74.         $data = json_decode($content,true);
  75.         $img = $data[“cover”];
  76.         $vurl = $data[“streamUri”];
  77.         $videoinfo[“poster”] = $img;
  78.         if (!GlobalBase::is_ipad()) {
  79.             $videoinfo[“data”][“live”] = true;
  80.             $videoinfo[“data”][“flashplayer”] = true;
  81.         }
  82.         $videoinfo[‘code’] = 200;
  83.         $videoinfo[“data”][“video”][“file”] = $vurl;
  84.         $videoinfo[“data”][“video”][“type”] = “video/m3u8″;
  85.         return $videoinfo;
  86.     }
  87.     public static function curl($url)
  88.     {
  89.         $params[“ua”] = “Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/63.0.3239.84 Safari/537.36″;
  90.         return GlobalBase::curl($url,$params);
  91.     }
  92. }
  93.  ?>