|
|
|
|
@ -26,7 +26,7 @@ import java.util.Set; |
|
|
|
|
|
|
|
|
|
public class EpgParser { |
|
|
|
|
|
|
|
|
|
private static final SimpleDateFormat formatFull = new SimpleDateFormat("yyyyMMddHHmmss"); |
|
|
|
|
private static final SimpleDateFormat formatFull = new SimpleDateFormat("yyyyMMddHHmmss Z"); |
|
|
|
|
private static final SimpleDateFormat formatDate = new SimpleDateFormat("yyyy-MM-dd"); |
|
|
|
|
private static final SimpleDateFormat formatTime = new SimpleDateFormat("HH:mm"); |
|
|
|
|
|
|
|
|
|
@ -43,17 +43,17 @@ public class EpgParser { |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
private static boolean shouldDownload(File file) { |
|
|
|
|
return !file.exists() || !equalToday(file); |
|
|
|
|
return !file.exists() || !isToday(file.lastModified()); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
private static boolean equalToday(File file) { |
|
|
|
|
Calendar calendar = Calendar.getInstance(); |
|
|
|
|
calendar.setTimeInMillis(file.lastModified()); |
|
|
|
|
return calendar.get(Calendar.DAY_OF_MONTH) == Calendar.getInstance().get(Calendar.DAY_OF_MONTH); |
|
|
|
|
private static boolean isToday(Date date) { |
|
|
|
|
return isToday(date.getTime()); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
private static Date parseDateTime(String text) throws Exception { |
|
|
|
|
return formatFull.parse(text.substring(0, 14)); |
|
|
|
|
private static boolean isToday(long millis) { |
|
|
|
|
Calendar calendar = Calendar.getInstance(); |
|
|
|
|
calendar.setTimeInMillis(millis); |
|
|
|
|
return calendar.get(Calendar.DAY_OF_MONTH) == Calendar.getInstance().get(Calendar.DAY_OF_MONTH); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
private static void readGzip(Live live, File file) throws Exception { |
|
|
|
|
@ -72,20 +72,17 @@ public class EpgParser { |
|
|
|
|
for (Tv.Channel channel : tv.getChannel()) mapping.put(channel.getId(), channel.getDisplayName()); |
|
|
|
|
for (Tv.Programme programme : tv.getProgramme()) { |
|
|
|
|
String key = mapping.get(programme.getChannel()); |
|
|
|
|
Date startDate = formatFull.parse(programme.getStart()); |
|
|
|
|
Date endDate = formatFull.parse(programme.getStop()); |
|
|
|
|
if (!exist.contains(key)) continue; |
|
|
|
|
if (!programme.equals(today)) continue; |
|
|
|
|
if (!isToday(startDate) && !isToday(endDate)) continue; |
|
|
|
|
if (!epgMap.containsKey(key)) epgMap.put(key, Epg.create(key, today)); |
|
|
|
|
String title = programme.getTitle(); |
|
|
|
|
String start = programme.getStart(); |
|
|
|
|
String stop = programme.getStop(); |
|
|
|
|
Date startDate = parseDateTime(start); |
|
|
|
|
Date endDate = parseDateTime(stop); |
|
|
|
|
EpgData epgData = new EpgData(); |
|
|
|
|
epgData.setTitle(Trans.s2t(programme.getTitle())); |
|
|
|
|
epgData.setStart(formatTime.format(startDate)); |
|
|
|
|
epgData.setEnd(formatTime.format(endDate)); |
|
|
|
|
epgData.setStartTime(startDate.getTime()); |
|
|
|
|
epgData.setEndTime(endDate.getTime()); |
|
|
|
|
epgData.setTitle(Trans.s2t(title)); |
|
|
|
|
epgMap.get(key).getList().add(epgData); |
|
|
|
|
} |
|
|
|
|
for (Group group : live.getGroups()) { |
|
|
|
|
|