Optimize epg parse

pull/605/head
jhengazuji 4 months ago
parent d24df9bf65
commit 8741528658
  1. 22
      app/src/main/java/com/fongmi/android/tv/api/EpgParser.java
  2. 4
      catvod/src/main/java/com/github/catvod/utils/Trans.java

@ -75,8 +75,15 @@ public class EpgParser {
private static Map<String, Channel> prepareLiveChannels(Live live) {
return live.getGroups().stream()
.flatMap(group -> group.getChannel().stream())
.flatMap(channel -> Stream.of(channel.getTvgId(), channel.getTvgName(), channel.getName()).filter(key -> !key.isEmpty()).map(key -> new AbstractMap.SimpleEntry<>(key, channel)))
.collect(Collectors.toMap(Map.Entry::getKey, Map.Entry::getValue, (oldValue, newValue) -> oldValue, HashMap::new));
.flatMap(channel -> Stream.of(channel.getTvgId(), channel.getTvgName(), channel.getName())
.filter(key -> !key.isEmpty())
.map(key -> new AbstractMap.SimpleEntry<>(key, channel)))
.collect(Collectors.toMap(
Map.Entry::getKey,
Map.Entry::getValue,
(oldValue, newValue) -> oldValue,
HashMap::new
));
}
private static XmlData parseXmlData(File file) throws Exception {
@ -105,7 +112,16 @@ public class EpgParser {
private static Channel findTargetChannel(String xmlChannelId, Map<String, Channel> liveChannelMap, Map<String, List<Tv.Channel>> xmlChannelIdMap) {
Channel targetChannel = liveChannelMap.get(xmlChannelId);
if (targetChannel != null) return targetChannel;
return Optional.ofNullable(xmlChannelIdMap.get(xmlChannelId)).flatMap(list -> list.stream().findFirst()).flatMap(xmlChannel -> xmlChannel.getDisplayName().stream().map(Tv.DisplayName::getText).filter(name -> !name.isEmpty()).filter(liveChannelMap::containsKey).findFirst().map(liveChannelMap::get)).orElse(null);
List<Tv.Channel> channels = xmlChannelIdMap.get(xmlChannelId);
if (channels == null) return null;
return channels.stream()
.flatMap(xmlChannel -> xmlChannel.getDisplayName().stream())
.map(Tv.DisplayName::getText)
.filter(name -> !name.isEmpty())
.filter(liveChannelMap::containsKey)
.findFirst()
.map(liveChannelMap::get)
.orElse(null);
}
private static void bindResultsToLive(Live live, ProgrammeResult result) {

File diff suppressed because one or more lines are too long
Loading…
Cancel
Save