pull/123/head
FongMi 3 years ago
parent 1de5668f71
commit b40f860cf4
  1. 17
      app/src/main/java/com/fongmi/android/tv/api/ApiConfig.java
  2. 33
      app/src/main/java/com/fongmi/android/tv/api/LiveConfig.java

@ -6,6 +6,7 @@ import android.text.TextUtils;
import com.fongmi.android.tv.R;
import com.fongmi.android.tv.bean.Config;
import com.fongmi.android.tv.bean.Live;
import com.fongmi.android.tv.bean.Parse;
import com.fongmi.android.tv.bean.Site;
import com.fongmi.android.tv.net.Callback;
@ -34,6 +35,7 @@ public class ApiConfig {
private List<String> flags;
private List<Parse> parses;
private List<Site> sites;
private List<Live> lives;
private JarLoader jLoader;
private PyLoader pLoader;
private Handler handler;
@ -73,6 +75,7 @@ public class ApiConfig {
this.config = Config.vod();
this.ads = new ArrayList<>();
this.sites = new ArrayList<>();
this.lives = new ArrayList<>();
this.flags = new ArrayList<>();
this.parses = new ArrayList<>();
this.jLoader = new JarLoader();
@ -94,6 +97,7 @@ public class ApiConfig {
this.parses.clear();
this.jLoader.clear();
this.pLoader.clear();
LiveConfig.get().remove(lives);
return this;
}
@ -126,7 +130,6 @@ public class ApiConfig {
private void parseConfig(JsonObject object, Callback callback) {
try {
parseJson(object);
LiveConfig.get().parse(object);
jLoader.parseJar("", Json.safeString(object, "spider", ""));
config.json(object.toString()).update();
handler.post(callback::success);
@ -148,6 +151,10 @@ public class ApiConfig {
if (parse.getName().equals(Prefers.getParse())) setParse(parse);
if (!parses.contains(parse)) parses.add(parse);
}
for (Live live : LiveConfig.get().parse(object)) {
if (live.getGroups().isEmpty()) continue;
if (!lives.contains(live)) lives.add(live);
}
if (home == null) setHome(sites.isEmpty() ? new Site() : sites.get(0));
if (parse == null) setParse(parses.isEmpty() ? new Parse() : parses.get(0));
flags.addAll(Json.safeListString(object, "flags"));
@ -196,6 +203,14 @@ public class ApiConfig {
return sites == null ? Collections.emptyList() : sites;
}
public List<Live> getLives() {
return lives == null ? Collections.emptyList() : lives;
}
public void setLives(List<Live> lives) {
this.lives = lives;
}
public List<Parse> getParses() {
return parses == null ? Collections.emptyList() : parses;
}

@ -15,11 +15,13 @@ import com.fongmi.android.tv.net.OKHttp;
import com.fongmi.android.tv.utils.FileUtil;
import com.fongmi.android.tv.utils.Json;
import com.fongmi.android.tv.utils.Prefers;
import com.fongmi.android.tv.utils.Utils;
import com.google.gson.JsonElement;
import com.google.gson.JsonObject;
import com.google.gson.JsonParser;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
public class LiveConfig {
@ -59,7 +61,7 @@ public class LiveConfig {
public LiveConfig clear() {
this.lives.clear();
this.home = null;
this.lives.addAll(ApiConfig.get().getLives());
return this;
}
@ -94,36 +96,37 @@ public class LiveConfig {
private String getText(String url) throws Exception {
if (url.startsWith("file")) return FileUtil.read(url);
else if (url.startsWith("http")) return OKHttp.newCall(url).execute().body().string();
else if (url.endsWith(".txt") || url.endsWith(".m3u")) return getText(Utils.convert(url));
else if (url.length() > 0 && url.length() % 4 == 0) return getText(new String(Base64.decode(url, Base64.DEFAULT)));
else return "";
}
private void addLive(Live live) {
lives.remove(live);
lives.add(live);
}
private void parse(String text) {
Live live = new Live(config.getUrl());
LiveParser.start(live, text);
addLive(live);
lives.remove(live);
lives.add(live);
setHome(live);
}
public void parse(JsonObject object) {
if (!object.has("lives")) return;
for (JsonElement element : Json.safeListElement(object, "lives")) parse(Live.objectFrom(element));
public List<Live> parse(JsonObject object) {
List<Live> items = new ArrayList<>();
if (!object.has("lives")) return Collections.emptyList();
for (JsonElement element : Json.safeListElement(object, "lives")) items.add(parse(Live.objectFrom(element)));
if (home == null) setHome(lives.isEmpty() ? new Live() : lives.get(0));
return items;
}
private void parse(Live live) {
private Live parse(Live live) {
try {
if (live.isProxy()) live = new Live(live.getChannels().get(0).getName(), live.getChannels().get(0).getUrls().get(0).split("ext=")[1]);
if (live.getType() == 0) LiveParser.start(live, getText(live.getUrl()));
if (live.getGroups().size() > 0) addLive(live);
if (live.getGroups().size() > 0 && !lives.contains(live)) lives.add(live);
if (live.getName().equals(config.getHome())) setHome(live);
return live;
} catch (Exception e) {
e.printStackTrace();
return new Live();
}
}
@ -165,6 +168,12 @@ public class LiveConfig {
return home;
}
public void remove(List<Live> lives) {
if (lives.contains(home)) home = null;
this.lives.removeAll(lives);
lives.clear();
}
public void setHome(Live home) {
this.home = home;
this.home.setActivated(true);

Loading…
Cancel
Save