* extra last-resort SxE pattern for space-less naming

@see
http://www.filebot.net/forums/viewtopic.php?f=4&t=1138
This commit is contained in:
Reinhard Pointner 2013-11-27 17:09:19 +00:00
parent 2f7df0bf4f
commit 9588603206
3 changed files with 26 additions and 7 deletions

View File

@ -248,11 +248,17 @@ public class MediaDetection {
public static Object getEpisodeIdentifier(CharSequence name, boolean strict) {
// check SxE first
Object match = new SeasonEpisodeMatcher(SeasonEpisodeMatcher.DEFAULT_SANITY, strict).match(name);
Object match = new SeasonEpisodeMatcher(SeasonEpisodeMatcher.DEFAULT_SANITY, true).match(name);
// then Date pattern
if (match == null)
if (match == null) {
match = new DateMatcher().match(name);
}
// check SxE non-strict
if (match == null && !strict) {
match = new SeasonEpisodeMatcher(SeasonEpisodeMatcher.DEFAULT_SANITY, false).match(name);
}
return match;
}

View File

@ -19,13 +19,14 @@ import java.util.regex.Pattern;
public class SeasonEpisodeMatcher {
public static final SeasonEpisodeFilter DEFAULT_SANITY = new SeasonEpisodeFilter(50, 50, 1000, 1970, 2100);
public static final SeasonEpisodeFilter STRICT_SANITY = new SeasonEpisodeFilter(10, 30, -1, -1, -1);
private SeasonEpisodeParser[] patterns;
private Pattern seasonPattern;
public SeasonEpisodeMatcher(SeasonEpisodeFilter sanity, boolean strict) {
// define variables
SeasonEpisodePattern Season_00_Episode_00, S00E00, SxE, Dot101, EP0, Num101;
SeasonEpisodePattern Season_00_Episode_00, S00E00, SxE, Dot101, EP0, Num101_TOKEN, Num101_SUBSTRING;
// match patterns like Season 01 Episode 02, ...
Season_00_Episode_00 = new SeasonEpisodePattern(null, "(?<!\\p{Alnum})(?i:season|series)[^\\p{Alnum}]{0,3}(\\d{1,4})[^\\p{Alnum}]{0,3}(?i:episode)[^\\p{Alnum}]{0,3}(\\d{1,4})[^\\p{Alnum}]{0,3}(?!\\p{Digit})");
@ -83,7 +84,7 @@ public class SeasonEpisodeMatcher {
};
// match patterns like 01, 102, 1003, 10102 (enclosed in separators)
Num101 = new SeasonEpisodePattern(sanity, "(?<!\\p{Alnum})([0-2]?\\d?)(\\d{2})(\\d{2})?(?!\\p{Alnum})") {
Num101_TOKEN = new SeasonEpisodePattern(sanity, "(?<!\\p{Alnum})([0-2]?\\d?)(\\d{2})(\\d{2})?(?!\\p{Alnum})") {
@Override
protected Collection<SxE> process(MatchResult match) {
@ -106,11 +107,20 @@ public class SeasonEpisodeMatcher {
}
};
// match patterns like 101, 102 (and greedily just grab the first)
Num101_SUBSTRING = new SeasonEpisodePattern(STRICT_SANITY, "(\\d{1})(\\d{2}).+") {
@Override
protected Collection<SxE> process(MatchResult match) {
return singleton(new SxE(match.group(1), match.group(2)));
}
};
// only use S00E00 and SxE pattern in strict mode
if (strict) {
patterns = new SeasonEpisodeParser[] { Season_00_Episode_00, S00E00, SxE, Dot101 };
} else {
patterns = new SeasonEpisodeParser[] { Season_00_Episode_00, S00E00, SxE, Dot101, new SeasonEpisodeUnion(EP0, Num101) };
patterns = new SeasonEpisodeParser[] { Season_00_Episode_00, S00E00, SxE, Dot101, new SeasonEpisodeUnion(EP0, Num101_TOKEN), Num101_SUBSTRING };
}
// season folder pattern for complementing partial sxe info from filename

View File

@ -74,14 +74,17 @@ public class SeasonEpisodeMatcherTest {
// test season digits <= 19
assertEquals(new SxE(null, 16), matcher.match("E16").get(0));
// test look-behind
assertEquals(null, matcher.match("720p"));
// test look-ahead
assertEquals(asList(new SxE(7, 20)), matcher.match("720p"));
// test ambiguous match processing
assertEquals(asList(new SxE(1, 1), new SxE(UNDEFINED, 101)), matcher.match("Test.101"));
// test 4-digit
assertEquals(asList(new SxE(23, 21)), matcher.match("the.simpsons.2321.hdtv-lol"));
// test Num101_SUBSTRING
assertEquals(asList(new SxE(4, 07)), matcher.match("TWalkingDead4071080p"));
}
@Test