虎牙直播解析源码

资源分享虎牙直播解析源码

虎牙直播解析源码

  1. <?php
  2. echo json_encode(HuYa::parse($url));
  3. class HuYa
  4. {
  5. public static function parse($url)
  6. {
  7. $vid = explode(“.html"basename($url))[0];
  8. return self::get_video_url($vid);
  9. }
  10. public static function get_video_url($vid)
  11. {
  12. $api = “http://v-api-play.huya.com/?r=vhuyaplay%2Fvideo&vid={$vid}";
  13. $content = self::curl($api);
  14. $data = json_decode($content,true);
  15. if($data[“code"]==1){
  16. $result = $data[“result"];
  17. $cover = $result[“cover"];
  18. $videoinfo[“poster"] = $cover;
  19. $items = $result[“items"];
  20. foreach ($items as $key => $value) {
  21. $height = $value[“height"];
  22. $vurl = $value[“transcode"][“urls"][0];
  23. switch ($height) {
  24. case “360":$def=“标清";break;
  25. case “540":$def=“高清";break;
  26. case “720":$def=“超清";break;
  27. case “1080":$def=“超高清";break;
  28. }
  29. if (GlobalBase::is_ipad()) {
  30. if($height==’720′){
  31. $videoinfo['code’] = 200;
  32. $videoinfo[“data"][“url"]= $vurl;
  33. break;
  34. }
  35. }else{
  36. $video[0] = $vurl;
  37. $video[1] = “video/mp4";
  38. $video[2] = $def;
  39. $video[3] = $height!=’720′ ? 0 : 10;
  40. $videoinfo['code’] = 200;
  41. $videoinfo[“data"][“video"][$key] = $video;
  42. $videoinfo[“data"][“flashplayer"] = true;
  43. }
  44. }
  45. return $videoinfo;
  46. }
  47. }
  48. public static function curl($url)
  49. {
  50. $params[“ua"] = “Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/63.0.3239.84 Safari/537.36";
  51. return GlobalBase::curl($url,$params);
  52. }
  53. }
  54. ?>

Posted by 柴郡猫