* update patters to make 1x01-1x02 take precendence over 1x01-02 pattern

This commit is contained in:
Reinhard Pointner 2014-03-22 07:46:40 +00:00
parent b365bf48c3
commit 56424aafe1
2 changed files with 22 additions and 5 deletions

View File

@ -26,7 +26,7 @@ public class SeasonEpisodeMatcher {
public SeasonEpisodeMatcher(SeasonEpisodeFilter sanity, boolean strict) { public SeasonEpisodeMatcher(SeasonEpisodeFilter sanity, boolean strict) {
// define variables // define variables
SeasonEpisodePattern Season_00_Episode_00, S00E00, SxE, Dot101, EP0, Num101_TOKEN, E1of2, Num101_SUBSTRING; SeasonEpisodePattern Season_00_Episode_00, S00E00, SxE1_SxE2, SxE, Dot101, EP0, Num101_TOKEN, E1of2, Num101_SUBSTRING;
// match patterns like Season 01 Episode 02, ... // 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})"); 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})");
@ -45,6 +45,20 @@ public class SeasonEpisodeMatcher {
} }
}; };
// match patterns 1x01-1x02, ...
SxE1_SxE2 = new SeasonEpisodePattern(sanity, "(?<!\\p{Alnum})(\\d{1,2}x\\d{2}([-._ ]\\d{1,2}x\\d{2})+)(?!\\p{Digit})") {
@Override
protected Collection<SxE> process(MatchResult match) {
List<SxE> matches = new ArrayList<SxE>(2);
String[] num = match.group(0).split("\\D+");
for (int i = 0; i < num.length; i += 2) {
matches.add(new SxE(num[i], num[i + 1])); // SxE-SxE-SxE
}
return matches;
}
};
// match patterns like 1x01, 1.02, ..., 1x01a, 10x01, 10.02, ... 1x01-02-03-04, 1x01x02x03x04 ... // match patterns like 1x01, 1.02, ..., 1x01a, 10x01, 10.02, ... 1x01-02-03-04, 1x01x02x03x04 ...
SxE = new SeasonEpisodePattern(sanity, "(?<!\\p{Alnum})(\\d{1,2})[xe](((?<=[^._ ])\\d{2,3}(\\D|$))+)") { SxE = new SeasonEpisodePattern(sanity, "(?<!\\p{Alnum})(\\d{1,2})[xe](((?<=[^._ ])\\d{2,3}(\\D|$))+)") {
@ -129,9 +143,9 @@ public class SeasonEpisodeMatcher {
// only use S00E00 and SxE pattern in strict mode // only use S00E00 and SxE pattern in strict mode
if (strict) { if (strict) {
patterns = new SeasonEpisodeParser[] { Season_00_Episode_00, S00E00, SxE, Dot101 }; patterns = new SeasonEpisodeParser[] { Season_00_Episode_00, S00E00, SxE1_SxE2, SxE, Dot101 };
} else { } else {
patterns = new SeasonEpisodeParser[] { Season_00_Episode_00, S00E00, SxE, Dot101, new SeasonEpisodeUnion(EP0, Num101_TOKEN, E1of2), Num101_SUBSTRING }; patterns = new SeasonEpisodeParser[] { Season_00_Episode_00, S00E00, SxE1_SxE2, SxE, Dot101, new SeasonEpisodeUnion(EP0, Num101_TOKEN, E1of2), Num101_SUBSTRING };
} }
// season folder pattern for complementing partial sxe info from filename // season folder pattern for complementing partial sxe info from filename

View File

@ -26,8 +26,11 @@ public class SeasonEpisodeMatcherTest {
assertEquals(asList(new SxE(null, 01), new SxE(1, 01), new SxE(null, 101)), matcher.match("alias.101.Part1")); assertEquals(asList(new SxE(null, 01), new SxE(1, 01), new SxE(null, 101)), matcher.match("alias.101.Part1"));
assertEquals(asList(new SxE(null, 01)), matcher.match("Documentaries.1of6")); assertEquals(asList(new SxE(null, 01)), matcher.match("Documentaries.1of6"));
// multiple values // multi-episode numbers
assertEquals(new SxE(1, 2), matcher.match("Test.42.s01e01.s01e02.300").get(1)); assertEquals("[1x01, 1x02]", matcher.match("Test.42.s01e01.s01e02.300").toString());
assertEquals("[1x01, 1x02]", matcher.match("1x01-02").toString());
assertEquals("[3x11, 3x12, 3x13, 3x14]", matcher.match("03x11-03x12-03x13-03x14").toString());
assertEquals("[9x09, 9x10]", matcher.match("09x09-09x10").toString());
} }
@Test @Test