From 5dc7e03b8d96ea67db6f94293a74fdb6a6e39760 Mon Sep 17 00:00:00 2001 From: "kay.one" Date: Sat, 8 Jun 2013 10:29:19 -0700 Subject: [PATCH] fixed nzbclub size parsing. Http timeout reduced from 100 to 20 seconds --- NzbDrone.Common/HttpProvider.cs | 1 + .../IndexerIntegrationTests.cs | 46 ++++++++++++++----- .../IntegrationTests/NzbxIntegrationTests.cs | 28 ----------- NzbDrone.Core.Test/NzbDrone.Core.Test.csproj | 1 - .../Indexers/NzbClub/NzbClubParser.cs | 23 +++++++++- UI/.idea/runConfigurations/Debug___Chrome.xml | 32 ++++++------- .../runConfigurations/Debug___Firefox.xml | 32 ++++++------- UI/Release/Layout.js | 6 +-- 8 files changed, 92 insertions(+), 77 deletions(-) delete mode 100644 NzbDrone.Core.Test/IndexerTests/IntegrationTests/NzbxIntegrationTests.cs diff --git a/NzbDrone.Common/HttpProvider.cs b/NzbDrone.Common/HttpProvider.cs index d3b9f67ac..50d1b1763 100644 --- a/NzbDrone.Common/HttpProvider.cs +++ b/NzbDrone.Common/HttpProvider.cs @@ -80,6 +80,7 @@ namespace NzbDrone.Common { var request = (HttpWebRequest)WebRequest.Create(url); request.UserAgent = _userAgent; + request.Timeout = 20 * 1000; request.Credentials = credential; var response = request.GetResponse(); diff --git a/NzbDrone.Core.Test/IndexerTests/IntegrationTests/IndexerIntegrationTests.cs b/NzbDrone.Core.Test/IndexerTests/IntegrationTests/IndexerIntegrationTests.cs index dbcd56d99..a244d89a8 100644 --- a/NzbDrone.Core.Test/IndexerTests/IntegrationTests/IndexerIntegrationTests.cs +++ b/NzbDrone.Core.Test/IndexerTests/IntegrationTests/IndexerIntegrationTests.cs @@ -1,39 +1,52 @@ -using FluentAssertions; +using System.Collections.Generic; +using FluentAssertions; using NzbDrone.Core.Indexers; using NzbDrone.Core.Indexers.Newznab; using NzbDrone.Core.Indexers.NzbClub; +using NzbDrone.Core.Indexers.Nzbx; +using NzbDrone.Core.Parser.Model; using NzbDrone.Core.Test.Framework; using NUnit.Framework; +using NzbDrone.Test.Common.Categories; namespace NzbDrone.Core.Test.IndexerTests.IntegrationTests { + [IntegrationTest] public class IndexerIntegrationTests : CoreTest { - [Test] - public void nzbclub_rss() + [SetUp] + public void SetUp() { UseRealHttp(); + + } + [Test] + public void nzbclub_rss() + { var indexer = new NzbClub(); var result = Subject.FetchRss(indexer); - result.Should().NotBeEmpty(); - result.Should().OnlyContain(c => !string.IsNullOrWhiteSpace(c.Title)); - result.Should().OnlyContain(c => !string.IsNullOrWhiteSpace(c.NzbUrl)); + ValidateResult(result); + } - //TODO: uncomment these after moving to restsharp for rss - //result.Should().OnlyContain(c => !string.IsNullOrWhiteSpace(c.NzbInfoUrl)); - //result.Should().OnlyContain(c => c.Size > 0); + [Test] + public void nzbx_rss() + { + var indexer = new Nzbx(); + + var result = Subject.FetchRss(indexer); + ValidateResult(result); } + + [Test] [Explicit("needs newznab api key")] public void nzbsorg_rss() { - UseRealHttp(); - var indexer = new Newznab(); indexer.Settings = new NewznabSettings { @@ -55,5 +68,16 @@ namespace NzbDrone.Core.Test.IndexerTests.IntegrationTests } + + + private void ValidateResult(IList reports) + { + reports.Should().NotBeEmpty(); + reports.Should().OnlyContain(c => !string.IsNullOrWhiteSpace(c.Title)); + reports.Should().OnlyContain(c => !string.IsNullOrWhiteSpace(c.NzbInfoUrl)); + reports.Should().OnlyContain(c => !string.IsNullOrWhiteSpace(c.NzbUrl)); + reports.Should().OnlyContain(c => c.Size > 0); + } + } } \ No newline at end of file diff --git a/NzbDrone.Core.Test/IndexerTests/IntegrationTests/NzbxIntegrationTests.cs b/NzbDrone.Core.Test/IndexerTests/IntegrationTests/NzbxIntegrationTests.cs deleted file mode 100644 index 86233e1a0..000000000 --- a/NzbDrone.Core.Test/IndexerTests/IntegrationTests/NzbxIntegrationTests.cs +++ /dev/null @@ -1,28 +0,0 @@ -using FluentAssertions; -using NzbDrone.Core.Indexers; -using NzbDrone.Core.Indexers.Nzbx; -using NzbDrone.Core.Test.Framework; -using NUnit.Framework; - -namespace NzbDrone.Core.Test.IndexerTests.IntegrationTests -{ - public class NzbxIntegrationTests : CoreTest - { - [Test] - public void should_be_able_to_fetch_rss() - { - UseRealHttp(); - - var indexer = new Nzbx(); - - var result = Subject.FetchRss(indexer); - - result.Should().NotBeEmpty(); - result.Should().OnlyContain(c => !string.IsNullOrWhiteSpace(c.Title)); - result.Should().OnlyContain(c => !string.IsNullOrWhiteSpace(c.NzbInfoUrl)); - result.Should().OnlyContain(c => !string.IsNullOrWhiteSpace(c.NzbUrl)); - result.Should().OnlyContain(c => c.Size > 0); - } - - } -} \ No newline at end of file diff --git a/NzbDrone.Core.Test/NzbDrone.Core.Test.csproj b/NzbDrone.Core.Test/NzbDrone.Core.Test.csproj index ed1deb168..01db5f2ce 100644 --- a/NzbDrone.Core.Test/NzbDrone.Core.Test.csproj +++ b/NzbDrone.Core.Test/NzbDrone.Core.Test.csproj @@ -137,7 +137,6 @@ - diff --git a/NzbDrone.Core/Indexers/NzbClub/NzbClubParser.cs b/NzbDrone.Core/Indexers/NzbClub/NzbClubParser.cs index 46d40d887..0355aaf82 100644 --- a/NzbDrone.Core/Indexers/NzbClub/NzbClubParser.cs +++ b/NzbDrone.Core/Indexers/NzbClub/NzbClubParser.cs @@ -1,18 +1,37 @@ using System; using System.ServiceModel.Syndication; using System.Text.RegularExpressions; +using NLog; using NzbDrone.Core.Parser.Model; namespace NzbDrone.Core.Indexers.NzbClub { public class NzbClubParser : BasicRssParser { + + private static readonly Regex SizeRegex = new Regex(@"(?:Size:)\s(?\d+.\d+\s[g|m]i?[b])", RegexOptions.Compiled | RegexOptions.IgnoreCase); + private readonly Logger logger; + + public NzbClubParser() + { + logger = LogManager.GetCurrentClassLogger(); + } + + protected override ReportInfo PostProcessor(SyndicationItem item, ReportInfo currentResult) { if (currentResult != null) { - var sizeString = Regex.Match(item.Summary.Text, @"Size:\s\d+\s+\w+", RegexOptions.IgnoreCase | RegexOptions.Compiled).Value; - currentResult.Size = GetReportSize(sizeString); + var match = SizeRegex.Match(item.Summary.Text); + + if (match.Success && match.Groups["size"].Success) + { + currentResult.Size = GetReportSize(match.Groups["size"].Value); + } + else + { + logger.Warn("Couldn't parse size from {0}", item.Summary.Text); + } } return currentResult; diff --git a/UI/.idea/runConfigurations/Debug___Chrome.xml b/UI/.idea/runConfigurations/Debug___Chrome.xml index 4ad681dfa..2323f096d 100644 --- a/UI/.idea/runConfigurations/Debug___Chrome.xml +++ b/UI/.idea/runConfigurations/Debug___Chrome.xml @@ -3,22 +3,22 @@ diff --git a/UI/.idea/runConfigurations/Debug___Firefox.xml b/UI/.idea/runConfigurations/Debug___Firefox.xml index 599880f12..1f0cbd78b 100644 --- a/UI/.idea/runConfigurations/Debug___Firefox.xml +++ b/UI/.idea/runConfigurations/Debug___Firefox.xml @@ -3,22 +3,22 @@ diff --git a/UI/Release/Layout.js b/UI/Release/Layout.js index 9efb385b9..998e89c5e 100644 --- a/UI/Release/Layout.js +++ b/UI/Release/Layout.js @@ -19,10 +19,10 @@ define([ columns: [ { - name : 'age', - label : 'Age', + name : 'indexer', + label : 'Indexer', sortable: true, - cell : Backgrid.IntegerCell + cell : Backgrid.StringCell }, { name : 'size',