* improved support for matching Season 05/01.avi naming patterns

This commit is contained in:
Reinhard Pointner 2013-04-18 10:03:41 +00:00
parent 444ddd8883
commit 8fa0531f1b
5 changed files with 35 additions and 4 deletions

View File

@ -105,6 +105,11 @@ public class MediaDetection {
}
public static List<SxE> parseEpisodeNumber(File file, boolean strict) {
return new SeasonEpisodeMatcher(SeasonEpisodeMatcher.DEFAULT_SANITY, strict).match(file);
}
public static Date parseDate(Object object) {
return new DateMetric().parse(object);
}

View File

@ -4,7 +4,9 @@ package net.sourceforge.filebot.similarity;
import static java.util.Arrays.*;
import static java.util.Collections.*;
import static java.util.regex.Pattern.*;
import java.io.File;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
@ -20,6 +22,7 @@ public class SeasonEpisodeMatcher {
public static final SeasonEpisodeFilter DEFAULT_SANITY = new SeasonEpisodeFilter(50, 50, 1000);
private SeasonEpisodePattern[] patterns;
private Pattern seasonPattern;
public SeasonEpisodeMatcher(SeasonEpisodeFilter sanity, boolean strict) {
@ -86,6 +89,9 @@ public class SeasonEpisodeMatcher {
if (strict) {
patterns = new SeasonEpisodePattern[] { patterns[0], patterns[1], patterns[2] };
}
// season folder pattern for complementing partial sxe info from filename
seasonPattern = compile("Season\\D?(\\d{1,2})", CASE_INSENSITIVE | UNICODE_CASE);
}
@ -105,6 +111,27 @@ public class SeasonEpisodeMatcher {
return match;
}
}
return null;
}
public List<SxE> match(File file) {
for (SeasonEpisodePattern pattern : patterns) {
List<SxE> match = pattern.match(file.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 null;
}

View File

@ -44,8 +44,7 @@ public class SeasonEpisodeMetric implements SimilarityMetric {
protected Collection<SxE> parse(Object object) {
if (object instanceof File) {
// parse file name
object = ((File) object).getName();
return seasonEpisodeMatcher.match((File) object);
}
return seasonEpisodeMatcher.match(object.toString());

View File

@ -193,7 +193,7 @@ samples
SBS
Screenshot
sd
Season.[0-9]+
Season.?[0-9]+
sed
ShareGo
ShareReactor

View File

@ -45,7 +45,7 @@ def forceMovie(f) {
}
def forceSeries(f) {
parseEpisodeNumber(f) || parseDate(f) || tryQuietly{ ut_label } =~ /^(?i:TV|Kids.Shows)/
parseEpisodeNumber(f) || parseDate(f) || f.path =~ /(?i:Season)\D?[0-9]{1,2}/ || tryQuietly{ ut_label } =~ /^(?i:TV|Kids.Shows)/
}
def forceAnime(f) {