* update SxE patterns and sanity metrics

@see http://www.filebot.net/forums/viewtopic.php?f=5&t=1059
This commit is contained in:
Reinhard Pointner 2013-11-02 17:24:11 +00:00
parent a83e7f2286
commit 64b74ac417
3 changed files with 19 additions and 11 deletions

View File

@ -18,7 +18,7 @@ import java.util.regex.Pattern;
public class SeasonEpisodeMatcher { public class SeasonEpisodeMatcher {
public static final SeasonEpisodeFilter DEFAULT_SANITY = new SeasonEpisodeFilter(50, 50, 1000); public static final SeasonEpisodeFilter DEFAULT_SANITY = new SeasonEpisodeFilter(50, 50, 1000, 1970, 2100);
private SeasonEpisodePattern[] patterns; private SeasonEpisodePattern[] patterns;
private Pattern seasonPattern; private Pattern seasonPattern;
@ -30,7 +30,7 @@ public class SeasonEpisodeMatcher {
patterns[0] = 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})"); patterns[0] = 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})");
// match patterns like S01E01, s01e02, ... [s01]_[e02], s01.e02, s01e02a, s2010e01 ... s01e01-02-03-04, [s01]_[e01-02-03-04] ... // match patterns like S01E01, s01e02, ... [s01]_[e02], s01.e02, s01e02a, s2010e01 ... s01e01-02-03-04, [s01]_[e01-02-03-04] ...
patterns[1] = new SeasonEpisodePattern(null, "(?<!\\p{Digit})[Ss](\\d{1,2}|\\d{4})[^\\p{Alnum}]{0,3}[Ee][Pp]?(((?<=[^._ ])[Ee]?[Pp]?\\d{1,3}(\\D|$))+)") { patterns[1] = new SeasonEpisodePattern(null, "(?<!\\p{Digit})[Ss](\\d{1,2}|\\d{4})[^\\p{Alnum}]{0,3}(?i:ep|e|p)(((?<=[^._ ])[Ee]?[Pp]?\\d{1,3}(\\D|$))+)") {
@Override @Override
protected Collection<SxE> process(MatchResult match) { protected Collection<SxE> process(MatchResult match) {
@ -72,12 +72,12 @@ public class SeasonEpisodeMatcher {
}; };
// match patterns like ep1, ep.1, ... // match patterns like ep1, ep.1, ...
patterns[4] = new SeasonEpisodePattern(sanity, "(?<!\\p{Alnum})(?i:e|ep|episode)[^\\p{Alnum}]{0,3}(\\d{1,3})(?!\\p{Digit})") { patterns[4] = new SeasonEpisodePattern(sanity, "(?<!\\p{Alnum})(\\d{2}|\\d{4})?[^\\p{Alnum}]{0,3}(?i:e|p|ep|episode)[^\\p{Alnum}]{0,3}(\\d{1,3})(?!\\p{Digit})") {
@Override @Override
protected Collection<SxE> process(MatchResult match) { protected Collection<SxE> process(MatchResult match) {
// regex doesn't match season // regex doesn't match season
return singleton(new SxE(null, match.group(1))); return singleton(new SxE(match.group(1), match.group(2)));
} }
}; };
@ -236,15 +236,19 @@ public class SeasonEpisodeMatcher {
public final int seasonLimit; public final int seasonLimit;
public final int seasonEpisodeLimit; public final int seasonEpisodeLimit;
public final int absoluteEpisodeLimit; public final int absoluteEpisodeLimit;
public final int seasonYearBegin;
public final int seasonYearEnd;
public SeasonEpisodeFilter(int seasonLimit, int seasonEpisodeLimit, int absoluteEpisodeLimit) { public SeasonEpisodeFilter(int seasonLimit, int seasonEpisodeLimit, int absoluteEpisodeLimit, int seasonYearBegin, int seasonYearEnd) {
this.seasonLimit = seasonLimit; this.seasonLimit = seasonLimit;
this.seasonEpisodeLimit = seasonEpisodeLimit; this.seasonEpisodeLimit = seasonEpisodeLimit;
this.absoluteEpisodeLimit = absoluteEpisodeLimit; this.absoluteEpisodeLimit = absoluteEpisodeLimit;
this.seasonYearBegin = seasonYearBegin;
this.seasonYearEnd = seasonYearEnd;
} }
boolean filter(SxE sxe) { boolean filter(SxE sxe) {
return (sxe.season >= 0 && sxe.season < seasonLimit && sxe.episode < seasonEpisodeLimit) || (sxe.season < 0 && sxe.episode < absoluteEpisodeLimit); return (sxe.season >= 0 && (sxe.season < seasonLimit || (sxe.season > seasonYearBegin && sxe.season < seasonYearEnd)) && sxe.episode < seasonEpisodeLimit) || (sxe.season < 0 && sxe.episode < absoluteEpisodeLimit);
} }
} }

View File

@ -9,13 +9,16 @@ import org.junit.Test;
public class SeasonEpisodeMatcherTest { public class SeasonEpisodeMatcherTest {
private static SeasonEpisodeMatcher matcher = new SeasonEpisodeMatcher(null, false); private static SeasonEpisodeMatcher matcher = new SeasonEpisodeMatcher(SeasonEpisodeMatcher.DEFAULT_SANITY, false);
@Test @Test
public void patternPrecedence() { public void patternPrecedence() {
// S01E01 pattern has highest precedence // S01E01 pattern has highest precedence
assertEquals(new SxE(1, 3), matcher.match("Test.101.1x02.S01E03").get(0)); assertEquals(new SxE(1, 3), matcher.match("Test.101.1x02.S01E03").get(0));
assertEquals(new SxE(1, 2), matcher.match("[s01]_[e02]").get(0));
assertEquals(new SxE(2013, 10), matcher.match("2013.P10").get(0));
// multiple values // multiple values
assertEquals(new SxE(1, 2), matcher.match("Test.42.s01e01.s01e02.300").get(1)); assertEquals(new SxE(1, 2), matcher.match("Test.42.s01e01.s01e02.300").get(1));
} }
@ -28,7 +31,7 @@ public class SeasonEpisodeMatcherTest {
assertEquals(new SxE(1, 2), matcher.match("Test - 1x01 and 1x02 - Multiple MatchCollection").get(1)); assertEquals(new SxE(1, 2), matcher.match("Test - 1x01 and 1x02 - Multiple MatchCollection").get(1));
// test high values // test high values
assertEquals(new SxE(12, 345), matcher.match("Test - 12x345 - High Values").get(0)); assertEquals(null, matcher.match("Test - 12x345 - High Values"));
// test look-ahead and look-behind // test look-ahead and look-behind
assertEquals(new SxE(1, 3), matcher.match("Test_-_103_[1280x720]").get(0)); assertEquals(new SxE(1, 3), matcher.match("Test_-_103_[1280x720]").get(0));
@ -63,7 +66,7 @@ public class SeasonEpisodeMatcherTest {
assertEquals(new SxE(10, 1), matcher.match("[Test]_1001_High_Values").get(0)); assertEquals(new SxE(10, 1), matcher.match("[Test]_1001_High_Values").get(0));
// test season digits <= 19 // test season digits <= 19
assertEquals(null, matcher.match("The 4400")); assertEquals(new SxE(null, 16), matcher.match("E16").get(0));
// test look-behind // test look-behind
assertEquals(null, matcher.match("720p")); assertEquals(null, matcher.match("720p"));
@ -72,7 +75,7 @@ public class SeasonEpisodeMatcherTest {
assertEquals(asList(new SxE(1, 1), new SxE(UNDEFINED, 101)), matcher.match("Test.101")); assertEquals(asList(new SxE(1, 1), new SxE(UNDEFINED, 101)), matcher.match("Test.101"));
// test 4-digit // test 4-digit
assertEquals(asList(new SxE(23, 21), new SxE(null, 2321)), matcher.match("the.simpsons.2321.hdtv-lol")); assertEquals(asList(new SxE(23, 21)), matcher.match("the.simpsons.2321.hdtv-lol"));
} }
@Test @Test

View File

@ -12,3 +12,4 @@ SuiG7p Suits
tvs.got Game of Thrones tvs.got Game of Thrones
UndG7p Underemployed UndG7p Underemployed
vampire The Vampire Diaries vampire The Vampire Diaries
wsop World Series of Poker