EPG.php 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161
  1. <?php
  2. if(date_default_timezone_get() != "Asia/Shanghai") date_default_timezone_set("Asia/Shanghai");
  3. $cgname = array(
  4. "CCTV1"=>"b3666b9d",
  5. "CCTV2"=>"c5717c2d",
  6. "CCTV3"=>"53eda06f",
  7. "CCTV4"=>"0ccc41bf",
  8. "CCTV5"=>"6b26bee1",
  9. "CCTV5+"=>"e4e3801d",
  10. "CCTV6"=>"ddb707c0",
  11. "CCTV7"=>"f2d13f2a",
  12. "CCTV8"=>"13e8f054",
  13. "CCTV9"=>"8f932b7b",
  14. "CCTV10"=>"7651a0a2",
  15. "CCTV11"=>"0a2de840",
  16. "CCTV12"=>"1e983148",
  17. "CCTV13"=>"f5b1a323",
  18. "CCTV14"=>"6fff4f43",
  19. "CCTV15"=>"3201ff16",
  20. "CCTV-17"=>"d3d48ldf",
  21. "东方卫视"=>"95f40184",
  22. "湖南卫视"=>"7d4daf1f",
  23. "凤凰卫视"=>"65e0f71a",
  24. "厦门卫视"=>"d6253770",
  25. "安徽卫视"=>"06a195fd",
  26. "浙江卫视"=>"9f005630",
  27. "江苏卫视"=>"69e7e66e",
  28. "东南卫视"=>"da0c3f96",
  29. "北京卫视"=>"696f2203",
  30. "广东卫视"=>"cb608c10",
  31. "深圳卫视"=>"50ca1f4c",
  32. "青海卫视"=>"6cf61152",
  33. "海峡卫视"=>"1d7e3bf3",
  34. "海南卫视"=>"8024c685",
  35. "黑龙江卫视"=>"59736a35",
  36. "吉林卫视"=>"a3aa4d01",
  37. "辽宁卫视"=>"019d9e5e",
  38. "河北卫视"=>"25feea76",
  39. "河南卫视"=>"789d0d22",
  40. "山西卫视"=>"d667526e",
  41. "陕西卫视"=>"6ef94ac4",
  42. "山东卫视"=>"c62d45e9",
  43. "江西卫视"=>"61914025",
  44. "湖北卫视"=>"526cbae7",
  45. "贵州卫视"=>"a136a49d",
  46. "云南卫视"=>"3a19b822",
  47. "甘肃卫视"=>"fac1ecf6",
  48. "宁夏卫视"=>"1c4d4f90",
  49. "西藏卫视"=>"e237763b",
  50. "新疆卫视"=>"aa83e122",
  51. "内蒙古卫视"=>"442cb1d6",
  52. "天津卫视"=>"b5cb5697",
  53. "四川卫视"=>"e5b252e4",
  54. "重庆卫视"=>"54cb9087",
  55. "广东.广东珠江"=>"e5815c01",
  56. "南方卫视"=>"f0a3d1b2",
  57. "深视都市频道"=>"0a0fa12e",
  58. "深视电视剧频道"=>"8abb60ec",
  59. "深视财经生活频道"=>"285dba33",
  60. "深圳娱乐频道"=>"ee3c6fc6",
  61. "深圳公共频道"=>"105358d0",
  62. "深圳少儿频道"=>"b79efdc1",
  63. "广东.广东影视"=>"02231bc5",
  64. "广东.经济科教"=>"dae1d7e4",
  65. "广东.广东新闻"=>"45781beb",
  66. "广东.广东公共"=>"0e89a6bf",
  67. "广东.广东综艺"=>"efa3b46b",
  68. "广东.广东少儿"=>"cee818c1",
  69. "广东.南方卫视"=>"ccfe6b99",
  70. "江西都市"=>"7ccabccb",
  71. "江西少儿"=>"6c5dfa38",
  72. "江西经济生活"=>"a2993378",
  73. "江西影视旅游"=>"ea576ce5",
  74. "江西教育"=>"0fdf31ad",
  75. "江西公共农业"=>"e92018d0",
  76. "南昌新闻综合频道"=>"2ec4c09d",
  77. "南昌都市频道"=>"13d434fe",
  78. "南昌公共频道"=>"777d0cb4",
  79. "南昌资讯频道"=>"efd6057b",
  80. );
  81. function compress_html($string) {
  82. $string = str_replace("\r", '', $string); //清除换行符
  83. $string = str_replace("\n", '', $string); //清除换行符
  84. $string = str_replace("\t", '', $string); //清除制表符
  85. return $string;
  86. }
  87. $cname = !empty($_GET["ch"]) ? $_GET["ch"] : exit(json_encode(["code" => 500, "msg" => "EPG频道参数不能为空!", "name" => $name, "date" => null, "data" => null], JSON_UNESCAPED_UNICODE));
  88. $dt1=$_GET['date'];
  89. $dt2=date('Y-m-d',strtotime($dt1)+86400);
  90. $w1=date("w",strtotime($dt1));
  91. if ($w1<'1') {$w1=7;}
  92. $w0=$w1-1;
  93. if ($w0<'1') {$w0=7;}
  94. if (empty($cgname[$cname])) {
  95. exit(json_encode(["code" => 500, "msg" => "未定义频道ID!", "name" => $name, "date" => null, "data" => null], JSON_UNESCAPED_UNICODE));
  96. } else {
  97. if ((strtotime($dt1) < time() && $w1 > date("w")) || date("Ymd", strtotime($dt1)) > (date("Ymd") - date("w") + '7')) {
  98. exit(json_encode(["code" => 500, "msg" => "超出搜视网时间范围!", "name" => $name, "date" => null, "data" => null], JSON_UNESCAPED_UNICODE));
  99. } else {
  100. $url0 = "https://www.tvsou.com/epg/";
  101. $t0 = array();
  102. $t1 = array();
  103. $nm = array();
  104. //获取前一天的最后一个节目名,作为当天第一个节目
  105. $url = $url0 . $cgname[$cname] . '/w' . $w0;
  106. $ch = curl_init();
  107. curl_setopt($ch, CURLOPT_URL, $url);
  108. curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
  109. curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
  110. curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, FALSE);
  111. $re = curl_exec($ch);
  112. curl_close($ch);
  113. $re = compress_html($re);
  114. preg_match('|<table class="layui-table c_table"(.*?)layui-tab-item|i', $re, $u);
  115. preg_match_all('|<tr>([\s\S]+?)<\/tr>|', trim($u[1]), $u);
  116. $u = $u[1];
  117. $ysdnum = sizeof($u);
  118. preg_match_all('|_blank\'>(.*?)<\/a>|', $u[$ysdnum - 1], $tr);
  119. $lstnm = $tr[1][1];
  120. //获取当天节目表
  121. $url = $url0 . $cgname[$cname] . '/w' . $w1;
  122. $ch = curl_init();
  123. curl_setopt($ch, CURLOPT_URL, $url);
  124. curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
  125. curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
  126. curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, FALSE);
  127. $re = curl_exec($ch);
  128. curl_close($ch);
  129. $re = compress_html($re);
  130. preg_match('|<table class="layui-table c_table"(.*?)layui-tab-item|i', $re, $u);
  131. preg_match_all('|<tr>([\s\S]+?)<\/tr>|', trim($u[1]), $u);
  132. $u = $u[1];
  133. $num = sizeof($u);
  134. for ($i = 0;$i < $num;$i++) {
  135. preg_match_all('|_blank\'>(.*?)<\/a>|', $u[$i], $tr);
  136. $t0[] = $tr[1][0];
  137. $nm[] = $tr[1][1];
  138. }
  139. //转码节目表
  140. for ($i = 1;$i < $num;$i++) {
  141. $t1[] = $t0[$i];
  142. }
  143. $t1[] = '00:00'; //当日最后一个节目设定结束时间,避免冲突
  144. $chn.= "{\"channel_name\":\"" . $cname . "\",\"date\":\"" . $dt1 . "\",\"epg_data\":[";
  145. $chn.= "{\"title\":\"" . $lstnm . "\",\"start\":\"00:00\",\"end\":\"" . $t0[0] . "\"},"; //前一天的最后一个节目名作为当天第一个节目,开始时间为00:00
  146. for ($i = 0;$i < $num;$i++) {
  147. $chn.= "{\"title\":\"" . $nm[$i] . "\",\"start\":\"" . $t0[$i] . "\",\"end\":\"" . $t1[$i] . "\"},";
  148. }
  149. $chn = substr($chn, 0, -1);
  150. $chn.= "]}";
  151. }
  152. }
  153. echo $chn;
  154. ?>