From f89ee90f72aa7f47266cc33600c037b26d7c0e08 Mon Sep 17 00:00:00 2001 From: Reinhard Pointner Date: Mon, 2 Dec 2013 14:41:15 +0000 Subject: [PATCH] * make auto-selection aware of alias titles --- .../filebot/media/MediaDetection.java | 25 +++++++++++++++++++ .../filebot/ui/rename/EpisodeListMatcher.java | 17 +------------ 2 files changed, 26 insertions(+), 16 deletions(-) diff --git a/source/net/sourceforge/filebot/media/MediaDetection.java b/source/net/sourceforge/filebot/media/MediaDetection.java index 80043af4..29225874 100644 --- a/source/net/sourceforge/filebot/media/MediaDetection.java +++ b/source/net/sourceforge/filebot/media/MediaDetection.java @@ -1019,6 +1019,31 @@ public class MediaDetection { return new Movie(info.getName(), info.getReleased().getYear(), info.getImdbId(), info.getId()); } + public static List getProbableMatches(String query, Collection options) { + // auto-select most probable search result + List probableMatches = new LinkedList(); + + // use name similarity metric + SimilarityMetric metric = new NameSimilarityMetric(); + float threshold = 0.85f; + + // remove trailing braces, e.g. Doctor Who (2005) -> Doctor Who + query = removeTrailingBrackets(query); + + // find probable matches using name similarity >= 0.85 + for (SearchResult option : options) { + float f = 0; + for (String n : option.getEffectiveNames()) { + f = Math.max(f, metric.getSimilarity(query, removeTrailingBrackets(n))); + } + if (f >= threshold) { + probableMatches.add(option); + } + } + + return probableMatches; + } + /* * Heavy-duty name matcher used for matching a file to or more movies (out of a list of ~50k) */ diff --git a/source/net/sourceforge/filebot/ui/rename/EpisodeListMatcher.java b/source/net/sourceforge/filebot/ui/rename/EpisodeListMatcher.java index 4224bed9..341f6379 100644 --- a/source/net/sourceforge/filebot/ui/rename/EpisodeListMatcher.java +++ b/source/net/sourceforge/filebot/ui/rename/EpisodeListMatcher.java @@ -4,7 +4,6 @@ import static java.util.Collections.*; import static net.sourceforge.filebot.MediaTypes.*; import static net.sourceforge.filebot.Settings.*; import static net.sourceforge.filebot.media.MediaDetection.*; -import static net.sourceforge.filebot.similarity.Normalization.*; import static net.sourceforge.tuned.FileUtilities.*; import static net.sourceforge.tuned.StringUtilities.*; import static net.sourceforge.tuned.ui.TunedUtilities.*; @@ -18,7 +17,6 @@ import java.util.Collections; import java.util.Comparator; import java.util.HashMap; import java.util.LinkedHashSet; -import java.util.LinkedList; import java.util.List; import java.util.Locale; import java.util.Map; @@ -42,8 +40,6 @@ import net.sourceforge.filebot.Settings; import net.sourceforge.filebot.similarity.CommonSequenceMatcher; import net.sourceforge.filebot.similarity.EpisodeMatcher; import net.sourceforge.filebot.similarity.Match; -import net.sourceforge.filebot.similarity.NameSimilarityMetric; -import net.sourceforge.filebot.similarity.SimilarityMetric; import net.sourceforge.filebot.ui.SelectDialog; import net.sourceforge.filebot.web.Episode; import net.sourceforge.filebot.web.EpisodeListProvider; @@ -67,18 +63,7 @@ class EpisodeListMatcher implements AutoCompleteMatcher { } // auto-select most probable search result - List probableMatches = new LinkedList(); - - // use name similarity metric - SimilarityMetric metric = new NameSimilarityMetric(); - - // find probable matches using name similarity >= 0.85 - for (SearchResult result : searchResults) { - // remove trailing braces, e.g. Doctor Who (2005) -> Doctor Who - if (metric.getSimilarity(removeTrailingBrackets(query), removeTrailingBrackets(result.getName())) >= 0.85) { - probableMatches.add(result); - } - } + List probableMatches = getProbableMatches(query, searchResults); // auto-select first and only probable search result if (probableMatches.size() == 1) {