|
|
|
@ -1,7 +1,5 @@ |
|
|
|
package com.fongmi.android.tv.api.config; |
|
|
|
package com.fongmi.android.tv.api.config; |
|
|
|
|
|
|
|
|
|
|
|
import com.fongmi.android.tv.App; |
|
|
|
|
|
|
|
import com.fongmi.android.tv.R; |
|
|
|
|
|
|
|
import com.fongmi.android.tv.Setting; |
|
|
|
import com.fongmi.android.tv.Setting; |
|
|
|
import com.fongmi.android.tv.api.Decoder; |
|
|
|
import com.fongmi.android.tv.api.Decoder; |
|
|
|
import com.fongmi.android.tv.api.LiveParser; |
|
|
|
import com.fongmi.android.tv.api.LiveParser; |
|
|
|
@ -14,9 +12,8 @@ import com.fongmi.android.tv.bean.Keep; |
|
|
|
import com.fongmi.android.tv.bean.Live; |
|
|
|
import com.fongmi.android.tv.bean.Live; |
|
|
|
import com.fongmi.android.tv.bean.Rule; |
|
|
|
import com.fongmi.android.tv.bean.Rule; |
|
|
|
import com.fongmi.android.tv.db.AppDatabase; |
|
|
|
import com.fongmi.android.tv.db.AppDatabase; |
|
|
|
import com.fongmi.android.tv.event.RefreshEvent; |
|
|
|
import com.fongmi.android.tv.event.ConfigEvent; |
|
|
|
import com.fongmi.android.tv.impl.Callback; |
|
|
|
import com.fongmi.android.tv.impl.Callback; |
|
|
|
import com.fongmi.android.tv.utils.Notify; |
|
|
|
|
|
|
|
import com.fongmi.android.tv.utils.UrlUtil; |
|
|
|
import com.fongmi.android.tv.utils.UrlUtil; |
|
|
|
import com.github.catvod.bean.Header; |
|
|
|
import com.github.catvod.bean.Header; |
|
|
|
import com.github.catvod.bean.Proxy; |
|
|
|
import com.github.catvod.bean.Proxy; |
|
|
|
@ -94,10 +91,10 @@ public class LiveConfig extends BaseConfig { |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
public LiveConfig clear() { |
|
|
|
public LiveConfig clear() { |
|
|
|
|
|
|
|
ads = null; |
|
|
|
home = null; |
|
|
|
home = null; |
|
|
|
lives = null; |
|
|
|
lives = null; |
|
|
|
rules = null; |
|
|
|
rules = null; |
|
|
|
ads = null; |
|
|
|
|
|
|
|
return this; |
|
|
|
return this; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@ -112,10 +109,16 @@ public class LiveConfig extends BaseConfig { |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
@Override |
|
|
|
protected void doLoad(int id, Config config, Callback callback) throws Throwable { |
|
|
|
protected void postEvent() { |
|
|
|
|
|
|
|
super.postEvent(); |
|
|
|
|
|
|
|
ConfigEvent.live(); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
|
|
|
|
protected void load(Config config) throws Throwable { |
|
|
|
String json = Decoder.getJson(UrlUtil.convert(config.getUrl()), TAG); |
|
|
|
String json = Decoder.getJson(UrlUtil.convert(config.getUrl()), TAG); |
|
|
|
if (Json.isObj(json)) checkJson(id, config, callback, Json.parse(json).getAsJsonObject()); |
|
|
|
if (Json.isObj(json)) checkJson(config, Json.parse(json).getAsJsonObject()); |
|
|
|
else parseText(id, config, callback, json); |
|
|
|
else parseText(config, json); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
public void load() { |
|
|
|
public void load() { |
|
|
|
@ -123,43 +126,38 @@ public class LiveConfig extends BaseConfig { |
|
|
|
load(new Callback()); |
|
|
|
load(new Callback()); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
private void parseText(int id, Config config, Callback callback, String text) { |
|
|
|
private void parseText(Config config, String text) { |
|
|
|
Live live = new Live(UrlUtil.getName(config.getUrl()), config.getUrl()).sync(); |
|
|
|
Live live = new Live(UrlUtil.getName(config.getUrl()), config.getUrl()).sync(); |
|
|
|
lives = new ArrayList<>(List.of(live)); |
|
|
|
lives = new ArrayList<>(List.of(live)); |
|
|
|
LiveParser.text(live, text); |
|
|
|
LiveParser.text(live, text); |
|
|
|
setHome(config, live, false); |
|
|
|
setHome(config, live, false); |
|
|
|
if (getTaskId() == id) App.post(callback::success); |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
private void checkJson(int id, Config config, Callback callback, JsonObject object) { |
|
|
|
private void checkJson(Config config, JsonObject object) throws Throwable { |
|
|
|
if (object.has("msg")) { |
|
|
|
if (object.has("msg")) { |
|
|
|
App.post(() -> callback.error(object.get("msg").getAsString())); |
|
|
|
throw new Exception(object.get("msg").getAsString()); |
|
|
|
} else if (object.has("urls")) { |
|
|
|
} else if (object.has("urls")) { |
|
|
|
parseDepot(id, config, callback, object); |
|
|
|
parseDepot(config, object); |
|
|
|
} else { |
|
|
|
} else { |
|
|
|
parseConfig(id, config, callback, object); |
|
|
|
parseConfig(config, object); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
private void parseDepot(int id, Config config, Callback callback, JsonObject object) { |
|
|
|
private void parseDepot(Config config, JsonObject object) throws Throwable { |
|
|
|
List<Depot> items = Depot.arrayFrom(object.getAsJsonArray("urls").toString()); |
|
|
|
List<Depot> items = Depot.arrayFrom(object.getAsJsonArray("urls").toString()); |
|
|
|
List<Config> configs = new ArrayList<>(); |
|
|
|
List<Config> configs = new ArrayList<>(); |
|
|
|
for (Depot item : items) configs.add(Config.find(item, LIVE)); |
|
|
|
for (Depot item : items) configs.add(Config.find(item, LIVE)); |
|
|
|
loadConfig(id, this.config = configs.get(0), callback); |
|
|
|
load(this.config = configs.get(0)); |
|
|
|
Config.delete(config.getUrl()); |
|
|
|
Config.delete(config.getUrl()); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
private void parseConfig(int id, Config config, Callback callback, JsonObject object) { |
|
|
|
private void parseConfig(Config config, JsonObject object) { |
|
|
|
try { |
|
|
|
initList(object); |
|
|
|
initList(object); |
|
|
|
initLive(config, object); |
|
|
|
initLive(config, object); |
|
|
|
} |
|
|
|
if (getTaskId() != id) return; |
|
|
|
|
|
|
|
if (callback != null) App.post(callback::success); |
|
|
|
public void parse(JsonObject object) { |
|
|
|
} catch (Throwable e) { |
|
|
|
parseConfig(getConfig(), object); |
|
|
|
e.printStackTrace(); |
|
|
|
|
|
|
|
if (getTaskId() != id) return; |
|
|
|
|
|
|
|
if (callback != null) App.post(() -> callback.error(Notify.getError(R.string.error_config_parse, e))); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
private void initList(JsonObject object) { |
|
|
|
private void initList(JsonObject object) { |
|
|
|
@ -179,11 +177,6 @@ public class LiveConfig extends BaseConfig { |
|
|
|
setHome(config, getLives().isEmpty() ? new Live() : getLives().stream().filter(item -> item.getName().equals(config.getHome())).findFirst().orElse(getLives().get(0)), false); |
|
|
|
setHome(config, getLives().isEmpty() ? new Live() : getLives().stream().filter(item -> item.getName().equals(config.getHome())).findFirst().orElse(getLives().get(0)), false); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
public void parse(JsonObject object) { |
|
|
|
|
|
|
|
int id = nextTaskId(); |
|
|
|
|
|
|
|
parseConfig(id, getConfig(), null, object); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public void setKeep(Channel channel) { |
|
|
|
public void setKeep(Channel channel) { |
|
|
|
if (home != null && !channel.getGroup().isHidden()) home.keep(channel).save(); |
|
|
|
if (home != null && !channel.getGroup().isHidden()) home.keep(channel).save(); |
|
|
|
} |
|
|
|
} |
|
|
|
@ -272,9 +265,9 @@ public class LiveConfig extends BaseConfig { |
|
|
|
private void setHome(Config config, Live live, boolean save) { |
|
|
|
private void setHome(Config config, Live live, boolean save) { |
|
|
|
home = live; |
|
|
|
home = live; |
|
|
|
home.setActivated(true); |
|
|
|
home.setActivated(true); |
|
|
|
config.home(home.getName()); |
|
|
|
config.setHome(home.getName()); |
|
|
|
if (save) config.save(); |
|
|
|
if (save) config.save(); |
|
|
|
getLives().forEach(item -> item.setActivated(home)); |
|
|
|
getLives().forEach(item -> item.setActivated(home)); |
|
|
|
if (!save && (home.isBoot() || Setting.isBootLive())) RefreshEvent.boot(); |
|
|
|
if (!save && (home.isBoot() || Setting.isBootLive())) ConfigEvent.boot(); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|