From 8eff5ec498f4d21e28aa906550f64da9f9f4b388 Mon Sep 17 00:00:00 2001 From: Reinhard Pointner Date: Sat, 23 Apr 2016 02:17:31 +0800 Subject: [PATCH] try to convert absolute numbers to SxE numbers when using {s00e00} binding (as best as possible, SxE numbers may not exactly match TheTVDB, but should in most common cases) --- source/net/filebot/format/MediaBindingBean.java | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/source/net/filebot/format/MediaBindingBean.java b/source/net/filebot/format/MediaBindingBean.java index 7b26db10..d8eebc5f 100644 --- a/source/net/filebot/format/MediaBindingBean.java +++ b/source/net/filebot/format/MediaBindingBean.java @@ -689,22 +689,25 @@ public class MediaBindingBean { List episode = getEpisodes(); for (SearchResult series : WebServices.TheTVDB.search(seriesInfo.getName(), locale)) { - // sanity check search result - if (!series.getEffectiveNames().contains(seriesInfo.getName())) + // sanity check + if (!series.getEffectiveNames().contains(seriesInfo.getName())) { continue; - - List airdateEpisodeList = WebServices.TheTVDB.getEpisodeList(series, SortOrder.Airdate, locale); + } // match by absolute number or airdate if possible, default to absolute number otherwise + List airdateEpisodeList = WebServices.TheTVDB.getEpisodeList(series, SortOrder.Airdate, locale); List airdateEpisode = episode.stream().flatMap(abs -> { return airdateEpisodeList.stream().filter(sxe -> abs.getSpecial() == null && sxe.getSpecial() == null).filter(sxe -> { return abs.getAbsolute() != null && abs.getAbsolute().equals(sxe.getAbsolute()); }); }).collect(toList()); - if (airdateEpisode.size() == episode.size()) { - return airdateEpisode.size() == 1 ? airdateEpisode.get(0) : new MultiEpisode(airdateEpisode); + // sanity check + if (airdateEpisode.size() != episode.size()) { + break; } + + return airdateEpisode.size() == 1 ? airdateEpisode.get(0) : new MultiEpisode(airdateEpisode); } }