From 1344332a665cfaec83b5a7f6ca1246808182919e Mon Sep 17 00:00:00 2001 From: Reinhard Pointner Date: Mon, 11 May 2015 14:37:27 +0000 Subject: [PATCH] * implement guessMovie feature --- .../filebot/subtitle/SubtitleUtilities.java | 51 ++++++------------- 1 file changed, 16 insertions(+), 35 deletions(-) diff --git a/source/net/filebot/subtitle/SubtitleUtilities.java b/source/net/filebot/subtitle/SubtitleUtilities.java index fbaccfb8..f0f34744 100644 --- a/source/net/filebot/subtitle/SubtitleUtilities.java +++ b/source/net/filebot/subtitle/SubtitleUtilities.java @@ -65,7 +65,7 @@ public final class SubtitleUtilities { throw new InterruptedException(); // auto-detect query and search for subtitles - Collection guessSet = new LinkedHashSet(); + Collection selection = new LinkedHashSet(); Collection querySet = new TreeSet(String.CASE_INSENSITIVE_ORDER); List files = bySeries.getValue(); @@ -104,19 +104,28 @@ public final class SubtitleUtilities { } } - // try OpenSubtitles guess function if we can't make sense of the files - if (!searchByMovie && !searchBySeries) { + if (searchByMovie || searchBySeries) { + selection.addAll(findProbableSearchResults(service, querySet, searchByMovie, searchBySeries)); + } + + // try OpenSubtitles guess function if we can't make sense of the files using local search + if (selection.isEmpty()) { for (File f : files) { - guessSet.addAll(service.guess(getName(f))); + selection.addAll(service.guess(getName(f))); } } - if (!searchByMovie && !searchBySeries && guessSet.isEmpty()) { + if (selection.isEmpty()) { continue; } // search for subtitles online using the auto-detected or forced query information - Set subtitles = findSubtitles(service, guessSet, querySet, searchByMovie, searchBySeries, languageName); + Set subtitles = new LinkedHashSet(); + + // fetch subtitles for all search results + for (SubtitleSearchResult it : selection) { + subtitles.addAll(service.getSubtitleList(it, languageName)); + } // allow early abort if (Thread.interrupted()) @@ -199,35 +208,7 @@ public final class SubtitleUtilities { return subtitleByVideo; } - public static Set findSubtitles(SubtitleProvider service, Collection guessSet, Collection querySet, boolean searchByMovie, boolean searchBySeries, String languageName) throws Exception { - Set subtitles = new LinkedHashSet(); - - // search for and automatically select movie / show entry - Set resultSet = new LinkedHashSet(); - - // add known results first - resultSet.addAll(guessSet); - - resultSet.addAll(findProbableSearchResults(service, querySet, searchByMovie, searchBySeries, languageName)); - - for (String query : querySet) { - // search and filter by movie/series as required - Stream searchResults = service.search(query).stream().filter((it) -> { - return (searchByMovie && it.isMovie()) || (searchBySeries && it.isSeries()); - }); - - resultSet.addAll(filterProbableSearchResults(query, searchResults::iterator, querySet.size() == 1 ? 4 : 2)); - } - - // fetch subtitles for all search results - for (SubtitleSearchResult it : resultSet) { - subtitles.addAll(service.getSubtitleList(it, languageName)); - } - - return subtitles; - } - - protected static List findProbableSearchResults(SubtitleProvider service, Collection querySet, boolean searchByMovie, boolean searchBySeries, String languageName) throws Exception { + protected static List findProbableSearchResults(SubtitleProvider service, Collection querySet, boolean searchByMovie, boolean searchBySeries) throws Exception { // search for and automatically select movie / show entry List resultSet = new ArrayList();