From 851f4b996f33f8c063c70fbaabf3bb1cf3a93e59 Mon Sep 17 00:00:00 2001 From: Reinhard Pointner Date: Tue, 11 Jun 2019 07:21:28 +0700 Subject: [PATCH] Use /all/ XEM mapping page to reduce network requests --- source/net/filebot/web/XEM.java | 26 ++++++++++++++++++++++---- 1 file changed, 22 insertions(+), 4 deletions(-) diff --git a/source/net/filebot/web/XEM.java b/source/net/filebot/web/XEM.java index 2d7ee62e..19637a5f 100644 --- a/source/net/filebot/web/XEM.java +++ b/source/net/filebot/web/XEM.java @@ -37,11 +37,21 @@ public enum XEM { } public Integer getSeason(Integer s) { - return this == AniDB ? 1 : s; + switch (this) { + case AniDB: + return 1; + default: + return s; + } } public String getSeriesName(Map> n, Integer s) { - return this == AniDB ? n.get(Integer.toString(s)).get(0) : n.get("all").get(0); + switch (this) { + case AniDB: + return s == null ? null : n.get(Integer.toString(s)).get(0); + default: + return n.get("all").get(0); + } } protected final Resource> haveMap = Resource.lazy(this::getHaveMap); @@ -78,7 +88,7 @@ public enum XEM { Integer e = getInteger(mappedNumbers, "episode"); Integer a = getInteger(mappedNumbers, "absolute"); - return episode.derive(mappedSeriesName, mappedSeason, e, a, null); + return episode.derive(mappedSeriesName, destination == AniDB ? null : mappedSeason, e, a, null); }).collect(toList()); if (mappedEpisode.size() == 1) { @@ -90,7 +100,7 @@ public enum XEM { return Optional.empty(); } - public List>> getAll(Integer id) throws Exception { + public List>> getAll(Integer id) throws Exception { Map parameters = new LinkedHashMap<>(2); parameters.put("origin", getOriginName()); parameters.put("id", id); @@ -100,6 +110,14 @@ public enum XEM { } public Map> getSingle(Integer id, Integer season, Integer episode) throws Exception { + return getAll(id).stream().filter(m -> { + return m.entrySet().stream().anyMatch(it -> { + return it.getKey().startsWith(getOriginName()) && Objects.equals(season, getInteger(it.getValue(), "season")) && Objects.equals(episode, getInteger(it.getValue(), "episode")); + }); + }).findFirst().orElse(emptyMap()); + } + + public Map> getSingle2(Integer id, Integer season, Integer episode) throws Exception { Map parameters = new LinkedHashMap<>(4); parameters.put("origin", getOriginName()); parameters.put("id", id);