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

Class Function

app/src/main/java/com/github/catvod/js/Function.java:11–54  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

9import java.lang.reflect.Method;
10
11public class Function {
12
13 private final QuickJSContext ctx;
14 private final Parser parser;
15
16 public Function(QuickJSContext ctx) {
17 this.parser = new Parser();
18 this.ctx = ctx;
19 setProperty();
20 }
21
22 private void setProperty() {
23 for (Method method : getClass().getMethods()) {
24 if (!method.isAnnotationPresent(JSMethod.class)) continue;
25 ctx.getGlobalObject().setProperty(method.getName(), args -> {
26 try {
27 return method.invoke(this, args);
28 } catch (Exception e) {
29 return null;
30 }
31 });
32 }
33 }
34
35 @JSMethod
36 public String pd(String html, String rule, String urlKey) {
37 return parser.parseDomForUrl(html, rule, urlKey);
38 }
39
40 @JSMethod
41 public String pdfh(String html, String rule) {
42 return parser.parseDomForUrl(html, rule, "");
43 }
44
45 @JSMethod
46 public JSArray pdfa(String html, String rule) {
47 return JSUtil.toArray(ctx, parser.parseDomForArray(html, rule));
48 }
49
50 @JSMethod
51 public JSArray pdfl(String html, String rule, String texts, String urls, String urlKey) {
52 return JSUtil.toArray(ctx, parser.parseDomForList(html, rule, texts, urls, urlKey));
53 }
54}

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected