* 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
This commit is contained in:
Reinhard Pointner 2013-09-21 05:10:27 +00:00
parent db11b488c5
commit fae437f780
2 changed files with 24 additions and 14 deletions

View File

@ -2,6 +2,7 @@ package net.sourceforge.filebot.similarity;
import static java.util.Collections.*; import static java.util.Collections.*;
import static java.util.regex.Pattern.*; import static java.util.regex.Pattern.*;
import static net.sourceforge.tuned.FileUtilities.*;
import java.io.File; import java.io.File;
import java.util.ArrayList; import java.util.ArrayList;
@ -119,8 +120,12 @@ public class SeasonEpisodeMatcher {
} }
public List<SxE> match(File file) { public List<SxE> match(File file) {
// take folder name into consideration as much as file name but put priority on file name
List<File> pathTail = listPathTail(file, 2, true);
for (SeasonEpisodePattern pattern : patterns) { for (SeasonEpisodePattern pattern : patterns) {
List<SxE> match = pattern.match(file.getName()); for (File tail : pathTail) {
List<SxE> match = pattern.match(tail.getName());
if (!match.isEmpty()) { if (!match.isEmpty()) {
// current pattern did match // current pattern did match
@ -135,6 +140,7 @@ public class SeasonEpisodeMatcher {
return match; return match;
} }
} }
}
return null; return null;
} }

View File

@ -356,23 +356,27 @@ public final class FileUtilities {
} }
public static List<File> listPath(File file) { public static List<File> listPath(File file) {
return listPathTail(file, Integer.MAX_VALUE); return listPathTail(file, Integer.MAX_VALUE, false);
} }
public static List<File> listPathTail(File file, int tailSize) { public static List<File> listPathTail(File file, int tailSize, boolean reverse) {
LinkedList<File> nodes = new LinkedList<File>(); LinkedList<File> nodes = new LinkedList<File>();
File node = file; File node = file;
for (int i = 0; node != null && i < tailSize && !UNC_PREFIX.equals(node.toString()); i++, node = node.getParentFile()) { for (int i = 0; node != null && i < tailSize && !UNC_PREFIX.equals(node.toString()); i++, node = node.getParentFile()) {
if (reverse) {
nodes.addLast(node);
} else {
nodes.addFirst(node); nodes.addFirst(node);
} }
}
return nodes; return nodes;
} }
public static File getRelativePathTail(File file, int tailSize) { public static File getRelativePathTail(File file, int tailSize) {
File f = null; File f = null;
for (File it : listPathTail(file, tailSize)) { for (File it : listPathTail(file, tailSize, false)) {
if (it.getParentFile() != null) { if (it.getParentFile() != null) {
f = new File(f, it.getName()); f = new File(f, it.getName());
} }