vqq.php 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144
  1. <?php
  2. error_reporting(0);
  3. if (!file_exists('Cache/qq')) {mkdir('Cache/qq', 0777, true);}
  4. $url = $_GET["url"];
  5. echo json_encode(VQQ::parse($url));
  6. class VQQ
  7. {
  8. public static function parse($url) {
  9. $content = file_get_contents($url);
  10. preg_match('#"drm":(0|1|2),#iU',$content,$isdrm);
  11. preg_match('#<title>(.*?)<\/title>#iU',$content,$name);
  12. $drm = $isdrm[1];
  13. preg_match('#cid=(\w+)&vid=(\w+)["|&]#',$content,$id);
  14. $cid = empty($id[1])? 0 :$id[1];
  15. $vid = $id[2];
  16. if (!$vid) {
  17. preg_match('#&vid=(\w+)["|&]#',$content,$id);
  18. $vid = $id[1];
  19. $cid = '';
  20. }
  21. $ep_file= 'Cache/qq/'.$vid.'.m3u8';
  22. if (!file_exists($ep_file)||filemtime($ep_file)+10800 < time()){
  23. if ($drm != 0) { //是否付费
  24. $cookie = file_get_contents("qqck.txt");;//这里写你的cookie
  25. return self::h5($vid,$cookie);
  26. } else{
  27. $cookie = file_get_contents("qqck.txt");;//这里写你的cookie
  28. return self::h5($vid,$cookie);
  29. }
  30. }else{
  31. $vurl = 'http://'.$_SERVER['HTTP_HOST'].'/'.$ep_file;
  32. $videoinfo['code'] = 200;
  33. $videoinfo['success'] = 1;
  34. $videoinfo['url'] = $vurl;
  35. $videoinfo['type'] = 'hls';
  36. $videoinfo['player'] = "dplayer";
  37. $videoinfo['cache'] = "1";
  38. }
  39. return $videoinfo;
  40. }
  41. public static function h5($vid,$cookie){
  42. $api = 'https://h5vv6.video.qq.com/getinfo?encver=2&defn=fhd&platform=10801&otype=ojson&sdtfrom=v4138&appVer=7&dtype=3&vid='.$vid.'&newnettype=4';
  43. $body = self::gh5($api,$cookie);
  44. $data = json_decode($body,true);
  45. $vi = $data["vl"]["vi"][0];
  46. $ui = $vi["ul"]["ui"];
  47. $url = $ui[3]["url"];
  48. $hls = $ui[3]['hls']['pt'];
  49. $vurl = $url.$hls;
  50. if($vurl ==''||$vurl ==null){ return ['code' => '404','url' => 'null']; }
  51. $data = file_get_contents($vurl);
  52. $lines = preg_split('/[\r\n]+/s', $data);//按行进行分割字符串
  53. $durations = array();
  54. $urls = array();
  55. $bool = true;
  56. $targetduration = "";
  57. foreach ($lines as $value) {
  58. if(!empty(strstr($value,"#EXT-X-TARGETDURATION:"))){//多码率
  59. $targetduration = $value;
  60. }else if(!empty(strstr($value,"#EXTINF:"))){//单码率
  61. $durations[count($durations)] = $value;
  62. $bool = true;
  63. }else if(!empty($value)&&substr($value,0,1)!="#"){
  64. if($bool){
  65. $urls[count($urls)] = $value;
  66. }
  67. }
  68. }
  69. $url = preg_replace('/(http:\/\/(.*?)\/(.*?)\/(.*?)\/)/i','https://omts.tc.qq.com/',$url);
  70. $m3u8 = "#EXTM3U\n#EXT-X-VERSION:3\n";
  71. $m3u8 .= empty($targetduration)?"#EXT-X-TARGETDURATION:7200\n" : $targetduration."\n";
  72. foreach ($durations as $key => $value) {
  73. $m3u8 .= $value."\n".$url.$urls[$key]."\n";
  74. }
  75. $m3u8 = str_replace('&ver=4','',$m3u8);
  76. $m3u8 .="#EXT-X-ENDLIST";
  77. $ep_file= 'Cache/qq/'.$vid.'.m3u8';
  78. file_put_contents($ep_file, $m3u8);
  79. $vvurl = 'http://'.$_SERVER['HTTP_HOST'].'/'.$ep_file;
  80. $videoinfo['success'] = 1;
  81. $videoinfo['code'] = 200;
  82. $videoinfo['url'] = $vvurl;
  83. $videoinfo['type'] = 'hls';
  84. $videoinfo['player'] = "dplayer";
  85. return $videoinfo;
  86. }
  87. public static function gh5($url,$cookie){
  88. $header = array(
  89. 'Host: h5vv6.video.qq.com',
  90. 'Accept: */*',
  91. 'Content-Type: text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.9',
  92. 'Connection: keep-alive',
  93. 'Cookie: '.$cookie,
  94. 'User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/97.0.4692.99 Safari/537.36',
  95. 'Referer: https://servicewechat.com/wxa75efa648b60994b/69/page-frame.html',
  96. 'Accept-Language: zh-CN,zh;q=0.9',
  97. );
  98. $curl = curl_init();
  99. //初始化 curl
  100. curl_setopt($curl, CURLOPT_URL, $url);
  101. //要访问网页 URL 地址
  102. curl_setopt($curl, CURLOPT_HTTPHEADER, $header);//设定是否输出页面内容
  103. curl_setopt($curl, CURLOPT_REFERER,$url) ;
  104. //伪装网页来源 URL
  105. curl_setopt($curl, CURLOPT_AUTOREFERER, 1);
  106. //当Location:重定向时,自动设置header中的Referer:信息
  107. curl_setopt($curl, CURLOPT_TIMEOUT, 10);
  108. //数据传输的最大允许时间
  109. curl_setopt($curl, CURLOPT_HEADER, 0);
  110. //不返回 header 部分
  111. curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
  112. //返回字符串,而非直接输出到屏幕上
  113. curl_setopt($curl, CURLOPT_FOLLOWLOCATION,1);
  114. //跟踪爬取重定向页面
  115. curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, '0');
  116. //不检查 SSL 证书来源
  117. curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, '0');
  118. //不检查 证书中 SSL 加密算法是否存在
  119. curl_setopt($curl, CURLOPT_ENCODING, '');
  120. //解决网页乱码问题
  121. //curl_setopt($curl, CURLOPT_COOKIE, '');
  122. //从字符串传参来提交cookies
  123. $data = curl_exec($curl);
  124. //运行 curl,请求网页并返回结果
  125. curl_close($curl);
  126. //关闭 curl
  127. return $data;
  128. }
  129. }
  130. ?>