hochu.php 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  1. <?php
  2. error_reporting(E_ERROR | E_PARSE);
  3. if (isset($_GET['url'])) {
  4. $headers = [
  5. 'Connection: keep-alive',
  6. 'User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/121.0.0.0 Safari/537.36 Edg/121.0.0.0',
  7. 'Accept: */*',
  8. 'Origin: http://cdnneedtv.ru',
  9. 'Referer: http://cdnneedtv.ru/',
  10. 'Accept-Encoding: gzip, deflate',
  11. 'Accept-Language: es,es-ES;q=0.9,en;q=0.8,en-GB;q=0.7,en-US;q=0.6',
  12. ];
  13. echo curl_get(rtrim($_GET['url']), $headers);
  14. exit;
  15. } else if (isset($_GET['id'])) {
  16. $headers = [
  17. "Accept: 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.7",
  18. "Accept-Language: es,es-ES;q=0.9,en;q=0.8,en-GB;q=0.7,en-US;q=0.6",
  19. "Cache-Control: no-cache",
  20. "Connection: keep-alive",
  21. "Pragma: no-cache",
  22. "Referer: http://hochu.tv/",
  23. "Upgrade-Insecure-Requests: 1",
  24. "User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/121.0.0.0 Safari/537.36 Edg/121.0.0.0",
  25. ];
  26. $ch_id = $_GET['id'];
  27. $channel_url = "http://hochu.tv/".$ch_id.".html";
  28. $response = curl_get($channel_url, headers);
  29. preg_match('/<iframe width=.*src="(.*)" .*>/i', $response, $matches);
  30. $url=$matches[1];
  31. $response = curl_get($url, $headers);
  32. $server = get_server_url();
  33. $pattern = '/file:"([^"]+)"}/i';
  34. preg_match($pattern, $response, $matches);
  35. if (isset($matches[1])) {
  36. $curl = curl_init($matches[1]);
  37. curl_setopt($curl, CURLOPT_URL, $matches[1]);
  38. curl_setopt($curl, CURLOPT_FOLLOWLOCATION, true);
  39. curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
  40. curl_setopt($curl, CURLOPT_HTTPHEADER, $headers);
  41. curl_setopt($curl, CURLOPT_TIMEOUT, 30);
  42. curl_setopt($curl, CURLOPT_ENCODING, '');
  43. curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, false); // Solo para depuración, ten cuidado
  44. curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false); // Solo para depuración, ten cuidado
  45. $response = curl_exec($curl);
  46. $play_url = str_replace("index.m3u8", "", curl_getinfo($curl)["url"]);
  47. curl_close($curl);
  48. $lineas_ts = explode("\n", $response);
  49. for ($i = 0; $i < count($lineas_ts) - 1; $i++) {
  50. if (strpos($lineas_ts[$i], '#') !== false) {
  51. echo $lineas_ts[$i].PHP_EOL;
  52. } else {
  53. echo $server.'?url='.$play_url.trim($matches[2]).$lineas_ts[$i].PHP_EOL;
  54. }
  55. }
  56. } else {
  57. echo "No se encontró la URL en el contenido.";
  58. }
  59. }else{
  60. $headers = ["User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/121.0.0.0 Safari/537.36 Edg/121.0.0.0"];
  61. $response = curl_get("http://hochu.tv/", headers);
  62. $pattern = '/<td.*<a.*href="(.*)"><img/i';
  63. preg_match_all($pattern, $response, $matches_href);
  64. $pattern = '/<td.*<a.*href=.*<img.*src="(.*)" style=".*>/i';
  65. preg_match_all($pattern, $response, $matches_images);
  66. $result="#EXTM3U".PHP_EOL;
  67. $server = get_server_url();
  68. $count=0;
  69. foreach ($matches_href[1] as $value) {
  70. $image_path=$matches_images[1][$count];
  71. $name=str_replace(".html","",$value);
  72. $name=str_replace("/","",$name);
  73. $result.='#EXTINF:-1 tvg-name="'.$name.'" tvg-logo="'.$server.'?url='."http://hochu.tv".$image_path.'",'.$name.PHP_EOL;
  74. $result.= $server.'?id='.$name.PHP_EOL;
  75. $count+=1;
  76. }
  77. header("Content-Type:vnd.apple.mpegURL");
  78. header("Content-Disposition:attachment;filename=index.m3u8");
  79. echo $result;
  80. }
  81. function get_server_url(){
  82. $headers = getallheaders();
  83. $schema = $headers["X-Forwarded-Proto"];
  84. if (!$schema){
  85. $schema = isset($_SERVER['HTTPS']) ? 'https' : 'http';
  86. }
  87. $host = $headers["X-Forwarded-Server-Name"];
  88. if (!$host){
  89. $host = $_SERVER['HTTP_HOST'];
  90. }else{
  91. $host .= ":" . $headers["X-Forwarded-Port"];
  92. }
  93. return $schema . "://" . $host . $_SERVER['SCRIPT_NAME'];
  94. }
  95. function curl_get($url, $headers) {
  96. $curl = curl_init($url);
  97. curl_setopt($curl, CURLOPT_URL, $url);
  98. curl_setopt($curl, CURLOPT_FOLLOWLOCATION, true);
  99. curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
  100. curl_setopt($curl, CURLOPT_HTTPHEADER, $headers);
  101. curl_setopt($curl, CURLOPT_TIMEOUT, 30);
  102. curl_setopt($curl, CURLOPT_ENCODING, '');
  103. curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, false); // Solo para depuración, ten cuidado
  104. curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false); // Solo para depuración, ten cuidado
  105. $resp = curl_exec($curl);
  106. curl_close($curl);
  107. return $resp;
  108. }
  109. ?>