MCPcopy Create free account
hub / github.com/FongMi/CatVodSpider / Parser

Class Parser

app/src/main/java/com/github/catvod/js/utils/Parser.java:20–171  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

18import java.util.regex.Pattern;
19
20public class Parser {
21
22 private final Pattern URL = Pattern.compile("url\\((.*?)\\)", Pattern.MULTILINE | Pattern.DOTALL);
23 private final Pattern NO_ADD = Pattern.compile(":eq|:lt|:gt|:first|:last|:not|:even|:odd|:has|:contains|:matches|:empty|^body$|^#");
24 private final Pattern JOIN_URL = Pattern.compile("(url|src|href|-original|-src|-play|-url|style)$|^(data-|url-|src-)", Pattern.MULTILINE | Pattern.CASE_INSENSITIVE);
25 private final Pattern SPEC_URL = Pattern.compile("^(ftp|magnet|thunder|ws):", Pattern.MULTILINE | Pattern.CASE_INSENSITIVE);
26
27 private final Cache cache;
28
29 public Parser() {
30 cache = new Cache();
31 }
32
33 private Info getParseInfo(String rule) {
34 Info info = new Info(rule);
35 if (rule.contains(":eq")) {
36 info.setRule(rule.split(":")[0]);
37 info.setInfo(rule.split(":")[1]);
38 } else if (rule.contains("--")) {
39 String[] rules = rule.split("--");
40 info.setExcludes(rules);
41 info.setRule(rules[0]);
42 }
43 return info;
44 }
45
46 private String parseHikerToJq(String parse, boolean first) {
47 if (!parse.contains("&&")) {
48 String[] split = parse.split(" ");
49 Matcher m = NO_ADD.matcher(split[split.length - 1]);
50 if (!m.find() && first) parse = parse + ":eq(0)";
51 return parse;
52 }
53 String[] parses = parse.split("&&");
54 List<String> items = new ArrayList<>();
55 for (int i = 0; i < parses.length; i++) {
56 String[] split = parses[i].split(" ");
57 if (NO_ADD.matcher(split[split.length - 1]).find()) {
58 items.add(parses[i]);
59 } else {
60 if (!first && i >= parses.length - 1) items.add(parses[i]);
61 else items.add(parses[i] + ":eq(0)");
62 }
63 }
64 return TextUtils.join(" ", items);
65 }
66
67 public String parseDomForUrl(String html, String rule, String addUrl) {
68 Document doc = cache.getPdfh(html);
69 if ("body&&Text".equals(rule) || "Text".equals(rule)) {
70 return doc.text();
71 } else if ("body&&Html".equals(rule) || "Html".equals(rule)) {
72 return doc.html();
73 }
74 String option = "";
75 if (rule.contains("&&")) {
76 String[] rs = rule.split("&&");
77 option = rs[rs.length - 1];

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected