From 5be99200c67e30b58f1b5dc44221f36206491b93 Mon Sep 17 00:00:00 2001 From: "kay.one" Date: Sun, 22 May 2011 23:48:52 -0700 Subject: [PATCH] Added newzbing tests, fixed quality parse bugs --- NzbDrone.Core.Test/IndexerProviderTest.cs | 38 ++++++++++++++++++ NzbDrone.Core.Test/ParserTest.cs | 5 ++- NzbDrone.Core/Parser.cs | 45 ++++++++++++++-------- NzbDrone.Core/Providers/Indexer/Newzbin.cs | 17 ++++---- 4 files changed, 82 insertions(+), 23 deletions(-) diff --git a/NzbDrone.Core.Test/IndexerProviderTest.cs b/NzbDrone.Core.Test/IndexerProviderTest.cs index dccb384a5..1eb820f59 100644 --- a/NzbDrone.Core.Test/IndexerProviderTest.cs +++ b/NzbDrone.Core.Test/IndexerProviderTest.cs @@ -43,6 +43,12 @@ namespace NzbDrone.Core.Test var parseResults = mocker.Resolve().Fetch(); + foreach (var episodeParseResult in parseResults) + { + var Uri = new Uri(episodeParseResult.NzbUrl); + Assert.DoesNotContain(Uri.PathAndQuery, "//"); + } + Assert.IsNotEmpty(parseResults); ExceptionVerification.ExcpectedWarns(warns); @@ -50,6 +56,38 @@ namespace NzbDrone.Core.Test + [Test] + public void newzbin() + { + var mocker = new AutoMoqer(); + + mocker.GetMock() + .Setup(h => h.DownloadStream(It.IsAny(), It.IsAny())) + .Returns(File.OpenRead(".\\Files\\Rss\\newzbin.xml")); + + var fakeSettings = Builder.CreateNew().Build(); + mocker.GetMock() + .Setup(c => c.GetSettings(It.IsAny())) + .Returns(fakeSettings); + + var parseResults = mocker.Resolve().Fetch(); + + foreach (var episodeParseResult in parseResults) + { + var Uri = new Uri(episodeParseResult.NzbUrl); + Assert.DoesNotContain(Uri.PathAndQuery, "//"); + } + + + Assert.IsNotEmpty(parseResults); + ExceptionVerification.ExcpectedWarns(1); + } + + + + + + [Test] [Row("Adventure.Inc.S03E19.DVDRip.XviD-OSiTV", 3, 19, QualityTypes.DVD)] public void custome_parser_partial_success(string title, int season, int episode, QualityTypes quality) diff --git a/NzbDrone.Core.Test/ParserTest.cs b/NzbDrone.Core.Test/ParserTest.cs index 9ec82dc28..4650a0db7 100644 --- a/NzbDrone.Core.Test/ParserTest.cs +++ b/NzbDrone.Core.Test/ParserTest.cs @@ -70,8 +70,10 @@ namespace NzbDrone.Core.Test [Row("WEEDS.S03E01-06.DUAL.BDRip.XviD.AC3.-HELLYWOOD", QualityTypes.BDRip)] [Row("WEEDS.S03E01-06.DUAL.BDRip.AC3.-HELLYWOOD", QualityTypes.BDRip)] [Row("Two.and.a.Half.Men.S08E05.720p.HDTV.X264-DIMENSION", QualityTypes.HDTV)] + [Row("this has no extention or periods HDTV", QualityTypes.TV)] [Row("Chuck.S04E05.HDTV.XviD-LOL", QualityTypes.TV)] [Row("The.Girls.Next.Door.S03E06.DVDRip.XviD-WiDE", QualityTypes.DVD)] + [Row("The.Girls.Next.Door.S03E06.HDTV-WiDE", QualityTypes.TV)] [Row("Degrassi.S10E27.WS.DSR.XviD-2HD", QualityTypes.TV)] [Row("Sonny.With.a.Chance.S02E15.720p.WEB-DL.DD5.1.H.264-SURFER", QualityTypes.WEBDL)] [Row("Sonny.With.a.Chance.S02E15.720p", QualityTypes.HDTV)] @@ -88,9 +90,10 @@ namespace NzbDrone.Core.Test [Row("WEEDS.S03E01-06.DUAL.BDRip.XviD.AC3.-HELLYWOOD.avi", QualityTypes.BDRip)] [Row("WEEDS.S03E01-06.DUAL.BDRip.XviD.AC3.-HELLYWOOD.avi", QualityTypes.BDRip)] [Row("Law & Order: Special Victims Unit - 11x11 - Quickie", QualityTypes.Unknown)] + [Row("(NZB)", QualityTypes.Unknown)] public void quality_parse(string postTitle, object quality) { - var result = Parser.ParseEpisodeInfo(postTitle).Quality; + var result = Parser.ParseQuality(postTitle); Assert.AreEqual(quality, result); } diff --git a/NzbDrone.Core/Parser.cs b/NzbDrone.Core/Parser.cs index 10d7ecaed..ded4abe8f 100644 --- a/NzbDrone.Core/Parser.cs +++ b/NzbDrone.Core/Parser.cs @@ -239,24 +239,39 @@ namespace NzbDrone.Core return QualityTypes.HDTV; //Based on extension - if (result == QualityTypes.Unknown && Path.HasExtension(name)) + + + + if (result == QualityTypes.Unknown) { - switch (Path.GetExtension(name).ToLower()) + try { - case ".avi": - case ".xvid": - case ".wmv": - case ".mp4": - { - result = QualityTypes.TV; - break; - } - case ".mkv": - { - result = QualityTypes.HDTV; - break; - } + switch (Path.GetExtension(name).ToLower()) + { + case ".avi": + case ".xvid": + case ".wmv": + case ".mp4": + { + result = QualityTypes.TV; + break; + } + case ".mkv": + { + result = QualityTypes.HDTV; + break; + } + } } + catch (ArgumentException) + { + //Swallow exception for cases where string contains illegal + //path characters. + } + } + if (name.Contains("hdtv")) + { + return QualityTypes.TV; } Logger.Trace("Quality Parsed:{0} Title:", result, name); diff --git a/NzbDrone.Core/Providers/Indexer/Newzbin.cs b/NzbDrone.Core/Providers/Indexer/Newzbin.cs index 9e98f3f5c..06a3d2de8 100644 --- a/NzbDrone.Core/Providers/Indexer/Newzbin.cs +++ b/NzbDrone.Core/Providers/Indexer/Newzbin.cs @@ -9,7 +9,8 @@ namespace NzbDrone.Core.Providers.Indexer { public class Newzbin : IndexerBase { - public Newzbin(HttpProvider httpProvider, ConfigProvider configProvider, IndexerProvider indexerProvider) : base(httpProvider, configProvider, indexerProvider) + public Newzbin(HttpProvider httpProvider, ConfigProvider configProvider, IndexerProvider indexerProvider) + : base(httpProvider, configProvider, indexerProvider) { } @@ -36,17 +37,19 @@ namespace NzbDrone.Core.Providers.Indexer protected override string NzbDownloadUrl(SyndicationItem item) { - return item.Id + "/nzb"; + return item.Id + "nzb"; } protected override EpisodeParseResult CustomParser(SyndicationItem item, EpisodeParseResult currentResult) { - var quality = Parser.ParseQuality(item.Summary.Text); - var proper = Parser.ParseProper(item.Summary.Text); - - currentResult.Quality = quality; - currentResult.Proper = proper; + if (currentResult != null) + { + var quality = Parser.ParseQuality(item.Summary.Text); + var proper = Parser.ParseProper(item.Summary.Text); + currentResult.Quality = quality; + currentResult.Proper = proper; + } return currentResult; }