From 27f272077dac2f19c155360c434504753b0f4e65 Mon Sep 17 00:00:00 2001 From: Reinhard Pointner Date: Sat, 16 Nov 2013 05:37:41 +0000 Subject: [PATCH] * add some stop-folder logic for movie structures --- .../filebot/media/MediaDetection.java | 12 ++++++++---- .../sourceforge/filebot/media/ReleaseInfo.java | 16 ++++++++++++++++ 2 files changed, 24 insertions(+), 4 deletions(-) diff --git a/source/net/sourceforge/filebot/media/MediaDetection.java b/source/net/sourceforge/filebot/media/MediaDetection.java index 8ccb3aaf..b97d1f80 100644 --- a/source/net/sourceforge/filebot/media/MediaDetection.java +++ b/source/net/sourceforge/filebot/media/MediaDetection.java @@ -701,7 +701,7 @@ public class MediaDetection { File f = movieFile; // check for double nested structures - if (checkMovie(f.getParentFile(), false) != null && checkMovie(f, false) == null) { + if (!isStructureRoot(f.getParentFile()) && checkMovie(f.getParentFile(), false) != null && checkMovie(f, false) == null) { return f.getParentFile(); } else { return f; @@ -711,7 +711,7 @@ public class MediaDetection { // first parent folder that matches a movie (max 3 levels deep) for (boolean strictness : new boolean[] { true, false }) { File f = movieFile.getParentFile(); - for (int i = 0; f != null && i < 3; f = f.getParentFile(), i++) { + for (int i = 0; f != null && i < 3 && !isStructureRoot(f); f = f.getParentFile(), i++) { String term = stripReleaseInfo(f.getName()); if (term.length() > 0 && checkMovie(f, strictness) != null) { return f; @@ -721,7 +721,7 @@ public class MediaDetection { // otherwise try the first potentially meaningful parent folder (max 2 levels deep) File f = movieFile.getParentFile(); - for (int i = 0; f != null && i < 2; f = f.getParentFile(), i++) { + for (int i = 0; f != null && i < 2 && !isStructureRoot(f); f = f.getParentFile(), i++) { String term = stripReleaseInfo(f.getName()); if (term.length() > 0) { // check for double nested structures @@ -733,7 +733,7 @@ public class MediaDetection { } } - if (movieFile.getParentFile() != null && stripReleaseInfo(movieFile.getParentFile().getName()).length() > 0) { + if (movieFile.getParentFile() != null && !isStructureRoot(f.getParentFile()) && stripReleaseInfo(movieFile.getParentFile().getName()).length() > 0) { return movieFile.getParentFile(); } return null; @@ -886,6 +886,10 @@ public class MediaDetection { } } + public static boolean isStructureRoot(File folder) throws IOException { + return releaseInfo.getStructureRootPattern().matcher(folder.getName()).matches(); + } + public static List stripReleaseInfo(Collection names, boolean strict) throws IOException { return releaseInfo.cleanRelease(names, strict); } diff --git a/source/net/sourceforge/filebot/media/ReleaseInfo.java b/source/net/sourceforge/filebot/media/ReleaseInfo.java index f377467b..e5a3ec9f 100644 --- a/source/net/sourceforge/filebot/media/ReleaseInfo.java +++ b/source/net/sourceforge/filebot/media/ReleaseInfo.java @@ -166,6 +166,22 @@ public class ReleaseInfo { return item; } + // cached patterns + private Pattern structureRootFolderPattern; + + public Pattern getStructureRootPattern() throws IOException { + if (structureRootFolderPattern == null) { + List folders = new ArrayList(); + for (String it : queryBlacklistResource.get()) { + if (it.startsWith("^")) { + folders.add(it); + } + } + structureRootFolderPattern = compile(join(folders, "|"), CASE_INSENSITIVE | UNICODE_CASE); + } + return structureRootFolderPattern; + } + public Pattern getLanguageTagPattern(Collection languages) { // [en] return compile("(?<=[-\\[{(])(" + join(quoteAll(languages), "|") + ")(?=\\p{Punct})", CASE_INSENSITIVE | UNICODE_CASE);