From 6842d4c1c3e0d6a4d92276eabf81b03c4a27ed05 Mon Sep 17 00:00:00 2001 From: Reinhard Pointner Date: Tue, 11 Nov 2014 05:37:23 +0000 Subject: [PATCH] * optimize subtitle lookup --- .../filebot/subtitle/SubtitleUtilities.java | 26 +++++++++++-------- 1 file changed, 15 insertions(+), 11 deletions(-) diff --git a/source/net/filebot/subtitle/SubtitleUtilities.java b/source/net/filebot/subtitle/SubtitleUtilities.java index fd4f3b51..77d2eed8 100644 --- a/source/net/filebot/subtitle/SubtitleUtilities.java +++ b/source/net/filebot/subtitle/SubtitleUtilities.java @@ -65,19 +65,22 @@ public final class SubtitleUtilities { throw new InterruptedException(); // auto-detect query and search for subtitles - boolean searchByMovie = false, searchBySeries = false; Collection querySet = new TreeSet(String.CASE_INSENSITIVE_ORDER); List files = bySeries.getValue(); + // try to guess what type of search might be required (minimize false negatives) + boolean searchBySeries = files.stream().anyMatch(f -> isEpisode(getName(f), false)); + boolean searchByMovie = files.stream().allMatch(f -> !isEpisode(getName(f), true)); + if (forceQuery != null && forceQuery.length() > 0) { querySet.add(forceQuery); - searchByMovie = true; - searchBySeries = true; - } else if (bySeries.getKey().length() > 0) { + searchByMovie = true; // manual query could be a movie + searchBySeries = true; // manual query could be a tv series + } else if (searchBySeries && bySeries.getKey().length() > 0) { // use auto-detected series name as query querySet.add(bySeries.getKey()); - searchBySeries = true; - } else { + } else if (searchBySeries || searchByMovie) { + // remainder is most likely a movie, or a badly named tv series for (File f : files) { List queries = new ArrayList(); @@ -88,13 +91,14 @@ public final class SubtitleUtilities { } } - if (queries.isEmpty()) { - queries.add(stripReleaseInfo(getName(f))); - } - if (queries.size() > 0) { querySet.addAll(queries); - searchByMovie = true; + } else { + // just use heavily stripped file names + String keywords = stripReleaseInfo(getName(f), false); + if (keywords != null && keywords.length() > 0) { + querySet.add(keywords); + } } } }