Add old parse system

pull/123/head
FongMi 3 years ago
parent 4f0cc1565f
commit 0f51ce75f3
  1. 12
      app/src/main/java/com/fongmi/android/tv/api/ApiConfig.java
  2. 20
      app/src/main/java/com/fongmi/android/tv/api/JarLoader.java
  3. 19
      app/src/main/java/com/fongmi/android/tv/bean/Parse.java
  4. 4
      app/src/main/java/com/fongmi/android/tv/bean/Result.java
  5. 58
      app/src/main/java/com/fongmi/android/tv/player/parse/ParseJob.java

@ -16,8 +16,12 @@ import com.google.gson.JsonElement;
import com.google.gson.JsonObject;
import com.google.gson.JsonParser;
import org.json.JSONObject;
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
@ -205,6 +209,14 @@ public class ApiConfig {
return jarLoader.proxyInvoke(param);
}
public JSONObject jsonExt(String key, LinkedHashMap<String, String> jxs, String url) throws Exception {
return jarLoader.jsonExt(key, jxs, url);
}
public JSONObject jsonExtMix(String flag, String key, String name, LinkedHashMap<String, HashMap<String, String>> jxs, String url) throws Exception {
return jarLoader.jsonExtMix(flag, key, name, jxs, url);
}
public Site getSite(String key) {
int index = getSites().indexOf(Site.get(key));
return index == -1 ? new Site() : getSites().get(index);

@ -9,8 +9,12 @@ import com.fongmi.android.tv.utils.Utils;
import com.github.catvod.crawler.Spider;
import com.github.catvod.crawler.SpiderNull;
import org.json.JSONObject;
import java.io.File;
import java.lang.reflect.Method;
import java.util.HashMap;
import java.util.LinkedHashMap;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
@ -98,10 +102,22 @@ public class JarLoader {
}
}
public JSONObject jsonExt(String key, LinkedHashMap<String, String> jxs, String url) throws Exception {
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 {
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);
}
public Object[] proxyInvoke(Map<?, ?> params) {
try {
Method proxyFun = methods.get(Utils.getMd5(jar));
if (proxyFun != null) return (Object[]) proxyFun.invoke(null, params);
Method method = methods.get(Utils.getMd5(jar));
if (method != null) return (Object[]) method.invoke(null, params);
else return null;
} catch (Exception e) {
e.printStackTrace();

@ -11,6 +11,7 @@ import com.google.gson.JsonElement;
import com.google.gson.annotations.SerializedName;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
@ -115,6 +116,20 @@ public class Parse {
return getName().equals(it.getName());
}
public String extUrl() {
int index = getUrl().indexOf("?");
if (getExt().isEmpty() || index == -1) return getUrl();
return getUrl().substring(0, index + 1) + "cat_ext=" + Utils.getBase64(getExt().toString()) + "&" + getUrl().substring(index + 1);
}
public HashMap<String, String> mixMap() {
HashMap<String, String> map = new HashMap<>();
map.put("type", getType().toString());
map.put("ext", getExt().toString());
map.put("url", getUrl());
return map;
}
public static class Ext {
@SerializedName("flag")
@ -134,6 +149,10 @@ public class Parse {
this.header = header;
}
public boolean isEmpty() {
return flag == null && header == null;
}
@NonNull
@Override
public String toString() {

@ -135,6 +135,10 @@ public class Result {
return TextUtils.isEmpty(jxFrom) ? "" : jxFrom;
}
public Integer getParse() {
return getParse(0);
}
public Integer getParse(Integer def) {
return parse == null ? def : parse;
}

@ -11,11 +11,13 @@ import com.fongmi.android.tv.impl.ParseCallback;
import com.fongmi.android.tv.net.OkHttp;
import com.fongmi.android.tv.ui.custom.CustomWebView;
import com.fongmi.android.tv.utils.Json;
import com.fongmi.android.tv.utils.Utils;
import com.google.gson.JsonObject;
import com.google.gson.JsonParser;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import java.util.concurrent.CountDownLatch;
@ -81,23 +83,40 @@ public class ParseJob implements ParseCallback {
private void doInBackground(String key, String webUrl, String flag) throws Exception {
switch (parse.getType()) {
case 0: //嗅探
App.post(() -> startWeb(key, parse, webUrl));
startWeb(key, parse, webUrl);
break;
case 1: //Json
jsonParse(parse, webUrl, false);
jsonParse(parse, webUrl, true);
break;
case 4: //God
case 2: //Json擴展
jsonExtend(webUrl);
break;
case 3: //Json聚合
jsonMix(webUrl, flag);
break;
case 4: //上帝模式
godParse(webUrl, flag);
break;
}
}
private void jsonParse(Parse item, String webUrl, boolean strict) throws Exception {
private void jsonParse(Parse item, String webUrl, boolean error) throws Exception {
Response response = OkHttp.newCall(item.getUrl() + webUrl, Headers.of(item.getHeaders())).execute();
JsonObject object = JsonParser.parseString(response.body().string()).getAsJsonObject();
object = object.has("data") ? object.getAsJsonObject("data") : object;
if (strict) checkResult(item, getHeader(object), Json.safeString(object, "url"));
else checkResult(getHeader(object), Json.safeString(object, "url"));
checkResult(getHeader(object), Json.safeString(object, "url"), item.getName(), error);
}
private void jsonExtend(String webUrl) throws Exception {
LinkedHashMap<String, String> jxs = new LinkedHashMap<>();
for (Parse item : ApiConfig.get().getParses()) if (item.getType() == 1) jxs.put(item.getName(), item.extUrl());
checkResult(Result.fromObject(ApiConfig.get().jsonExt(parse.getUrl(), jxs, webUrl)));
}
private void jsonMix(String webUrl, String flag) throws Exception {
LinkedHashMap<String, HashMap<String, String>> jxs = new LinkedHashMap<>();
for (Parse item : ApiConfig.get().getParses()) jxs.put(item.getName(), item.mixMap());
checkResult(Result.fromObject(ApiConfig.get().jsonExtMix(flag + "@", parse.getUrl(), parse.getName(), jxs, webUrl)));
}
private void godParse(String webUrl, String flag) throws Exception {
@ -107,12 +126,12 @@ public class ParseJob implements ParseCallback {
for (Parse item : json) infinite.execute(() -> jsonParse(latch, item, webUrl));
latch.await();
if (webs.isEmpty()) onParseError();
for (Parse item : webs) App.post(() -> startWeb(item, webUrl));
for (Parse item : webs) startWeb(item, webUrl);
}
private void jsonParse(CountDownLatch latch, Parse item, String webUrl) {
try {
jsonParse(item, webUrl, true);
jsonParse(item, webUrl, false);
} catch (Exception e) {
e.printStackTrace();
} finally {
@ -120,14 +139,15 @@ public class ParseJob implements ParseCallback {
}
}
private void checkResult(Map<String, String> headers, String url) {
if (TextUtils.isEmpty(url)) onParseError();
else onParseSuccess(headers, url, "");
private void checkResult(Map<String, String> headers, String url, String from, boolean error) {
if (!TextUtils.isEmpty(url)) onParseSuccess(headers, url, from);
else if (error) onParseError();
}
private void checkResult(Parse item, Map<String, String> headers, String url) throws Exception {
Response response = OkHttp.newCall(url, Headers.of(headers)).execute();
if (response.code() == 200) onParseSuccess(headers, url, item.getName());
private void checkResult(Result result) {
if (result.getUrl().isEmpty()) onParseError();
else if (result.getParse() == 1) startWeb(Utils.checkProxy(result.getUrl()), result.getHeaders());
else onParseSuccess(result.getHeaders(), result.getUrl(), result.getJxFrom());
}
private void startWeb(Parse item, String webUrl) {
@ -135,7 +155,15 @@ public class ParseJob implements ParseCallback {
}
private void startWeb(String key, Parse item, String webUrl) {
webViews.add(CustomWebView.create(App.get()).start(key, item.getName(), item.getUrl() + webUrl, item.getHeaders(), this));
startWeb(key, item.getName(), item.getUrl() + webUrl, item.getHeaders());
}
private void startWeb(String url, Map<String, String> headers) {
startWeb("", "", url, headers);
}
private void startWeb(String key, String form, String url, Map<String, String> headers) {
App.post(() -> webViews.add(CustomWebView.create(App.get()).start(key, form, url, headers, this)));
}
private Map<String, String> getHeader(JsonObject object) {

Loading…
Cancel
Save