New: Part One/Two/Three/.. parser support for mini series.

This commit is contained in:
Taloth Saldono 2016-06-15 20:58:42 +02:00
parent b320a23bf8
commit 4783803b6b
2 changed files with 28 additions and 2 deletions

View File

@ -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)
{

View File

@ -82,6 +82,10 @@ namespace NzbDrone.Core.Parser
new Regex(@"^(?<title>.+?)(?:\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));
}
}
}