From 4783803b6b64edf8c0394413930143a599943dc5 Mon Sep 17 00:00:00 2001 From: Taloth Saldono Date: Wed, 15 Jun 2016 20:58:42 +0200 Subject: [PATCH] New: Part One/Two/Three/.. parser support for mini series. --- .../ParserTests/SingleEpisodeParserFixture.cs | 1 + src/NzbDrone.Core/Parser/Parser.cs | 29 +++++++++++++++++-- 2 files changed, 28 insertions(+), 2 deletions(-) diff --git a/src/NzbDrone.Core.Test/ParserTests/SingleEpisodeParserFixture.cs b/src/NzbDrone.Core.Test/ParserTests/SingleEpisodeParserFixture.cs index ada174309..83db4a5e1 100644 --- a/src/NzbDrone.Core.Test/ParserTests/SingleEpisodeParserFixture.cs +++ b/src/NzbDrone.Core.Test/ParserTests/SingleEpisodeParserFixture.cs @@ -121,6 +121,7 @@ namespace NzbDrone.Core.Test.ParserTests [TestCase("Judge Judy 2016 02 25 S20E142", "Judge Judy", 20, 142)] [TestCase("Judge Judy 2016 02 25 S20E143", "Judge Judy", 20, 143)] [TestCase("Red Dwarf - S02 - E06 - Parallel Universe", "Red Dwarf", 2, 6)] + [TestCase("O.J.Simpson.Made.in.America.Part.Two.720p.HDTV.x264-2HD", "O J Simpson Made in America", 1, 2)] //[TestCase("", "", 0, 0)] public void should_parse_single_episode(string postTitle, string title, int seasonNumber, int episodeNumber) { diff --git a/src/NzbDrone.Core/Parser/Parser.cs b/src/NzbDrone.Core/Parser/Parser.cs index a5ffa86cb..9ad8be7a6 100644 --- a/src/NzbDrone.Core/Parser/Parser.cs +++ b/src/NzbDrone.Core/Parser/Parser.cs @@ -82,6 +82,10 @@ namespace NzbDrone.Core.Parser new Regex(@"^(?.+?)(?:\W+(?:(?:Part\W?|(?<!\d+\W+)e)(?<episode>\d{1,2}(?!\d+)))+)", RegexOptions.IgnoreCase | RegexOptions.Compiled), + //Mini-Series, treated as season 1, episodes are labelled as Part One/Two/Three/...Nine, Part.One, Part_One + new Regex(@"^(?<title>.+?)(?:\W+(?:Part[-._ ](?<episode>One|Two|Three|Four|Five|Six|Seven|Eight|Nine)(?>[-._ ])))", + RegexOptions.IgnoreCase | RegexOptions.Compiled), + //Mini-Series, treated as season 1, episodes are labelled as XofY new Regex(@"^(?<title>.+?)(?:\W+(?:(?<episode>(?<!\d+)\d{1,2}(?!\d+))of\d+)+)", RegexOptions.IgnoreCase | RegexOptions.Compiled), @@ -250,6 +254,8 @@ namespace NzbDrone.Core.Parser private static readonly Regex RequestInfoRegex = new Regex(@"\[.+?\]", RegexOptions.Compiled); + private static readonly string[] Numbers = new[] { "zero", "one", "two", "three", "four", "five", "six", "seven", "eight", "nine" }; + public static ParsedEpisodeInfo ParsePath(string path) { var fileInfo = new FileInfo(path); @@ -628,8 +634,8 @@ namespace NzbDrone.Core.Parser //Allows use to return a list of 0 episodes (We can handle that as a full season release) if (episodeCaptures.Any()) { - var first = Convert.ToInt32(episodeCaptures.First().Value); - var last = Convert.ToInt32(episodeCaptures.Last().Value); + var first = ParseNumber(episodeCaptures.First().Value); + var last = ParseNumber(episodeCaptures.Last().Value); if (first > last) { @@ -774,5 +780,24 @@ namespace NzbDrone.Core.Parser return string.Empty; } + + private static int ParseNumber(string value) + { + int number; + + if (int.TryParse(value, out number)) + { + return number; + } + + number = Array.IndexOf(Numbers, value.ToLower()); + + if (number != -1) + { + return number; + } + + throw new FormatException(string.Format("{0} isn't a number", value)); + } } }