Support type 1 live

pull/123/head
FongMi 3 years ago
parent 75003387e8
commit f05bfd6d03
  1. 2
      app/src/main/java/com/fongmi/android/tv/api/LiveConfig.java
  2. 19
      app/src/main/java/com/fongmi/android/tv/api/LiveParser.java
  3. 14
      app/src/main/java/com/fongmi/android/tv/bean/Channel.java
  4. 10
      app/src/main/java/com/fongmi/android/tv/bean/Group.java
  5. 2
      app/src/main/java/com/fongmi/android/tv/bean/Live.java
  6. 10
      app/src/main/java/com/fongmi/android/tv/bean/Part.java

@ -93,7 +93,7 @@ public class LiveConfig {
private void parse(String text) {
Live live = new Live(config.getUrl());
LiveParser.start(live, text);
LiveParser.text(live, text);
lives.remove(live);
lives.add(live);
setHome(live);

@ -27,10 +27,11 @@ public class LiveParser {
public static void start(Live live) {
if (live.getGroups().size() > 0) return;
start(live, getText(live.getUrl()));
if (live.getType() == 0) text(live, getText(live.getUrl()));
if (live.getType() == 1) json(live, getText(live.getUrl()));
}
public static void start(Live live, String text) {
public static void text(Live live, String text) {
int number = 0;
if (live.getGroups().size() > 0) return;
if (text.trim().startsWith("#EXTM3U")) m3u(live, text);
@ -38,7 +39,16 @@ public class LiveParser {
for (Group group : live.getGroups()) {
for (Channel channel : group.getChannel()) {
channel.setNumber(++number);
channel.setUa(live.getUa());
channel.live(live);
}
}
}
private static void json(Live live, String text) {
live.getGroups().addAll(Group.arrayFrom(text));
for (Group group : live.getGroups()) {
for (Channel channel : group.getChannel()) {
channel.live(live);
}
}
}
@ -50,7 +60,6 @@ public class LiveParser {
Group group = live.find(Group.create(extract(line, GROUP)));
channel = group.find(Channel.create(extract(line, NAME)));
channel.setLogo(extract(line, LOGO));
channel.epg(live).logo(live);
} else if (line.contains("://")) {
channel.getUrls().add(line);
}
@ -65,7 +74,7 @@ public class LiveParser {
if (live.getGroups().isEmpty()) live.getGroups().add(Group.create(R.string.live_group));
if (split[1].contains("://")) {
Group group = live.getGroups().get(live.getGroups().size() - 1);
group.find(Channel.create(split[0]).epg(live).logo(live)).addUrls(split[1].split("#"));
group.find(Channel.create(split[0])).addUrls(split[1].split("#"));
}
}
}

@ -197,16 +197,10 @@ public class Channel {
return this;
}
public Channel epg(Live live) {
if (live.getEpg().isEmpty() || getEpg().startsWith("http")) return this;
setEpg(live.getEpg().replace("{name}", getName()).replace("{epg}", getEpg()));
return this;
}
public Channel logo(Live live) {
if (live.getLogo().isEmpty() || getLogo().startsWith("http")) return this;
setLogo(live.getLogo().replace("{name}", getName()).replace("{logo}", getLogo()));
return this;
public void live(Live live) {
if (live.getUa().length() > 0 && getUa().isEmpty()) setUa(live.getUa());
if (!getEpg().startsWith("http")) setEpg(live.getEpg().replace("{name}", getName()).replace("{epg}", getEpg()));
if (!getLogo().startsWith("http")) setLogo(live.getLogo().replace("{name}", getName()).replace("{logo}", getLogo()));
}
public String getScheme() {

@ -9,9 +9,13 @@ import androidx.annotation.StringRes;
import com.fongmi.android.tv.R;
import com.fongmi.android.tv.utils.ImgUtil;
import com.fongmi.android.tv.utils.ResUtil;
import com.google.gson.Gson;
import com.google.gson.annotations.SerializedName;
import com.google.gson.reflect.TypeToken;
import java.lang.reflect.Type;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
public class Group {
@ -27,6 +31,12 @@ public class Group {
private int position;
public static List<Group> arrayFrom(String str) {
Type listType = new TypeToken<List<Group>>() {}.getType();
List<Group> items = new Gson().fromJson(str, listType);
return items == null ? Collections.emptyList() : items;
}
public static Group create(String name) {
return new Group(name);
}

@ -81,7 +81,7 @@ public class Live {
return TextUtils.isEmpty(ua) ? "" : ua;
}
public List<Channel> getChannels() {
private List<Channel> getChannels() {
return channels = channels == null ? new ArrayList<>() : channels;
}

@ -8,6 +8,7 @@ import com.google.gson.reflect.TypeToken;
import java.lang.reflect.Type;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
public class Part {
@ -16,12 +17,9 @@ public class Part {
private String t;
private static List<Part> arrayFrom(String str) {
try {
Type listType = new TypeToken<ArrayList<Part>>() {}.getType();
return new Gson().fromJson(str, listType);
} catch (Exception e) {
return new ArrayList<>();
}
Type listType = new TypeToken<List<Part>>() {}.getType();
List<Part> items = new Gson().fromJson(str, listType);
return items == null ? Collections.emptyList() : items;
}
public static List<String> get(String str) {

Loading…
Cancel
Save