优化配置加载逻辑;

支持仅设置直播地址的情况;
pull/142/head
于俊 9 months ago
parent ba60fca04f
commit d7082fa582
  1. 38
      app/src/main/java/com/github/tvbox/osc/api/ApiConfig.java
  2. 8
      app/src/main/java/com/github/tvbox/osc/ui/dialog/ApiDialog.java

@ -86,6 +86,7 @@ public class ApiConfig {
liveChannelGroupList = new ArrayList<>();
parseBeanList = new ArrayList<>();
gson = new Gson();
loadDefaultConfig();
}
public static ApiConfig get() {
@ -137,6 +138,7 @@ public class ApiConfig {
return "".getBytes();
}
private String TempKey = null;
private String configUrl(String apiUrl){
String configUrl = "", pk = ";pk;";
apiUrl=apiUrl.replace("file://", "clan://localhost/");
@ -159,14 +161,8 @@ public class ApiConfig {
}
return configUrl;
}
private String TempKey = null;
public void loadConfig(boolean useCache, LoadConfigCallback callback, Activity activity) {
String apiUrl = Hawk.get(HawkConfig.API_URL, "");
if (apiUrl.isEmpty()) {
callback.error("-1");
return;
}
//独立加载直播配置
String liveApiUrl = Hawk.get(HawkConfig.LIVE_API_URL, "");
String liveApiConfigUrl=configUrl(liveApiUrl);
@ -234,6 +230,10 @@ public class ApiConfig {
}
}
if (apiUrl.isEmpty()) {
callback.error("-1");
return;
}
File cache = new File(App.getInstance().getFilesDir().getAbsolutePath() + "/" + MD5.encode(apiUrl));
if (useCache && cache.exists()) {
try {
@ -244,11 +244,7 @@ public class ApiConfig {
th.printStackTrace();
}
}
// String finalApiUrl = apiUrl;
String configUrl=configUrl(apiUrl);
// String configKey = TempKey;
OkGo.<String>get(configUrl)
.headers("User-Agent", userAgent)
.headers("Accept", requestAccept)
@ -546,7 +542,17 @@ public class ApiConfig {
}
OkGoHelper.setDnsList();
LOG.i("echo-api-config-----------load");
//追加的广告拦截
if(infoJson.has("ads")){
for (JsonElement host : infoJson.getAsJsonArray("ads")) {
if(!AdBlocker.hasHost(host.getAsString())){
AdBlocker.addAdHost(host.getAsString());
}
}
}
}
private void loadDefaultConfig() {
String defaultIJKADS="{\"ijk\":[{\"options\":[{\"name\":\"opensles\",\"category\":4,\"value\":\"0\"},{\"name\":\"framedrop\",\"category\":4,\"value\":\"1\"},{\"name\":\"soundtouch\",\"category\":4,\"value\":\"1\"},{\"name\":\"start-on-prepared\",\"category\":4,\"value\":\"1\"},{\"name\":\"http-detect-rangeupport\",\"category\":1,\"value\":\"0\"},{\"name\":\"fflags\",\"category\":1,\"value\":\"fastseek\"},{\"name\":\"skip_loop_filter\",\"category\":2,\"value\":\"48\"},{\"name\":\"reconnect\",\"category\":4,\"value\":\"1\"},{\"name\":\"enable-accurate-seek\",\"category\":4,\"value\":\"0\"},{\"name\":\"mediacodec\",\"category\":4,\"value\":\"0\"},{\"name\":\"mediacodec-all-videos\",\"category\":4,\"value\":\"0\"},{\"name\":\"mediacodec-auto-rotate\",\"category\":4,\"value\":\"0\"},{\"name\":\"mediacodec-handle-resolution-change\",\"category\":4,\"value\":\"0\"},{\"name\":\"mediacodec-hevc\",\"category\":4,\"value\":\"0\"},{\"name\":\"max-buffer-size\",\"category\":4,\"value\":\"15728640\"}],\"group\":\"软解码\"},{\"options\":[{\"name\":\"opensles\",\"category\":4,\"value\":\"0\"},{\"name\":\"framedrop\",\"category\":4,\"value\":\"1\"},{\"name\":\"soundtouch\",\"category\":4,\"value\":\"1\"},{\"name\":\"start-on-prepared\",\"category\":4,\"value\":\"1\"},{\"name\":\"http-detect-rangeupport\",\"category\":1,\"value\":\"0\"},{\"name\":\"fflags\",\"category\":1,\"value\":\"fastseek\"},{\"name\":\"skip_loop_filter\",\"category\":2,\"value\":\"48\"},{\"name\":\"reconnect\",\"category\":4,\"value\":\"1\"},{\"name\":\"enable-accurate-seek\",\"category\":4,\"value\":\"0\"},{\"name\":\"mediacodec\",\"category\":4,\"value\":\"1\"},{\"name\":\"mediacodec-all-videos\",\"category\":4,\"value\":\"1\"},{\"name\":\"mediacodec-auto-rotate\",\"category\":4,\"value\":\"1\"},{\"name\":\"mediacodec-handle-resolution-change\",\"category\":4,\"value\":\"1\"},{\"name\":\"mediacodec-hevc\",\"category\":4,\"value\":\"1\"},{\"name\":\"max-buffer-size\",\"category\":4,\"value\":\"15728640\"}],\"group\":\"硬解码\"}],\"ads\":[\"mimg.0c1q0l.cn\",\"www.googletagmanager.com\",\"www.google-analytics.com\",\"mc.usihnbcq.cn\",\"mg.g1mm3d.cn\",\"mscs.svaeuzh.cn\",\"cnzz.hhttm.top\",\"tp.vinuxhome.com\",\"cnzz.mmstat.com\",\"www.baihuillq.com\",\"s23.cnzz.com\",\"z3.cnzz.com\",\"c.cnzz.com\",\"stj.v1vo.top\",\"z12.cnzz.com\",\"img.mosflower.cn\",\"tips.gamevvip.com\",\"ehwe.yhdtns.com\",\"xdn.cqqc3.com\",\"www.jixunkyy.cn\",\"sp.chemacid.cn\",\"hm.baidu.com\",\"s9.cnzz.com\",\"z6.cnzz.com\",\"um.cavuc.com\",\"mav.mavuz.com\",\"wofwk.aoidf3.com\",\"z5.cnzz.com\",\"xc.hubeijieshikj.cn\",\"tj.tianwenhu.com\",\"xg.gars57.cn\",\"k.jinxiuzhilv.com\",\"cdn.bootcss.com\",\"ppl.xunzhuo123.com\",\"xomk.jiangjunmh.top\",\"img.xunzhuo123.com\",\"z1.cnzz.com\",\"s13.cnzz.com\",\"xg.huataisangao.cn\",\"z7.cnzz.com\",\"xg.huataisangao.cn\",\"z2.cnzz.com\",\"s96.cnzz.com\",\"q11.cnzz.com\",\"thy.dacedsfa.cn\",\"xg.whsbpw.cn\",\"s19.cnzz.com\",\"z8.cnzz.com\",\"s4.cnzz.com\",\"f5w.as12df.top\",\"ae01.alicdn.com\",\"www.92424.cn\",\"k.wudejia.com\",\"vivovip.mmszxc.top\",\"qiu.xixiqiu.com\",\"cdnjs.hnfenxun.com\",\"cms.qdwght.com\"]}";
JsonObject defaultJson=gson.fromJson(defaultIJKADS, JsonObject.class);
// 广告地址
@ -555,21 +561,13 @@ public class ApiConfig {
for (JsonElement host : defaultJson.getAsJsonArray("ads")) {
AdBlocker.addAdHost(host.getAsString());
}
//追加的广告拦截
if(infoJson.has("ads")){
for (JsonElement host : infoJson.getAsJsonArray("ads")) {
if(!AdBlocker.hasHost(host.getAsString())){
AdBlocker.addAdHost(host.getAsString());
}
}
}
}
// IJK解码配置
if(ijkCodes==null){
ijkCodes = new ArrayList<>();
boolean foundOldSelect = false;
String ijkCodec = Hawk.get(HawkConfig.IJK_CODEC, "硬解码");
JsonArray ijkJsonArray = infoJson.has("ijk")?infoJson.get("ijk").getAsJsonArray():defaultJson.get("ijk").getAsJsonArray();
JsonArray ijkJsonArray = defaultJson.get("ijk").getAsJsonArray();
for (JsonElement opt : ijkJsonArray) {
JsonObject obj = (JsonObject) opt;
String name = obj.get("group").getAsString();
@ -596,8 +594,8 @@ public class ApiConfig {
ijkCodes.get(0).selected(true);
}
}
LOG.i("echo-default-config-----------load");
}
private void parseLiveJson(String apiUrl, File f) throws Throwable {
BufferedReader bReader = new BufferedReader(new InputStreamReader(new FileInputStream(f), "UTF-8"));
StringBuilder sb = new StringBuilder();

@ -79,9 +79,9 @@ public class ApiDialog extends BaseDialog {
inputApiLive.setText(newApi);
Hawk.put(HawkConfig.LIVE_API_URL, newApi);
}
listener.onchange(newApi);
dismiss();
}
listener.onchange(newApi);
dismiss();
}
});
findViewById(R.id.inputSubmitLive).setOnClickListener(new View.OnClickListener() {
@ -178,9 +178,9 @@ public class ApiDialog extends BaseDialog {
inputApiLive.setText(newApi);
Hawk.put(HawkConfig.LIVE_API_URL, newApi);
}
listener.onchange(newApi);
dismiss();
}
listener.onchange(newApi);
dismiss();
return true;
}
return false;

Loading…
Cancel
Save