* 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,20 +120,25 @@ public class SeasonEpisodeMatcher {
} }
public List<SxE> match(File file) { public List<SxE> match(File file) {
for (SeasonEpisodePattern pattern : patterns) { // take folder name into consideration as much as file name but put priority on file name
List<SxE> match = pattern.match(file.getName()); List<File> pathTail = listPathTail(file, 2, true);
if (!match.isEmpty()) { for (SeasonEpisodePattern pattern : patterns) {
// current pattern did match for (File tail : pathTail) {
for (int i = 0; i < match.size(); i++) { List<SxE> match = pattern.match(tail.getName());
if (match.get(i).season < 0) {
Matcher sm = seasonPattern.matcher(file.getPath()); if (!match.isEmpty()) {
if (sm.find()) { // current pattern did match
match.set(i, new SxE(Integer.parseInt(sm.group(1)), match.get(i).episode)); 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; return null;

View File

@ -356,15 +356,19 @@ 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()) {
nodes.addFirst(node); if (reverse) {
nodes.addLast(node);
} else {
nodes.addFirst(node);
}
} }
return nodes; return nodes;
@ -372,7 +376,7 @@ public final class FileUtilities {
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());
} }