Support parse tvg-id

pull/590/head
FongMi 8 months ago
parent eb12c2a227
commit dcec68ae3c
  1. 6
      app/src/main/java/com/fongmi/android/tv/api/EpgParser.java
  2. 2
      app/src/main/java/com/fongmi/android/tv/api/LiveParser.java
  3. 35
      app/src/main/java/com/fongmi/android/tv/bean/Channel.java
  4. 2
      app/src/main/java/com/fongmi/android/tv/model/LiveViewModel.java
  5. 2
      app/src/mobile/java/com/fongmi/android/tv/ui/activity/LiveActivity.java

@ -66,7 +66,7 @@ public class EpgParser {
Map<String, Tv.Channel> mapping = new HashMap<>();
String today = formatDate.format(new Date());
Tv tv = new Persister().read(Tv.class, Path.read(file), false);
for (Group group : live.getGroups()) for (Channel channel : group.getChannel()) exist.add(channel.getTvgName());
for (Group group : live.getGroups()) for (Channel channel : group.getChannel()) exist.add(channel.getTvgId());
for (Tv.Channel channel : tv.getChannel()) mapping.put(channel.getId(), channel);
for (Tv.Programme programme : tv.getProgramme()) {
String key = programme.getChannel();
@ -81,8 +81,8 @@ public class EpgParser {
}
for (Group group : live.getGroups()) {
for (Channel channel : group.getChannel()) {
if (epgMap.containsKey(channel.getTvgName())) channel.setData(epgMap.get(channel.getTvgName()));
if (srcMap.containsKey(channel.getTvgName())) channel.setLogo(srcMap.get(channel.getTvgName()));
if (epgMap.containsKey(channel.getTvgId())) channel.setData(epgMap.get(channel.getTvgId()));
if (srcMap.containsKey(channel.getTvgId())) channel.setLogo(srcMap.get(channel.getTvgId()));
}
}
}

@ -28,6 +28,7 @@ public class LiveParser {
private static final Pattern TVG_LOGO = Pattern.compile(".*tvg-logo=\"(.?|.+?)\".*");
private static final Pattern TVG_NAME = Pattern.compile(".*tvg-name=\"(.?|.+?)\".*");
private static final Pattern TVG_URL = Pattern.compile(".*tvg-url=\"(.?|.+?)\".*");
private static final Pattern TVG_ID = Pattern.compile(".*tvg-id=\"(.?|.+?)\".*");
private static final Pattern URL_TVG = Pattern.compile(".*url-tvg=\"(.?|.+?)\".*");
private static final Pattern GROUP = Pattern.compile(".*group-title=\"(.?|.+?)\".*");
private static final Pattern NAME = Pattern.compile(".*,(.+?)$");
@ -101,6 +102,7 @@ public class LiveParser {
channel.setTvgName(extract(line, TVG_NAME));
channel.setNumber(extract(line, TVG_CHNO));
channel.setLogo(extract(line, TVG_LOGO));
channel.setTvgId(extract(line, TVG_ID));
Catchup unknown = Catchup.create();
unknown.setType(extract(line, CATCHUP));
unknown.setSource(extract(line, CATCHUP_SOURCE));

@ -24,8 +24,6 @@ public class Channel {
@SerializedName("urls")
private List<String> urls;
@SerializedName("tvgName")
private String tvgName;
@SerializedName("number")
private String number;
@SerializedName("logo")
@ -44,6 +42,10 @@ public class Channel {
private String origin;
@SerializedName("referer")
private String referer;
@SerializedName("tvgId")
private String tvgId;
@SerializedName("tvgName")
private String tvgName;
@SerializedName("catchup")
private Catchup catchup;
@SerializedName("header")
@ -89,14 +91,6 @@ public class Channel {
this.name = name;
}
public String getTvgName() {
return TextUtils.isEmpty(tvgName) ? getName() : tvgName;
}
public void setTvgName(String tvgName) {
this.tvgName = tvgName;
}
public List<String> getUrls() {
return urls = urls == null ? new ArrayList<>() : urls;
}
@ -177,6 +171,22 @@ public class Channel {
this.referer = referer;
}
public String getTvgId() {
return TextUtils.isEmpty(tvgId) ? getTvgName() : tvgId;
}
public void setTvgId(String tvgId) {
this.tvgId = tvgId;
}
public String getTvgName() {
return TextUtils.isEmpty(tvgName) ? getName() : tvgName;
}
public void setTvgName(String tvgName) {
this.tvgName = tvgName;
}
public Catchup getCatchup() {
return catchup == null ? new Catchup() : catchup;
}
@ -327,8 +337,8 @@ public class Channel {
if (!live.getOrigin().isEmpty() && getOrigin().isEmpty()) setOrigin(live.getOrigin());
if (!live.getCatchup().isEmpty() && getCatchup().isEmpty()) setCatchup(live.getCatchup());
if (!live.getReferer().isEmpty() && getReferer().isEmpty()) setReferer(live.getReferer());
if (live.getEpg().contains("{") && !getEpg().startsWith("http")) setEpg(live.getEpgApi().replace("{name}", getTvgName()).replace("{epg}", getEpg()));
if (live.getLogo().contains("{") && !getLogo().startsWith("http")) setLogo(live.getLogo().replace("{name}", getTvgName()).replace("{logo}", getLogo()));
if (live.getEpg().contains("{") && !getEpg().startsWith("http")) setEpg(live.getEpgApi().replace("{id}", getTvgId()).replace("{name}", getTvgName()).replace("{epg}", getEpg()));
if (live.getLogo().contains("{") && !getLogo().startsWith("http")) setLogo(live.getLogo().replace("{id}", getTvgId()).replace("{name}", getTvgName()).replace("{logo}", getLogo()));
}
public void setLine(String line) {
@ -353,6 +363,7 @@ public class Channel {
setFormat(item.getFormat());
setParse(item.getParse());
setClick(item.getClick());
setTvgId(item.getTvgId());
setLogo(item.getLogo());
setName(item.getName());
setUrls(item.getUrls());

@ -77,7 +77,7 @@ public class LiveViewModel extends ViewModel {
String date = formatDate.format(new Date());
String url = item.getEpg().replace("{date}", date);
execute(EPG, () -> {
if (url.startsWith("http") && !item.getData().equal(date)) item.setData(Epg.objectFrom(OkHttp.string(url), item.getTvgName(), formatTime));
if (url.startsWith("http") && !item.getData().equal(date)) item.setData(Epg.objectFrom(OkHttp.string(url), item.getTvgId(), formatTime));
return item.getData().selected();
});
}

@ -634,7 +634,7 @@ public class LiveActivity extends BaseActivity implements CustomKeyDownLive.List
}
private void setEpg(Epg epg) {
if (mChannel != null && mChannel.getTvgName().equals(epg.getKey())) setEpg();
if (mChannel != null && mChannel.getTvgId().equals(epg.getKey())) setEpg();
}
private void fetch(EpgData item) {

Loading…
Cancel
Save