Clean parse code

pull/102/head
FongMi 3 years ago
parent 6d96843f50
commit 17f3551b66
  1. 11
      app/src/main/java/com/fongmi/android/tv/bean/Parse.java
  2. 24
      app/src/main/java/com/fongmi/android/tv/player/ParseTask.java

@ -9,6 +9,7 @@ import com.google.gson.Gson;
import com.google.gson.JsonElement; import com.google.gson.JsonElement;
import com.google.gson.annotations.SerializedName; import com.google.gson.annotations.SerializedName;
import java.util.HashMap;
import java.util.List; import java.util.List;
public class Parse { public class Parse {
@ -85,12 +86,20 @@ public class Parse {
return getExt().getHeader(); return getExt().getHeader();
} }
public String mixUrl() { public String extUrl() {
int index = getUrl().indexOf("?"); int index = getUrl().indexOf("?");
if (index == -1) return getUrl(); if (index == -1) return getUrl();
return getUrl().substring(0, index + 1) + "cat_ext=" + Utils.getBase64(getExt().toString()) + "&" + getUrl().substring(index + 1); 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;
}
@Override @Override
public boolean equals(Object obj) { public boolean equals(Object obj) {
if (this == obj) return true; if (this == obj) return true;

@ -82,27 +82,17 @@ public class ParseTask {
private void jsonExtend(String webUrl) { private void jsonExtend(String webUrl) {
LinkedHashMap<String, String> jxs = new LinkedHashMap<>(); LinkedHashMap<String, String> jxs = new LinkedHashMap<>();
for (Parse item : ApiConfig.get().getParses()) if (item.getType() == 1) jxs.put(item.getName(), item.mixUrl()); for (Parse item : ApiConfig.get().getParses()) if (item.getType() == 1) jxs.put(item.getName(), item.extUrl());
Result result = Result.fromObject(ApiConfig.get().jsonExt(parse.getUrl(), jxs, webUrl)); checkResult(Result.fromObject(ApiConfig.get().jsonExt(parse.getUrl(), jxs, webUrl)));
if (result.getUrl().isEmpty()) {
onParseError();
} else if (result.getParse(0) == 1) {
handler.post(() -> Players.get().web().start(result.getUrl(), callback));
} else {
onParseSuccess(result.getHeaders(), result.getUrl(), result.getJxFrom());
}
} }
private void jsonMix(String webUrl, String flag) { private void jsonMix(String webUrl, String flag) {
LinkedHashMap<String, HashMap<String, String>> jxs = new LinkedHashMap<>(); LinkedHashMap<String, HashMap<String, String>> jxs = new LinkedHashMap<>();
for (Parse item : ApiConfig.get().getParses()) { for (Parse item : ApiConfig.get().getParses()) jxs.put(item.getName(), item.mixMap());
HashMap<String, String> map = new HashMap<>(); checkResult(Result.fromObject(ApiConfig.get().jsonExtMix(flag + "@", parse.getUrl(), parse.getName(), jxs, webUrl)));
map.put("type", item.getType().toString()); }
map.put("ext", item.getExt().toString());
map.put("url", item.getUrl()); private void checkResult(Result result) {
jxs.put(item.getName(), map);
}
Result result = Result.fromObject(ApiConfig.get().jsonExtMix(flag + "@", parse.getUrl(), parse.getName(), jxs, webUrl));
if (result.getUrl().isEmpty()) { if (result.getUrl().isEmpty()) {
onParseError(); onParseError();
} else if (result.getParse(0) == 1) { } else if (result.getParse(0) == 1) {

Loading…
Cancel
Save