Add js demo
This commit is contained in:
parent
c5863fc9ef
commit
224c946898
|
|
@ -2,6 +2,6 @@
|
||||||
.idea
|
.idea
|
||||||
*build
|
*build
|
||||||
*.jks
|
*.jks
|
||||||
*i.java
|
*ni.java
|
||||||
*r.java
|
*ar.java
|
||||||
/local.properties
|
/local.properties
|
||||||
|
|
@ -8,7 +8,7 @@ android {
|
||||||
|
|
||||||
defaultConfig {
|
defaultConfig {
|
||||||
applicationId "com.github.catvod.demo"
|
applicationId "com.github.catvod.demo"
|
||||||
minSdk 17
|
minSdk 18
|
||||||
targetSdk 28
|
targetSdk 28
|
||||||
ndk { abiFilters "armeabi-v7a" }
|
ndk { abiFilters "armeabi-v7a" }
|
||||||
buildConfigField("String", "CLIENT_ID", "\"${clientId}\"")
|
buildConfigField("String", "CLIENT_ID", "\"${clientId}\"")
|
||||||
|
|
@ -40,6 +40,7 @@ dependencies {
|
||||||
implementation('com.github.thegrizzlylabs:sardine-android:0.8') { exclude group: 'com.squareup.okhttp3', module: 'okhttp' }
|
implementation('com.github.thegrizzlylabs:sardine-android:0.8') { exclude group: 'com.squareup.okhttp3', module: 'okhttp' }
|
||||||
implementation 'com.googlecode.juniversalchardet:juniversalchardet:1.0.3'
|
implementation 'com.googlecode.juniversalchardet:juniversalchardet:1.0.3'
|
||||||
implementation('com.squareup.okhttp3:okhttp:3.12.13') { force = true }
|
implementation('com.squareup.okhttp3:okhttp:3.12.13') { force = true }
|
||||||
|
implementation 'wang.harlon.quickjs:wrapper-android:0.20.2'
|
||||||
implementation 'com.google.net.cronet:cronet-okhttp:0.1.0'
|
implementation 'com.google.net.cronet:cronet-okhttp:0.1.0'
|
||||||
implementation 'com.google.code.gson:gson:2.8.6'
|
implementation 'com.google.code.gson:gson:2.8.6'
|
||||||
implementation 'cn.wanghaomiao:JsoupXpath:2.5.1'
|
implementation 'cn.wanghaomiao:JsoupXpath:2.5.1'
|
||||||
|
|
|
||||||
|
|
@ -34,15 +34,22 @@ public abstract class Spider {
|
||||||
return "";
|
return "";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public String searchContent(String key, boolean quick, String pg) throws Exception {
|
||||||
|
return "";
|
||||||
|
}
|
||||||
|
|
||||||
public String playerContent(String flag, String id, List<String> vipFlags) throws Exception {
|
public String playerContent(String flag, String id, List<String> vipFlags) throws Exception {
|
||||||
return "";
|
return "";
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean manualVideoCheck() {
|
public boolean manualVideoCheck() throws Exception {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean isVideoFormat(String url) {
|
public boolean isVideoFormat(String url) throws Exception {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void destroy() {
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,14 @@
|
||||||
|
package com.github.catvod.js;
|
||||||
|
|
||||||
|
import com.whl.quickjs.android.QuickJSLoader;
|
||||||
|
|
||||||
|
public class JSLoader {
|
||||||
|
|
||||||
|
public static void init() {
|
||||||
|
try {
|
||||||
|
QuickJSLoader.init();
|
||||||
|
} catch (Throwable ignored) {
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
@ -7,6 +7,7 @@ import android.os.Handler;
|
||||||
import android.os.Looper;
|
import android.os.Looper;
|
||||||
|
|
||||||
import com.github.catvod.crawler.SpiderDebug;
|
import com.github.catvod.crawler.SpiderDebug;
|
||||||
|
import com.github.catvod.js.JSLoader;
|
||||||
|
|
||||||
import java.lang.reflect.Field;
|
import java.lang.reflect.Field;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
@ -39,6 +40,7 @@ public class Init {
|
||||||
public static void init(Context context) {
|
public static void init(Context context) {
|
||||||
get().app = ((Application) context);
|
get().app = ((Application) context);
|
||||||
SpiderDebug.log("自定義爬蟲代碼載入成功!");
|
SpiderDebug.log("自定義爬蟲代碼載入成功!");
|
||||||
|
JSLoader.init();
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void execute(Runnable runnable) {
|
public static void execute(Runnable runnable) {
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,26 @@
|
||||||
|
package com.github.catvod.spider;
|
||||||
|
|
||||||
|
import android.content.Context;
|
||||||
|
|
||||||
|
import com.github.catvod.crawler.Spider;
|
||||||
|
import com.github.catvod.crawler.SpiderDebug;
|
||||||
|
import com.whl.quickjs.wrapper.QuickJSContext;
|
||||||
|
|
||||||
|
public class JSDemo extends Spider {
|
||||||
|
|
||||||
|
private QuickJSContext jsContext;
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void init(Context context, String extend) {
|
||||||
|
jsContext = QuickJSContext.create();
|
||||||
|
jsContext.evaluate("var text = 'Hello QuickJS';");
|
||||||
|
String text = jsContext.getGlobalObject().getString("text");
|
||||||
|
SpiderDebug.log(text);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void destroy() {
|
||||||
|
super.destroy();
|
||||||
|
jsContext.destroy();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -32,12 +32,7 @@ public class XPath extends Spider {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void init(Context context) {
|
|
||||||
super.init(context);
|
|
||||||
}
|
|
||||||
|
|
||||||
public void init(Context context, String extend) {
|
public void init(Context context, String extend) {
|
||||||
super.init(context, extend);
|
|
||||||
this.ext = extend;
|
this.ext = extend;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue