资源分享

NOW直播解析源码

NOW直播解析源码

  1. <?php
  2. //https://now.qq.com/cgi-bin/now/web/room/get_room_info_v2?room_id=1983753
  3. //https://now.qq.com/cgi-bin/now/web/user/get_personal_live_rcmd_read?_=0.6791041731369902&bkn=869715713&num=19&tab_id=2
  4. //https://now.qq.com/pc/index.html?roomid=1210251521
  5. //https://now.qq.com/h5/index.html?roomid=79072731
  6. //https://now.qq.com/cgi-bin/now/web/room/get_live_room_url?platform=4&room_id=1210676514
  7. //require_once("../include/global.inc.php");
  8. echo json_encode(Now::parse($url));
  9. /**
  10. */
  11. class Now
  12. {
  13.     public static function parse($url)
  14.     {
  15.         parse_str(parse_url($url)["query"]);
  16.         if($roomid){
  17.             return self::get_room_info_v2($roomid);
  18.         }
  19.     }
  20.     public static function get_room_info_v2($room_id)
  21.     {
  22.         $api = "https://now.qq.com/cgi-bin/now/web/room/get_room_info_v2?room_id=$room_id";
  23.         $content = self::curl($api);
  24.         $data = json_decode($content,true)["result"];
  25.         $is_on_live = $data["is_on_live"];
  26.         if($is_on_live){//是否直播
  27.             return self::get_live_room_url($room_id);
  28.         }else{
  29.             if(!emptyempty($data["vid"])){
  30.                 $vid = $data["vid"];
  31.                 return self::get_record_room_info($vid);
  32.             }else{
  33.                 return GlobalBase::get_unknown_video();
  34.             }
  35.         }
  36.     }
  37.     public static function get_record_room_info($vid)
  38.     {
  39.         $api = "https://now.qq.com/cgi-bin/now/web/room/get_record_room_info?vid=$vid";
  40.         $content = self::curl($api);
  41.         $data = json_decode($content,true)["result"];
  42.         $record_video_url = $data["record_video_url"];
  43.         $video_cover_url = $data["video_cover_url"];
  44.         $videoinfo["poster"] = $video_cover_url;
  45.         $videoinfo["video"]["file"] = $record_video_url;
  46.         $videoinfo["video"]["type"] = "video/m3u8";
  47.         return $videoinfo;
  48.     }
  49.     public static function get_live_room_url($room_id)
  50.     {
  51.         $api = "https://now.qq.com/cgi-bin/now/web/room/get_live_room_url?platform=4&room_id=$room_id";
  52.         $content = self::curl($api);
  53.         $data = json_decode($content,true)["result"];
  54.         $videoURLList = $data["videoURLList"];
  55.         foreach ($videoURLList as $key => $value) {
  56.             if (GlobalBase::is_ipad()) {
  57.                 $videoinfo["url"]= $value;
  58.                 break;
  59.             }else{
  60.                 switch ($key) {
  61.                     case 0:$def = "自动";break;
  62.                     case 1:$def = "高清";break;
  63.                     case 2:$def = "标清";break;
  64.                     case 3:$def = "流畅";break;
  65.                 }
  66.                 $videoinfo["live"] = true;
  67.                 $video[0] = $value;
  68.                 $video[1] = "video/m3u8";
  69.                 $video[2] = $def;
  70.                 $video[3] =  $key != 0 ? 0 : 10;
  71.                 $videoinfo["video"][$key] = $video;
  72.             }
  73.         }
  74.         return $videoinfo;
  75.     }
  76.     public static function curl($url)
  77.     {
  78.         $params["ua"] = "Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/63.0.3239.84 Safari/537.36";
  79.         return GlobalBase::curl($url,$params);
  80.     }
  81. }
  82.  ?>
(0)

本文由 柴郡猫-cheshirex,搬瓦工VPS,bandwagonhost 作者:cheshirex 发表,转载请注明来源!

关键词:

热评文章

发表评论

电子邮件地址不会被公开。 必填项已用*标注