From 9588603206c8c3bc6650416b71f0f635968e0fbb Mon Sep 17 00:00:00 2001 From: Reinhard Pointner Date: Wed, 27 Nov 2013 17:09:19 +0000 Subject: [PATCH] * extra last-resort SxE pattern for space-less naming @see http://www.filebot.net/forums/viewtopic.php?f=4&t=1138 --- .../filebot/media/MediaDetection.java | 10 ++++++++-- .../filebot/similarity/SeasonEpisodeMatcher.java | 16 +++++++++++++--- .../similarity/SeasonEpisodeMatcherTest.java | 7 +++++-- 3 files changed, 26 insertions(+), 7 deletions(-) diff --git a/source/net/sourceforge/filebot/media/MediaDetection.java b/source/net/sourceforge/filebot/media/MediaDetection.java index 070494ae..d8763177 100644 --- a/source/net/sourceforge/filebot/media/MediaDetection.java +++ b/source/net/sourceforge/filebot/media/MediaDetection.java @@ -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; } diff --git a/source/net/sourceforge/filebot/similarity/SeasonEpisodeMatcher.java b/source/net/sourceforge/filebot/similarity/SeasonEpisodeMatcher.java index 1c193038..f17e11a8 100644 --- a/source/net/sourceforge/filebot/similarity/SeasonEpisodeMatcher.java +++ b/source/net/sourceforge/filebot/similarity/SeasonEpisodeMatcher.java @@ -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, "(? 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 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 diff --git a/test/net/sourceforge/filebot/similarity/SeasonEpisodeMatcherTest.java b/test/net/sourceforge/filebot/similarity/SeasonEpisodeMatcherTest.java index 0eff1a11..e9581497 100644 --- a/test/net/sourceforge/filebot/similarity/SeasonEpisodeMatcherTest.java +++ b/test/net/sourceforge/filebot/similarity/SeasonEpisodeMatcherTest.java @@ -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