From 03aa27c45cd9b482fd82fe744f715ccd236de224 Mon Sep 17 00:00:00 2001 From: "kay.one" Date: Thu, 24 Nov 2011 00:12:24 -0800 Subject: [PATCH] Parser now ignores daily episodes from the future. --- NzbDrone.Core.Test/Files/RSS/nzbmatrix.xml | 10 ----- NzbDrone.Core.Test/ParserTest.cs | 20 +++++++++- .../DiskScanProviderTest_ImportFile.cs | 2 +- .../LogProviderTests/LogProviderFixture.cs | 2 +- NzbDrone.Core/Parser.cs | 38 ++++++++++++------- 5 files changed, 45 insertions(+), 27 deletions(-) diff --git a/NzbDrone.Core.Test/Files/RSS/nzbmatrix.xml b/NzbDrone.Core.Test/Files/RSS/nzbmatrix.xml index 4c422f780..71872272e 100644 --- a/NzbDrone.Core.Test/Files/RSS/nzbmatrix.xml +++ b/NzbDrone.Core.Test/Files/RSS/nzbmatrix.xml @@ -148,16 +148,6 @@ 6 - - Fussball Bundesliga 2010 2011 30 Spieltag FC Bayern Muenchen vs Bayer 04 Leverkusen German WS dTV XviD WoGS - http://nzbmatrix.com/nzb-details.php?id=914423&hit=1 - http://nzbmatrix.com/nzb-details.php?id=914423&hit=1 - Name: Fussball Bundesliga 2010 2011 30 Spieltag FC Bayern Muenchen vs Bayer 04 Leverkusen German WS dTV XviD WoGS
Category: TV: Divx/Xvid
Size: 1.28 GB
Added: 2011-04-25 11:41:35
Group: alt.binaries.multimedia
NFO: View NFO ]]>
- TV: Divx/Xvid - tv.divx/xvid - 6 - -
How I Met Your Mother S06E20 The Exploding Meatball Sub German Custom Subbed WS HDTV XviD iNTERNAL BaCKToRG http://nzbmatrix.com/nzb-details.php?id=914420&hit=1 diff --git a/NzbDrone.Core.Test/ParserTest.cs b/NzbDrone.Core.Test/ParserTest.cs index 8f6c6075d..1ca1b1ab9 100644 --- a/NzbDrone.Core.Test/ParserTest.cs +++ b/NzbDrone.Core.Test/ParserTest.cs @@ -172,7 +172,7 @@ namespace NzbDrone.Core.Test [TestCase("2011.01.10 - Denis Leary - HD TV.mkv", "", 2011, 1, 10)] [TestCase("2011.03.13 - Denis Leary - HD TV.mkv", "", 2011, 3, 13)] [TestCase("The Tonight Show with Jay Leno - 2011-06-16 - Larry David, \"Bachelorette\" Ashley Hebert, Pitbull with Ne-Yo", "The Tonight Show with Jay Leno", 2011, 6, 16)] - public void episode_daily_parse(string postTitle, string title, int year, int month, int day) + public void parse_daily_episodes(string postTitle, string title, int year, int month, int day) { var result = Parser.ParseTitle(postTitle); var airDate = new DateTime(year, month, day); @@ -181,6 +181,16 @@ namespace NzbDrone.Core.Test Assert.IsNull(result.EpisodeNumbers); } + [Test] + public void parse_daily_should_fail_if_episode_is_far_in_future() + { + var title = string.Format("{0}.{1}.{2} - Denis Leary - HD TV.mkv", DateTime.Now.Year, DateTime.Now.Month, DateTime.Now.AddDays(2).Day); + + Parser.ParseTitle(title).Should().BeNull(); + + ExceptionVerification.ExcpectedWarns(1); + } + [TestCase("30.Rock.Season.04.HDTV.XviD-DIMENSION", "30.Rock", 4)] [TestCase("Parks.and.Recreation.S02.720p.x264-DIMENSION", "Parks.and.Recreation", 2)] @@ -364,5 +374,13 @@ namespace NzbDrone.Core.Test ExceptionVerification.ExcpectedWarns(1); } + + [TestCase("Fussball Bundesliga 2010 2011 30 Spieltag FC Bayern Muenchen vs Bayer 04 Leverkusen German WS dTV XviD WoGS")] + public void unparsable_should_log_error_but_not_throw(string title) + { + Parser.ParseTitle(title); + ExceptionVerification.IgnoreWarns(); + ExceptionVerification.ExcpectedErrors(1); + } } } diff --git a/NzbDrone.Core.Test/ProviderTests/DiskScanProviderTest_ImportFile.cs b/NzbDrone.Core.Test/ProviderTests/DiskScanProviderTest_ImportFile.cs index 57cf7ad38..f3db56dba 100644 --- a/NzbDrone.Core.Test/ProviderTests/DiskScanProviderTest_ImportFile.cs +++ b/NzbDrone.Core.Test/ProviderTests/DiskScanProviderTest_ImportFile.cs @@ -137,7 +137,7 @@ namespace NzbDrone.Core.Test.ProviderTests //Assert VerifySkipImport(result, mocker); - ExceptionVerification.ExcpectedWarns(1); + ExceptionVerification.ExcpectedWarns(2); } [Test] diff --git a/NzbDrone.Core.Test/ProviderTests/LogProviderTests/LogProviderFixture.cs b/NzbDrone.Core.Test/ProviderTests/LogProviderTests/LogProviderFixture.cs index 34d00f77d..fbd9616f2 100644 --- a/NzbDrone.Core.Test/ProviderTests/LogProviderTests/LogProviderFixture.cs +++ b/NzbDrone.Core.Test/ProviderTests/LogProviderTests/LogProviderFixture.cs @@ -155,7 +155,7 @@ namespace NzbDrone.Core.Test.ProviderTests.LogProviderTests //Assert var result = Db.Fetch(); - result.Should().HaveCount(21); + result.Should().HaveCount(20); result.Should().OnlyContain(s => s.Time > DateTime.Now.AddDays(-30)); } diff --git a/NzbDrone.Core/Parser.cs b/NzbDrone.Core/Parser.cs index fece6bf26..a729b4255 100644 --- a/NzbDrone.Core/Parser.cs +++ b/NzbDrone.Core/Parser.cs @@ -80,26 +80,36 @@ namespace NzbDrone.Core internal static EpisodeParseResult ParseTitle(string title) { - Logger.Trace("Parsing string '{0}'", title); - var simpleTitle = SimpleTitleRegex.Replace(title, String.Empty); - - foreach (var regex in ReportTitleRegex) + try { - var match = regex.Matches(simpleTitle); + Logger.Trace("Parsing string '{0}'", title); + var simpleTitle = SimpleTitleRegex.Replace(title, String.Empty); - if (match.Count != 0) + foreach (var regex in ReportTitleRegex) { - var result = ParseMatchCollection(match); - if (result != null) + var match = regex.Matches(simpleTitle); + + if (match.Count != 0) { - result.Language = ParseLanguage(title); - result.Quality = ParseQuality(title); - return result; + var result = ParseMatchCollection(match); + if (result != null) + { + //Check if episode is in the future (most likley a parse error) + if (result.AirDate > DateTime.Now.AddDays(1).Date) + break; + + result.Language = ParseLanguage(title); + result.Quality = ParseQuality(title); + return result; + } } } + Logger.Warn("Unable to parse episode info. {0}", title); + } + catch (Exception e) + { + Logger.Error("An error has occurred while trying to parse '{0}'", title); } - - Logger.Warn("Unable to parse episode info. {0}", title); return null; } @@ -164,7 +174,7 @@ namespace NzbDrone.Core parsedEpisode = new EpisodeParseResult { - AirDate = new DateTime(airyear, airmonth, airday), + AirDate = new DateTime(airyear, airmonth, airday).Date, }; }