|
|
|
|
@ -10,7 +10,6 @@ import com.fongmi.android.tv.bean.Result; |
|
|
|
|
import com.fongmi.android.tv.net.OKHttp; |
|
|
|
|
import com.fongmi.android.tv.server.Server; |
|
|
|
|
import com.fongmi.android.tv.ui.custom.CustomWebView; |
|
|
|
|
import com.fongmi.android.tv.utils.Json; |
|
|
|
|
import com.google.gson.JsonObject; |
|
|
|
|
import com.google.gson.JsonParser; |
|
|
|
|
|
|
|
|
|
@ -43,16 +42,17 @@ public class ParseTask { |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
public ParseTask run(Result result, boolean useParse) { |
|
|
|
|
setParse(result.getPlayUrl(), useParse); |
|
|
|
|
setParse(result, useParse); |
|
|
|
|
executor.submit(() -> doInBackground(result.getUrl(), result.getFlag())); |
|
|
|
|
return this; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
private void setParse(String url, boolean useParse) { |
|
|
|
|
private void setParse(Result result, boolean useParse) { |
|
|
|
|
String url = result.getPlayUrl(); |
|
|
|
|
if (useParse) parse = ApiConfig.get().getParse(); |
|
|
|
|
else if (url.startsWith("json:")) parse = Parse.get(1, url.substring(5)); |
|
|
|
|
else if (url.startsWith("parse:")) parse = ApiConfig.get().getParse(url.substring(6)); |
|
|
|
|
if (parse == null) parse = Parse.get(0, url); |
|
|
|
|
if (parse == null) parse = Parse.get(0, url, result.getHeader()); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
private void doInBackground(String webUrl, String flag) { |
|
|
|
|
@ -62,7 +62,7 @@ public class ParseTask { |
|
|
|
|
} |
|
|
|
|
switch (parse.getType()) { |
|
|
|
|
case 0: //嗅探
|
|
|
|
|
handler.post(() -> webView.start(parse.getUrl() + webUrl, callback)); |
|
|
|
|
handler.post(() -> webView.start(parse.getUrl() + webUrl, parse.getHeaders(), callback)); |
|
|
|
|
break; |
|
|
|
|
case 1: //Json
|
|
|
|
|
jsonParse(webUrl); |
|
|
|
|
@ -78,7 +78,7 @@ public class ParseTask { |
|
|
|
|
|
|
|
|
|
private void jsonParse(String webUrl) { |
|
|
|
|
try { |
|
|
|
|
Response response = OKHttp.newCall(parse.getUrl() + webUrl, Headers.of(Json.toMap(parse.getHeader()))).execute(); |
|
|
|
|
Response response = OKHttp.newCall(parse.getUrl() + webUrl, Headers.of(parse.getHeaders())).execute(); |
|
|
|
|
JsonObject object = JsonParser.parseString(response.body().string()).getAsJsonObject(); |
|
|
|
|
HashMap<String, String> headers = new HashMap<>(); |
|
|
|
|
for (String key : object.keySet()) if (key.equalsIgnoreCase("user-agent") || key.equalsIgnoreCase("referer")) headers.put(key, object.get(key).getAsString()); |
|
|
|
|
@ -105,7 +105,7 @@ public class ParseTask { |
|
|
|
|
if (result.getUrl().isEmpty()) { |
|
|
|
|
onParseError(); |
|
|
|
|
} else if (result.getParse(0) == 1) { |
|
|
|
|
handler.post(() -> webView.start(Server.proxy(result.getUrl()), callback)); |
|
|
|
|
handler.post(() -> webView.start(Server.proxy(result.getUrl()), result.getHeaders(), callback)); |
|
|
|
|
} else { |
|
|
|
|
onParseSuccess(result.getHeaders(), result.getUrl(), result.getJxFrom()); |
|
|
|
|
} |
|
|
|
|
|