From 480c16b0f867c7e8509144551faebc971a35ebb1 Mon Sep 17 00:00:00 2001 From: Reinhard Pointner Date: Sat, 8 Jun 2019 04:32:00 +0700 Subject: [PATCH] Add anime-lists parser * https://github.com/ScudLee/anime-lists --- source/net/filebot/web/AnimeLists.java | 36 +++++++++++++++----------- 1 file changed, 21 insertions(+), 15 deletions(-) diff --git a/source/net/filebot/web/AnimeLists.java b/source/net/filebot/web/AnimeLists.java index 8b0bcf24..4e17e309 100644 --- a/source/net/filebot/web/AnimeLists.java +++ b/source/net/filebot/web/AnimeLists.java @@ -3,6 +3,7 @@ package net.filebot.web; import static java.util.Arrays.*; import static java.util.stream.Collectors.*; import static net.filebot.CachedResource.*; +import static net.filebot.Logging.*; import static net.filebot.util.StringUtilities.*; import java.io.ByteArrayInputStream; @@ -31,25 +32,30 @@ public enum AnimeLists { public Optional map(Episode episode, AnimeLists destination) throws Exception { return find(episode.getSeriesInfo().getId()).map(a -> { - Integer s = destination.getSeason(a); - Integer e = destination.getEpisodeNumber(a, episode.getEpisode()); + if (destination == TheTVDB && a.defaulttvdbseason == null) { + // auto-align mode + try { + return WebServices.TheTVDB.getEpisodeList(a.tvdbid, SortOrder.Airdate, Locale.ENGLISH).stream().filter(e -> { + return episode.getEpisode() != null && episode.getEpisode().equals(e.getAbsolute()); + }).findFirst().orElse(null); + } catch (Exception e) { + debug.warning(e::toString); + return null; + } + } else { + // offset mode + Integer s = this == AniDB ? null : a.defaulttvdbseason; + Integer e = episode.getEpisode(); - return episode.derive(s, e); + if (a.episodeoffset != null) { + e = this == AniDB ? e - a.episodeoffset : e + a.episodeoffset; + } + + return episode.derive(s, e); + } }); } - protected Integer getSeason(Entry a) { - return this == AniDB ? null : a.defaulttvdbseason; - } - - protected Integer getEpisodeNumber(Entry a, Integer e) { - if (a.episodeoffset != null) { - return this == AniDB ? e - a.episodeoffset : e + a.episodeoffset; - } - - return e; - } - public Optional map(int id, AnimeLists destination) throws Exception { return find(id).map(destination::getId); }