|
|
|
|
@ -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) { |
|
|
|
|
|