1090ys.php 7.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246
  1. <?php
  2. header("Content-Type: text/html; charset=UTF-8");
  3. libxml_use_internal_errors(true);
  4. $typeid =$_GET["t"];
  5. $page = $_GET["pg"];
  6. $ids = $_GET["ids"];
  7. $web='http://1090ys2.com';
  8. //===============================================影视分类相关配置开始===========================
  9. //电影 连续剧 要加一个空格,否则无法显示
  10. $movietype = '{"class":[{"type_id":1,"type_name":"电 影"},{"type_id":2,"type_name":"国产剧"},{"type_id":3,"type_name":"韩剧"},{"type_id":4,"type_name":"美剧"},{"type_id":5,"type_name":"日剧"},{"type_id":22,"type_name":"综艺"},{"type_id":26,"type_name":"国漫"},{"type_id":25,"type_name":"日漫"}]}';
  11. //===============================================影视分类相关配置结束===========================
  12. //===============================================影视列表相关配置开始===========================
  13. //取出影片的链接 默认引用xpath列表规则
  14. $linkAttr='href';
  15. //取出影片ID的文本左边 从$linkAttr取值 /show/78197.html 影视ID78197前面的文本是/show/
  16. $url1='/show/';
  17. //取出影片ID的文本右边 从$linkAttr取值 /show/78197.html 影视ID78197后面的文本是.html
  18. $url2='.html';
  19. //xpath列表
  20. $query='//div[@class="stui-vodlist__box"]/a';
  21. //取出影片的图片
  22. $picAttr='//div[@class="stui-vodlist__box"]/a/@data-original';
  23. //取出影片的标题 默认引用xpath列表规则
  24. $titleAttr='title';
  25. //影视更新情况 例如:更新至*集
  26. $query2 = '//div[@class="stui-vodlist__box"]/a/span[@class="pic-text text-right"]';
  27. //影视列表链接 pageid=页码 typeid=类目ID
  28. $liebiao='http://1090ys2.com/whole/typeid/page/pageid.html';
  29. //每页多少个影片
  30. $num=30;
  31. //===============================================影视列表相关配置结束===========================
  32. //===============================================影视详情相关配置开始===========================
  33. //影片链接 vodid=影片ID
  34. $detail='http://1090ys2.com/show/vodid.html';
  35. //影片名称
  36. $vodtitle='//div[@class="stui-content__detail"]/h1';
  37. //影片类型 /html/body/div[3]/div/div[2]/div[1]/div/div/div/div[2]/p[3]/text()[1]
  38. $vodtype='/html/body/div[3]/div/div[2]/div[1]/div/div/div/div[2]/p[3]/text()[1]';
  39. //播放地址名称 /html/body/div[3]/div/div[2]/div[2]/div/div[1]/div/h3
  40. $playname='//div[@class="stui-pannel__head bottom-line active clearfix"]/h3';
  41. //播放地址
  42. $playurl='//div[@class="stui-pannel_bd col-pd clearfix"]';
  43. //取出影片的全部播放链接 注意这里的数字在下面$i2= $i+1;引用 $i是从0开始 具体情况具体分析
  44. // /html/body/div[3]/div/div[2]/div[2]/div/div[2]/ul/li/a /html/body/div[3]/div/div[2]/div[3]/div/div[2]/ul/li/a
  45. $linkAttr2='//html/body/div[3]/div/div[2]/div[数字]/div/div[2]/ul/li/a';
  46. //取出影片图片
  47. $vodimg='//a[@class="stui-vodlist__thumb picture v-thumb"]/img/@data-original';
  48. //取出影片简介
  49. $vodtext='//span[@class="detail-sketch"]';
  50. //取出影片年份
  51. $vodyear='/html/body/div[3]/div/div[2]/div[1]/div/div/div/div[2]/h1';
  52. //===============================================影视详情相关配置结束===========================
  53. if ($typeid<> null && $page<>null){
  54. $liebiao=str_replace("typeid",$typeid,$liebiao);
  55. $liebiao=str_replace("pageid",$page,$liebiao);
  56. //读取影视列表
  57. $html = curl_get($liebiao);
  58. $dom = new DOMDocument();
  59. $dom->loadHTML($html);
  60. $dom->normalize();
  61. $xpath = new DOMXPath($dom);
  62. $texts = $xpath->query($query2);
  63. $events = $xpath->query($query);
  64. $picevents = $xpath->query($picAttr);
  65. $length=$events->length;
  66. if ($length<$num)
  67. {
  68. $page2=$page;
  69. }else{
  70. $length=$length+1;
  71. $page2=$page + 1;
  72. }
  73. $result='{"code":1,"page":'.$page.',"pagecount":'. $page2 .',"total":'. $length.',"list":[';
  74. for ($i = 0; $i < $events->length; $i++) {
  75. $event = $events->item($i);
  76. $text = $texts->item($i)->nodeValue;
  77. $link = $event->getAttribute($linkAttr);
  78. $title = $event->getAttribute($titleAttr);
  79. $pic = $picevents->item($i)->nodeValue;
  80. if($url1<>null){
  81. $link2 =getSubstr($link,$url1,$url2);
  82. }else{
  83. $link2 =$link;
  84. }
  85. if (substr($pic,0,4)<>'http'){
  86. $pic = $web.$pic;
  87. }
  88. $result=$result.'{"vod_id":"'.$link2.'","vod_name":"'.$title.'","vod_pic":"'.$pic.'","type_id":'.$typeid.',"vod_remarks":"'.$text.'"},';
  89. }
  90. $result=substr($result, 0, strlen($result)-1).']}';
  91. echo $result;
  92. }else if ($ids<> null){
  93. $detail=str_replace("vodid",$ids,$detail);
  94. $html = curl_get($detail);
  95. $dom = new DOMDocument();
  96. $dom->loadHTML($html);
  97. $dom->normalize();
  98. $xpath = new DOMXPath($dom);
  99. $texts = $xpath->query($vodtitle);
  100. $text = $texts->item(0)->nodeValue;
  101. $texts = $xpath->query($vodtype);
  102. $type = $texts->item(0)->nodeValue;
  103. $texts = $xpath->query($vodtext);
  104. $vodtext2 = $texts->item(0)->nodeValue;
  105. $texts = $xpath->query($vodyear);
  106. $year = $texts->item(0)->nodeValue;
  107. $texts = $xpath->query($vodimg);
  108. $img = $texts->item(0)->nodeValue;
  109. if (substr($img,0,4)<>'http'){
  110. $img = $web.$img;
  111. }
  112. $result='{"list":[{"vod_id":"'.$ids.'",';
  113. $result=$result.'"vod_name":"'.$text.'",';
  114. $result=$result.'"vod_pic":"'.$img.'",';
  115. $result=$result.'"type_name":"'.$type.'",';
  116. $result=$result.'"vod_year":"'.$year.'",';
  117. $result=$result.'"vod_content":"'.$vodtext2.'",';
  118. $yuan = '';
  119. $dizhi = '';
  120. $text1 = $xpath->query($playname);
  121. $text2 = $xpath->query($playurl);
  122. for ($i = 0; $i < $text2->length; $i++) {
  123. $event2 = $text2->item($i);
  124. $event1 = $text1->item($i);
  125. $bfyuan = $event1->nodeValue;
  126. $yuan = $yuan.$bfyuan.'$$$';
  127. // //*[@id="vlink_1"]/ul/li/a //*[@id="vlink_2"]/ul/li/a
  128. //两个列表取出来比较发现vlink_1和 vlink_2是递增,$i是从0开始。所以第一次就是0+1 第二次就是1+1=2
  129. $i2= $i+2;
  130. $linkAttr3=str_replace("数字",$i2,$linkAttr2);
  131. $link = $xpath->query($linkAttr3);
  132. $dizhi2 = '';
  133. for ($z = 0; $z < $link->length; $z++) {
  134. $text3 = $link->item($z);
  135. $text4 = $text3->nodeValue;
  136. $link4 = $text3->getAttribute($linkAttr);
  137. if (substr($link4,0,4)<>'http'){
  138. $link4 = $web.$link4;
  139. }
  140. $dizhi2 = $dizhi2.$text4.'$'.$link4.'#';
  141. }
  142. $dizhi=$dizhi.substr($dizhi2, 0, strlen($dizhi2)-1).'$$$';
  143. }
  144. $result= $result.'"vod_play_from":"'.substr($yuan, 0, strlen($yuan)-3).'",';
  145. $result= $result.'"vod_play_url":"'.substr($dizhi, 0, strlen($dizhi)-3).'"}]}';
  146. echo $result;
  147. }else{
  148. echo $movietype;
  149. }
  150. function curl_get($url){
  151. $header = array(
  152. 'User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/63.0.3239.132 Safari/537.36',
  153. );
  154. $curl = curl_init();
  155. curl_setopt($curl, CURLOPT_URL, $url);
  156. curl_setopt($curl, CURLOPT_HEADER, 0);
  157. curl_setopt($curl, CURLOPT_TIMEOUT, 30);
  158. curl_setopt($curl, CURLOPT_HTTPHEADER, $header);
  159. curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
  160. curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);
  161. curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, false);
  162. $data = curl_exec($curl);
  163. if (curl_error($curl)) {
  164. return "Error: ".curl_error($curl);
  165. } else {
  166. curl_close($curl);
  167. return $data;
  168. }
  169. }
  170. function getSubstr($str, $leftStr, $rightStr)
  171. {
  172. $left = strpos($str, $leftStr);
  173. $right = strpos($str, $rightStr,$left);
  174. if($left < 0 or $right < $left){
  175. return '';
  176. }
  177. return substr($str, $left + strlen($leftStr),$right-$left-strlen($leftStr));
  178. }
  179. ?>