From fae437f780ee31593e03f8128c9f17fd28dbc7de Mon Sep 17 00:00:00 2001 From: Reinhard Pointner Date: Sat, 21 Sep 2013 05:10:27 +0000 Subject: [PATCH] * SxE matching: take folder name into consideration as much as file name but put priority on file name @see http://www.filebot.net/forums/viewtopic.php?f=6&t=954 --- .../similarity/SeasonEpisodeMatcher.java | 26 ++++++++++++------- .../net/sourceforge/tuned/FileUtilities.java | 12 ++++++--- 2 files changed, 24 insertions(+), 14 deletions(-) diff --git a/source/net/sourceforge/filebot/similarity/SeasonEpisodeMatcher.java b/source/net/sourceforge/filebot/similarity/SeasonEpisodeMatcher.java index 42cde733..a7ed4dec 100644 --- a/source/net/sourceforge/filebot/similarity/SeasonEpisodeMatcher.java +++ b/source/net/sourceforge/filebot/similarity/SeasonEpisodeMatcher.java @@ -2,6 +2,7 @@ package net.sourceforge.filebot.similarity; import static java.util.Collections.*; import static java.util.regex.Pattern.*; +import static net.sourceforge.tuned.FileUtilities.*; import java.io.File; import java.util.ArrayList; @@ -119,20 +120,25 @@ public class SeasonEpisodeMatcher { } public List match(File file) { - for (SeasonEpisodePattern pattern : patterns) { - List match = pattern.match(file.getName()); + // take folder name into consideration as much as file name but put priority on file name + List pathTail = listPathTail(file, 2, true); - if (!match.isEmpty()) { - // current pattern did match - for (int i = 0; i < match.size(); i++) { - if (match.get(i).season < 0) { - Matcher sm = seasonPattern.matcher(file.getPath()); - if (sm.find()) { - match.set(i, new SxE(Integer.parseInt(sm.group(1)), match.get(i).episode)); + for (SeasonEpisodePattern pattern : patterns) { + for (File tail : pathTail) { + List match = pattern.match(tail.getName()); + + if (!match.isEmpty()) { + // current pattern did match + for (int i = 0; i < match.size(); i++) { + if (match.get(i).season < 0) { + Matcher sm = seasonPattern.matcher(file.getPath()); + if (sm.find()) { + match.set(i, new SxE(Integer.parseInt(sm.group(1)), match.get(i).episode)); + } } } + return match; } - return match; } } return null; diff --git a/source/net/sourceforge/tuned/FileUtilities.java b/source/net/sourceforge/tuned/FileUtilities.java index 5818b639..e32264a4 100644 --- a/source/net/sourceforge/tuned/FileUtilities.java +++ b/source/net/sourceforge/tuned/FileUtilities.java @@ -356,15 +356,19 @@ public final class FileUtilities { } public static List listPath(File file) { - return listPathTail(file, Integer.MAX_VALUE); + return listPathTail(file, Integer.MAX_VALUE, false); } - public static List listPathTail(File file, int tailSize) { + public static List listPathTail(File file, int tailSize, boolean reverse) { LinkedList nodes = new LinkedList(); File node = file; for (int i = 0; node != null && i < tailSize && !UNC_PREFIX.equals(node.toString()); i++, node = node.getParentFile()) { - nodes.addFirst(node); + if (reverse) { + nodes.addLast(node); + } else { + nodes.addFirst(node); + } } return nodes; @@ -372,7 +376,7 @@ public final class FileUtilities { public static File getRelativePathTail(File file, int tailSize) { File f = null; - for (File it : listPathTail(file, tailSize)) { + for (File it : listPathTail(file, tailSize, false)) { if (it.getParentFile() != null) { f = new File(f, it.getName()); }