Fix epg bug

pull/497/head
FongMi 2 years ago
parent 9deb0ed65f
commit a2388be249
  1. 18
      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. 19
      app/src/main/java/com/fongmi/android/tv/bean/Tv.java

@ -30,11 +30,15 @@ public class EpgParser {
private static final SimpleDateFormat formatDate = new SimpleDateFormat("yyyy-MM-dd");
private static final SimpleDateFormat formatTime = new SimpleDateFormat("HH:mm");
public static void start(Live live) throws Exception {
if (!live.getEpg().contains(".xml") || live.getEpg().contains("{")) return;
File file = Path.cache(Uri.parse(live.getEpg()).getLastPathSegment());
if (shouldDownload(file)) Download.create(live.getEpg(), file).start();
readXml(live, Path.read(file));
public static void start(Live live) {
try {
if (!live.getEpg().contains(".xml") || live.getEpg().contains("{")) return;
File file = Path.cache(Uri.parse(live.getEpg()).getLastPathSegment());
if (shouldDownload(file)) Download.create(live.getEpg(), file).start();
readXml(live, Path.read(file));
} catch (Exception e) {
e.printStackTrace();
}
}
private static boolean shouldDownload(File file) {
@ -55,12 +59,14 @@ public class EpgParser {
Set<String> exist = new HashSet<>();
Map<String, Epg> epgMap = new HashMap<>();
Map<String, String> mapping = new HashMap<>();
String today = formatDate.format(new Date());
Tv tv = new Persister().read(Tv.class, xml);
for (Group group : live.getGroups()) for (Channel channel : group.getChannel()) exist.add(channel.getTvgName());
for (Tv.Channel channel : tv.getChannel()) mapping.put(channel.getId(), channel.getDisplayName());
for (Tv.Programme programme : tv.getProgramme()) {
String key = mapping.get(programme.getChannel());
if (!exist.contains(key)) continue;
if (!programme.equals(today)) continue;
String title = programme.getTitle();
String start = programme.getStart();
String stop = programme.getStop();
@ -73,7 +79,7 @@ public class EpgParser {
epgData.setEndTime(endDate.getTime());
epgData.setTitle(Trans.s2t(title));
Epg epg = epgMap.get(key);
if (epg == null) epgMap.put(key, epg = Epg.create(key, formatDate.format(startDate)));
if (epg == null) epgMap.put(key, epg = Epg.create(key, today));
epg.getList().add(epgData);
}
for (Group group : live.getGroups()) {

@ -75,9 +75,9 @@ public class LiveParser {
if (setting.find(line)) {
setting.check(line);
} else if (line.startsWith("#EXTM3U")) {
live.setEpg(extract(line, TVG_URL));
catchup.setType(extract(line, CATCHUP));
catchup.setSource(extract(line, CATCHUP_SOURCE));
if (live.getEpg().isEmpty()) live.setEpg(extract(line, TVG_URL));
} else if (line.startsWith("#EXTINF:")) {
Group group = live.find(Group.create(extract(line, GROUP), live.isPass()));
channel = group.find(Channel.create(extract(line, NAME)));

@ -60,20 +60,31 @@ public class Tv {
@Element(name = "title")
private String title;
@Element(name = "date", required = false)
private String date;
public String getStart() {
return start;
return TextUtils.isEmpty(start) ? "" : start;
}
public String getStop() {
return stop;
return TextUtils.isEmpty(stop) ? "" : stop;
}
public String getChannel() {
return channel;
return TextUtils.isEmpty(channel) ? "" : channel;
}
public String getTitle() {
return title;
return TextUtils.isEmpty(title) ? "" : title;
}
public String getDate() {
return TextUtils.isEmpty(date) ? "" : date;
}
public boolean equals(String date) {
return getDate().isEmpty() || getDate().equals(date);
}
}
}

Loading…
Cancel
Save