From c0d17622980615c8140dc8bdd4a2b9063d8491f6 Mon Sep 17 00:00:00 2001 From: Reinhard Pointner Date: Sat, 10 Nov 2012 09:02:38 +0000 Subject: [PATCH] * check for double nested structures, e.g. Your.Sisters.Sister.2011.LiMiTED.720p.BluRay.x264-AN0NYM0US/ams-yss-720p/ams-yss-720p.mkv --- .../filebot/media/MediaDetection.java | 36 ++++++++++++++----- 1 file changed, 28 insertions(+), 8 deletions(-) diff --git a/source/net/sourceforge/filebot/media/MediaDetection.java b/source/net/sourceforge/filebot/media/MediaDetection.java index 8607d516..0b50b1d4 100644 --- a/source/net/sourceforge/filebot/media/MediaDetection.java +++ b/source/net/sourceforge/filebot/media/MediaDetection.java @@ -407,7 +407,8 @@ public class MediaDetection { } // search by file name or folder name - List terms = new ArrayList(); + Collection terms = new LinkedHashSet(); + // 1. term: try to match movie pattern 'name (year)' or use filename as is terms.add(reduceMovieName(getName(movieFile))); @@ -494,10 +495,17 @@ public class MediaDetection { } - public static File guessMovieFolder(File movieFile) throws IOException { + public static File guessMovieFolder(File movieFile) throws Exception { // special case for folder mode if (movieFile.isDirectory()) { - return movieFile; + File f = movieFile; + + // check for double nested structures + if (matchMovieFile(f.getParentFile()) != null && matchMovieFile(f) == null) { + return f.getParentFile(); + } else { + return f; + } } // first meaningful parent folder (max 2 levels deep) @@ -505,12 +513,24 @@ public class MediaDetection { for (int i = 0; f != null && i < 2; f = f.getParentFile(), i++) { String term = stripReleaseInfo(f.getName()); if (term.length() > 0) { - return f; + // check for double nested structures + if (matchMovieFile(f.getParentFile()) != null && matchMovieFile(f) == null) { + return f.getParentFile(); + } else { + return f; + } } } + return null; } + + private static Movie matchMovieFile(File file) throws Exception { + List matches = file != null ? matchMovieName(singleton(file.getName()), false, 0) : null; + return matches != null && matches.size() > 0 ? matches.get(0) : null; + } + private static List> movieIndex; @@ -533,7 +553,7 @@ public class MediaDetection { } - public static List matchMovieName(final List files, boolean strict, int maxStartIndex) throws Exception { + public static List matchMovieName(final Collection files, boolean strict, int maxStartIndex) throws Exception { // cross-reference file / folder name with movie list final HighPerformanceMatcher nameMatcher = new HighPerformanceMatcher(maxStartIndex); final Map matchMap = new HashMap(); @@ -570,7 +590,7 @@ public class MediaDetection { } - public static List matchMovieFromStringWithoutSpacing(List names, boolean strict) throws IOException { + public static List matchMovieFromStringWithoutSpacing(Collection names, boolean strict) throws IOException { Pattern spacing = Pattern.compile("[\\p{Punct}\\p{Space}]+"); List terms = new ArrayList(names.size()); @@ -605,7 +625,7 @@ public class MediaDetection { } - private static Collection queryMovieByFileName(List files, MovieIdentificationService queryLookupService, Locale locale) throws Exception { + private static Collection queryMovieByFileName(Collection files, MovieIdentificationService queryLookupService, Locale locale) throws Exception { // remove blacklisted terms Set querySet = new LinkedHashSet(); querySet.addAll(stripReleaseInfo(files, true)); @@ -654,7 +674,7 @@ public class MediaDetection { List nfoFiles = new ArrayList(); if (file.isDirectory()) { nfoFiles.addAll(filter(listFiles(singleton(file), 10, false), NFO_FILES)); - } else { + } else if (file.getParentFile().isDirectory()) { addAll(nfoFiles, file.getParentFile().listFiles(NFO_FILES)); }