1
0
Fork 0
mirror of https://github.com/Sonarr/Sonarr synced 2024-12-27 10:17:47 +00:00

Improved the parser to properly handle files without titles, with tests.

This commit is contained in:
Mark McDowall 2012-01-16 19:18:19 -08:00
parent 850880de47
commit 5cea5282bd
2 changed files with 6 additions and 2 deletions

View file

@ -56,6 +56,8 @@ namespace NzbDrone.Core.Test
[TestCase("24-7 Flyers-Rangers- Road to the NHL Winter Classic - S01E01 - Part 1", "24 7 Flyers Rangers Road to the NHL Winter Classic", 1, 1)] [TestCase("24-7 Flyers-Rangers- Road to the NHL Winter Classic - S01E01 - Part 1", "24 7 Flyers Rangers Road to the NHL Winter Classic", 1, 1)]
[TestCase("The.Kennedys.Part.2.DSR.XviD-SYS", "The Kennedys", 1, 2)] [TestCase("The.Kennedys.Part.2.DSR.XviD-SYS", "The Kennedys", 1, 2)]
[TestCase("the-pacific-e07-720p", "The Pacific", 1, 7)] [TestCase("the-pacific-e07-720p", "The Pacific", 1, 7)]
[TestCase("S6E02-Unwrapped-(Playing With Food) - [DarkData]", "", 6, 2)]
[TestCase("S06E03-Unwrapped-(Number Ones Unwrapped) - [DarkData]", "", 6, 3)]
public void ParseTitle_single(string postTitle, string title, int seasonNumber, int episodeNumber) public void ParseTitle_single(string postTitle, string title, int seasonNumber, int episodeNumber)
{ {
var result = Parser.ParseTitle(postTitle); var result = Parser.ParseTitle(postTitle);
@ -159,6 +161,8 @@ namespace NzbDrone.Core.Test
[TestCase("S03E01.S03E02.720p.HDTV.X264-DIMENSION", "", 3, new[] { 1, 2 }, 2)] [TestCase("S03E01.S03E02.720p.HDTV.X264-DIMENSION", "", 3, new[] { 1, 2 }, 2)]
[TestCase("Desparate Housewives - S07E22 - 7x23 - And Lots of Security.. [HDTV].mkv", "Desparate Housewives", 7, new[] { 22, 23 }, 2)] [TestCase("Desparate Housewives - S07E22 - 7x23 - And Lots of Security.. [HDTV].mkv", "Desparate Housewives", 7, new[] { 22, 23 }, 2)]
[TestCase("S07E22 - 7x23 - And Lots of Security.. [HDTV].mkv", "", 7, new[] { 22, 23 }, 2)] [TestCase("S07E22 - 7x23 - And Lots of Security.. [HDTV].mkv", "", 7, new[] { 22, 23 }, 2)]
[TestCase("2x04x05.720p.BluRay-FUTV", "", 2, new[] { 4, 5 }, 2)]
[TestCase("S02E04E05.720p.BluRay-FUTV", "", 2, new[] { 4, 5 }, 2)]
public void TitleParse_multi(string postTitle, string title, int season, int[] episodes, int count) public void TitleParse_multi(string postTitle, string title, int season, int[] episodes, int count)
{ {
var result = Parser.ParseTitle(postTitle); var result = Parser.ParseTitle(postTitle);

View file

@ -35,8 +35,8 @@ namespace NzbDrone.Core
new Regex(@"^(?<title>.+?)(?:\W+(?:(?:Part\W?|(?<!\d+\W+)e)(?<episode>\d{1,2}(?!\d+)))+)\W?(?!\\)", new Regex(@"^(?<title>.+?)(?:\W+(?:(?:Part\W?|(?<!\d+\W+)e)(?<episode>\d{1,2}(?!\d+)))+)\W?(?!\\)",
RegexOptions.IgnoreCase | RegexOptions.Compiled), RegexOptions.IgnoreCase | RegexOptions.Compiled),
//No Title - Single episodes or multi-episode (S01E05E06, S01E05-06, etc) //Episodes without a title, Single (S01E05, 1x05) AND Multi (S01E04E05, 1x04x05)
new Regex(@"^(?:\W?S?(?<season>\d{1,2}(?!\d+))(?:(?:\-|[ex]|\s){2}(?<episode>\d{1,2}(?!\d+)))+\W*)+\W?(?!\\)", new Regex(@"^(?:S?(?<season>\d{1,2}(?!\d+))(?:(?:\-|[ex]|\s)(?<episode>\d{1,2}(?!\d+)))+\W*)+\W?(?!\\)",
RegexOptions.IgnoreCase | RegexOptions.Compiled), RegexOptions.IgnoreCase | RegexOptions.Compiled),
//Episodes over 99 (3-digits or more) //Episodes over 99 (3-digits or more)