From a6e44febfdd7ae06fed9002620d9b3c3b25027bc Mon Sep 17 00:00:00 2001 From: Reinhard Pointner Date: Sat, 28 May 2016 16:05:53 +0800 Subject: [PATCH] can't initialize with known options because misleading NFO files may lead to bad matches --- source/net/filebot/media/MediaDetection.java | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) diff --git a/source/net/filebot/media/MediaDetection.java b/source/net/filebot/media/MediaDetection.java index 05bbf973..1f197f60 100644 --- a/source/net/filebot/media/MediaDetection.java +++ b/source/net/filebot/media/MediaDetection.java @@ -586,21 +586,20 @@ public class MediaDetection { } } - // search by file name or folder name (initialize with known options) - Set terms = options.stream().map(Movie::getNameWithYear).collect(toCollection(LinkedHashSet::new)); + // search by file name or folder name (NOTE: can't initialize with known options because misleading NFO files may lead to bad matches) + List names = new ArrayList(2); // 1. term: try to match movie pattern 'name (year)' or use filename as is - terms.add(getName(movieFile)); + names.add(getName(movieFile)); // 2. term: first meaningful parent folder File movieFolder = guessMovieFolder(movieFile); if (movieFolder != null) { - terms.add(getName(movieFolder)); + names.add(getName(movieFolder)); } // reduce movie names - terms = new LinkedHashSet(reduceMovieNamePermutations(terms)); - + Set terms = reduceMovieNamePermutations(names); List movieNameMatches = matchMovieName(terms, true, 0); // skip further queries if collected matches are already sufficient @@ -753,7 +752,7 @@ public class MediaDetection { return null; } - public static List reduceMovieNamePermutations(Collection terms) throws IOException { + public static Set reduceMovieNamePermutations(Collection terms) throws IOException { LinkedList names = new LinkedList(); for (String it : terms) { @@ -769,7 +768,7 @@ public class MediaDetection { } } - return names; + return new LinkedHashSet(names); } public static File guessMovieFolder(File movieFile) throws Exception {