* 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:
parent
db11b488c5
commit
fae437f780
|
@ -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<SxE> match(File file) {
|
||||
for (SeasonEpisodePattern pattern : patterns) {
|
||||
List<SxE> match = pattern.match(file.getName());
|
||||
// take folder name into consideration as much as file name but put priority on file name
|
||||
List<File> 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<SxE> 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;
|
||||
|
|
|
@ -356,15 +356,19 @@ public final class FileUtilities {
|
|||
}
|
||||
|
||||
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>();
|
||||
|
||||
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());
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue