You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

174 lines
6.7 KiB

8 months ago
  1. package com.github.catvod.spider;
  2. import com.github.catvod.bean.Class;
  3. import com.github.catvod.bean.Result;
  4. import com.github.catvod.bean.Vod;
  5. import com.github.catvod.crawler.Spider;
  6. import com.github.catvod.net.OkHttp;
  7. import com.github.catvod.utils.Util;
  8. import com.google.gson.Gson;
  9. import com.google.gson.JsonArray;
  10. import com.google.gson.JsonElement;
  11. import com.google.gson.JsonObject;
  12. import org.jsoup.Jsoup;
  13. import org.jsoup.nodes.Document;
  14. import org.jsoup.nodes.Element;
  15. import org.jsoup.select.Elements;
  16. import java.net.URLEncoder;
  17. import java.security.MessageDigest;
  18. import java.security.NoSuchAlgorithmException;
  19. import java.util.ArrayList;
  20. import java.util.HashMap;
  21. import java.util.List;
  22. import java.util.regex.Matcher;
  23. import java.util.regex.Pattern;
  24. public class NCat extends Spider {
  25. private static final String siteUrl = "https://www.ncat3.com:51111";
  26. private static final String picUrl = "https://vres.a357899.cn";
  27. private static final String cateUrl = siteUrl + "/show/";
  28. private static final String detailUrl = siteUrl + "/detail/";
  29. private static final String searchUrl = siteUrl + "/search?k=";
  30. private static final String playUrl = siteUrl + "/play/";
  31. private HashMap<String, String> getHeaders() {
  32. HashMap<String, String> headers = new HashMap<>();
  33. headers.put("User-Agent", Util.CHROME);
  34. return headers;
  35. }
  36. @Override
  37. public String homeContent(boolean filter) throws Exception {
  38. List<Vod> list = new ArrayList<>();
  39. List<Class> classes = new ArrayList<>();
  40. String[] typeIdList = {"1", "2", "3", "4", "6"};
  41. String[] typeNameList = {"电影", "连续剧", "动漫", "综艺", "短剧"};
  42. for (int i = 0; i < typeNameList.length; i++) {
  43. classes.add(new Class(typeIdList[i], typeNameList[i]));
  44. }
  45. Document doc = Jsoup.parse(OkHttp.string(siteUrl, getHeaders()));
  46. for (Element element : doc.select("div.module-item")) {
  47. try {
  48. String pic = element.select("img").attr("data-original");
  49. String url = element.select("a").attr("href");
  50. String name = element.select("img").attr("title");
  51. if (!pic.startsWith("http")) {
  52. pic = picUrl + pic;
  53. }
  54. String id = url.split("/")[2];
  55. list.add(new Vod(id, name, pic));
  56. } catch (Exception e) {
  57. }
  58. }
  59. return Result.string(classes, list);
  60. }
  61. @Override
  62. public String categoryContent(String tid, String pg, boolean filter, HashMap<String, String> extend) throws Exception {
  63. List<Vod> list = new ArrayList<>();
  64. String target = cateUrl + tid + "-----3-" + pg + ".html";
  65. Document doc = Jsoup.parse(OkHttp.string(target, getHeaders()));
  66. for (Element element : doc.select("div.module-item")) {
  67. try {
  68. String pic = element.select("img").attr("data-original");
  69. String url = element.select("a").attr("href");
  70. String name = element.select("img").attr("title");
  71. if (!pic.startsWith("http")) {
  72. pic = picUrl + pic;
  73. }
  74. String id = url.split("/")[2];
  75. list.add(new Vod(id, name, pic));
  76. } catch (Exception e) {
  77. }
  78. }
  79. Integer total = (Integer.parseInt(pg) + 1) * 20;
  80. return Result.string(Integer.parseInt(pg), Integer.parseInt(pg) + 1, 20, total, list);
  81. }
  82. @Override
  83. public String detailContent(List<String> ids) throws Exception {
  84. Document doc = Jsoup.parse(OkHttp.string(detailUrl.concat(ids.get(0)), getHeaders()));
  85. String name = doc.select("div.detail-title strong").text();
  86. String pic = doc.select(".detail-pic img").attr("data-original");
  87. String year = doc.select("a.detail-tags-item").get(0).text();
  88. String desc = doc.select("div.detail-desc p").text();
  89. // 播放源
  90. Elements tabs = doc.select("a.source-item span");
  91. Elements list = doc.select("div.episode-list");
  92. String PlayFrom = "";
  93. String PlayUrl = "";
  94. for (int i = 0; i < tabs.size(); i++) {
  95. String tabName = tabs.get(i).text();
  96. if (!"".equals(PlayFrom)) {
  97. PlayFrom = PlayFrom + "$$$" + tabName;
  98. } else {
  99. PlayFrom = PlayFrom + tabName;
  100. }
  101. Elements li = list.get(i).select("a");
  102. String liUrl = "";
  103. for (int i1 = 0; i1 < li.size(); i1++) {
  104. if (!"".equals(liUrl)) {
  105. liUrl = liUrl + "#" + li.get(i1).text() + "$" + li.get(i1).attr("href").replace("/play/", "");
  106. } else {
  107. liUrl = liUrl + li.get(i1).text() + "$" + li.get(i1).attr("href").replace("/play/", "");
  108. }
  109. }
  110. if (!"".equals(PlayUrl)) {
  111. PlayUrl = PlayUrl + "$$$" + liUrl;
  112. } else {
  113. PlayUrl = PlayUrl + liUrl;
  114. }
  115. }
  116. Vod vod = new Vod();
  117. vod.setVodId(ids.get(0));
  118. vod.setVodPic(picUrl + pic);
  119. vod.setVodYear(year);
  120. vod.setVodName(name);
  121. vod.setVodContent(desc);
  122. vod.setVodPlayFrom(PlayFrom);
  123. vod.setVodPlayUrl(PlayUrl);
  124. return Result.string(vod);
  125. }
  126. @Override
  127. public String searchContent(String key, boolean quick) throws Exception {
  128. List<Vod> list = new ArrayList<>();
  129. Document doc = Jsoup.parse(OkHttp.string(searchUrl.concat(URLEncoder.encode(key)).concat(".html"), getHeaders()));
  130. for (Element element : doc.select("a.search-result-item")) {
  131. try {
  132. String pic = element.select("img").attr("data-original");
  133. String url = element.attr("href");
  134. String name = element.select("img").attr("title");
  135. if (!pic.startsWith("http")) {
  136. pic = picUrl + pic;
  137. }
  138. String id = url.split("/")[2];
  139. list.add(new Vod(id, name, pic));
  140. } catch (Exception e) {
  141. }
  142. }
  143. return Result.string(list);
  144. }
  145. @Override
  146. public String playerContent(String flag, String id, List<String> vipFlags) throws Exception {
  147. Document doc = Jsoup.parse(OkHttp.string(playUrl.concat(id), getHeaders()));
  148. String regex = "src: \"(.*?)m3u8\",";
  149. Pattern pattern = Pattern.compile(regex);
  150. Matcher matcher = pattern.matcher(doc.html());
  151. String url = "";
  152. if (matcher.find()) {
  153. url = matcher.group(1);
  154. url = url.replace("\\/", "/") + "m3u8";
  155. }
  156. return Result.get().url(url).header(getHeaders()).string();
  157. }
  158. }