|
|
|
|
@ -28,36 +28,45 @@ public class JarLoader { |
|
|
|
|
private String recent; |
|
|
|
|
|
|
|
|
|
public JarLoader() { |
|
|
|
|
this.loaders = new ConcurrentHashMap<>(); |
|
|
|
|
this.methods = new ConcurrentHashMap<>(); |
|
|
|
|
this.spiders = new ConcurrentHashMap<>(); |
|
|
|
|
loaders = new ConcurrentHashMap<>(); |
|
|
|
|
methods = new ConcurrentHashMap<>(); |
|
|
|
|
spiders = new ConcurrentHashMap<>(); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
public void clear() { |
|
|
|
|
for (Spider spider : spiders.values()) spider.destroy(); |
|
|
|
|
this.loaders.clear(); |
|
|
|
|
this.methods.clear(); |
|
|
|
|
this.spiders.clear(); |
|
|
|
|
loaders.clear(); |
|
|
|
|
methods.clear(); |
|
|
|
|
spiders.clear(); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
public void setRecent(String recent) { |
|
|
|
|
this.recent = recent; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
private void load(String key, File file) throws Throwable { |
|
|
|
|
private void load(String key, File file) { |
|
|
|
|
DexClassLoader loader = new DexClassLoader(file.getAbsolutePath(), FileUtil.getCachePath(), null, App.get().getClassLoader()); |
|
|
|
|
Class<?> classInit = loader.loadClass("com.github.catvod.spider.Init"); |
|
|
|
|
Method method = classInit.getMethod("init", Context.class); |
|
|
|
|
method.invoke(classInit, App.get()); |
|
|
|
|
loaders.put(key, loader); |
|
|
|
|
putProxy(key); |
|
|
|
|
setContext(key); |
|
|
|
|
getProxy(key); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
private void putProxy(String key) { |
|
|
|
|
private void setContext(String key) { |
|
|
|
|
try { |
|
|
|
|
Class<?> classProxy = loaders.get(key).loadClass("com.github.catvod.spider.Proxy"); |
|
|
|
|
methods.put(key, classProxy.getMethod("proxy", Map.class)); |
|
|
|
|
} catch (Exception e) { |
|
|
|
|
Class<?> clz = loaders.get(key).loadClass("com.github.catvod.spider.Init"); |
|
|
|
|
Method method = clz.getMethod("init", Context.class); |
|
|
|
|
method.invoke(clz, App.get()); |
|
|
|
|
} catch (Throwable e) { |
|
|
|
|
e.printStackTrace(); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
private void getProxy(String key) { |
|
|
|
|
try { |
|
|
|
|
Class<?> clz = loaders.get(key).loadClass("com.github.catvod.spider.Proxy"); |
|
|
|
|
Method method = clz.getMethod("proxy", Map.class); |
|
|
|
|
methods.put(key, method); |
|
|
|
|
} catch (Throwable e) { |
|
|
|
|
e.printStackTrace(); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
@ -70,7 +79,7 @@ public class JarLoader { |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
public void parseJar(String key, String jar) throws Throwable { |
|
|
|
|
public void parseJar(String key, String jar) { |
|
|
|
|
String[] texts = jar.split(";md5;"); |
|
|
|
|
String md5 = !jar.startsWith("file") && texts.length > 1 ? texts[1].trim() : ""; |
|
|
|
|
jar = texts[0]; |
|
|
|
|
@ -87,6 +96,11 @@ public class JarLoader { |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
public DexClassLoader getLoader(String key, String jar) { |
|
|
|
|
if (!loaders.containsKey(key)) parseJar(key, jar); |
|
|
|
|
return loaders.get(key); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
public Spider getSpider(String key, String api, String ext, String jar) { |
|
|
|
|
try { |
|
|
|
|
String jaKey = Utils.getMd5(jar); |
|
|
|
|
@ -103,13 +117,13 @@ public class JarLoader { |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
public JSONObject jsonExt(String key, LinkedHashMap<String, String> jxs, String url) throws Exception { |
|
|
|
|
public JSONObject jsonExt(String key, LinkedHashMap<String, String> jxs, String url) throws Throwable { |
|
|
|
|
Class<?> clz = loaders.get("").loadClass("com.github.catvod.parser.Json" + key); |
|
|
|
|
Method method = clz.getMethod("parse", LinkedHashMap.class, String.class); |
|
|
|
|
return (JSONObject) method.invoke(null, jxs, url); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
public JSONObject jsonExtMix(String flag, String key, String name, LinkedHashMap<String, HashMap<String, String>> jxs, String url) throws Exception { |
|
|
|
|
public JSONObject jsonExtMix(String flag, String key, String name, LinkedHashMap<String, HashMap<String, String>> jxs, String url) throws Throwable { |
|
|
|
|
Class<?> clz = loaders.get("").loadClass("com.github.catvod.parser.Mix" + key); |
|
|
|
|
Method method = clz.getMethod("parse", LinkedHashMap.class, String.class, String.class, String.class); |
|
|
|
|
return (JSONObject) method.invoke(null, jxs, name, flag, url); |
|
|
|
|
@ -120,7 +134,7 @@ public class JarLoader { |
|
|
|
|
Method method = methods.get(Utils.getMd5(recent)); |
|
|
|
|
if (method != null) return (Object[]) method.invoke(null, params); |
|
|
|
|
else return null; |
|
|
|
|
} catch (Exception e) { |
|
|
|
|
} catch (Throwable e) { |
|
|
|
|
e.printStackTrace(); |
|
|
|
|
return null; |
|
|
|
|
} |
|
|
|
|
|