From a5bb99367e6c31cbe3ae4e9abd39d2c97e79c8a4 Mon Sep 17 00:00:00 2001 From: "kay.one" Date: Tue, 30 Jul 2013 22:49:41 -0700 Subject: [PATCH] skip queue check and adding new items if download client isn't configured correctly. --- .../Download/DownloadServiceFixture.cs | 21 ++++++++++++++++++- .../Specifications/NotInQueueSpecification.cs | 11 +++++++++- .../Download/Clients/BlackholeProvider.cs | 8 +++++++ .../Download/Clients/Nzbget/NzbgetClient.cs | 8 +++++++ .../Download/Clients/PneumaticClient.cs | 8 +++++++ .../Download/Clients/Sabnzbd/SabnzbdClient.cs | 11 +++++++++- NzbDrone.Core/Download/DownloadService.cs | 10 +++++++-- NzbDrone.Core/Download/IDownloadClient.cs | 1 + 8 files changed, 73 insertions(+), 5 deletions(-) diff --git a/NzbDrone.Core.Test/Download/DownloadServiceFixture.cs b/NzbDrone.Core.Test/Download/DownloadServiceFixture.cs index 306a2b2c1..32b859c0e 100644 --- a/NzbDrone.Core.Test/Download/DownloadServiceFixture.cs +++ b/NzbDrone.Core.Test/Download/DownloadServiceFixture.cs @@ -6,6 +6,7 @@ using NzbDrone.Core.Download; using NzbDrone.Core.Parser.Model; using NzbDrone.Core.Test.Framework; using NzbDrone.Core.Tv; +using NzbDrone.Test.Common; namespace NzbDrone.Core.Test.Download { @@ -28,9 +29,12 @@ namespace NzbDrone.Core.Test.Download _parseResult = Builder.CreateNew() .With(c => c.Series = Builder.CreateNew().Build()) - .With(c=>c.Report = Builder.CreateNew().Build()) + .With(c => c.Report = Builder.CreateNew().Build()) .With(c => c.Episodes = episodes) .Build(); + + + Mocker.GetMock().Setup(c => c.IsConfigured).Returns(true); } private void WithSuccessfulAdd() @@ -76,5 +80,20 @@ namespace NzbDrone.Core.Test.Download Subject.DownloadReport(_parseResult); VerifyEventNotPublished(); } + + + [Test] + public void should_not_attempt_download_if_client_isnt_configure() + { + Mocker.GetMock().Setup(c => c.IsConfigured).Returns(false); + + + Subject.DownloadReport(_parseResult); + + Mocker.GetMock().Verify(c => c.DownloadNzb(It.IsAny()),Times.Never()); + VerifyEventNotPublished(); + + ExceptionVerification.ExpectedWarns(1); + } } } diff --git a/NzbDrone.Core/DecisionEngine/Specifications/NotInQueueSpecification.cs b/NzbDrone.Core/DecisionEngine/Specifications/NotInQueueSpecification.cs index 79127ab9e..7787d6f56 100644 --- a/NzbDrone.Core/DecisionEngine/Specifications/NotInQueueSpecification.cs +++ b/NzbDrone.Core/DecisionEngine/Specifications/NotInQueueSpecification.cs @@ -1,6 +1,7 @@ using System; using System.Collections.Generic; using System.Linq; +using NLog; using NzbDrone.Core.Download; using NzbDrone.Core.Parser.Model; using NzbDrone.Core.Tv; @@ -10,10 +11,12 @@ namespace NzbDrone.Core.DecisionEngine.Specifications public class NotInQueueSpecification : IDecisionEngineSpecification { private readonly IProvideDownloadClient _downloadClientProvider; + private readonly Logger _logger; - public NotInQueueSpecification(IProvideDownloadClient downloadClientProvider) + public NotInQueueSpecification(IProvideDownloadClient downloadClientProvider, Logger logger) { _downloadClientProvider = downloadClientProvider; + _logger = logger; } public string RejectionReason @@ -28,6 +31,12 @@ namespace NzbDrone.Core.DecisionEngine.Specifications { var downloadClient = _downloadClientProvider.GetDownloadClient(); + if (!downloadClient.IsConfigured) + { + _logger.Warn("Download client {0} isn't configured yet.", downloadClient.GetType().Name); + return true; + } + var queue = downloadClient.GetQueue().Select(queueItem => Parser.Parser.ParseTitle(queueItem.Title)).Where(episodeInfo => episodeInfo != null); return !IsInQueue(subject, queue); diff --git a/NzbDrone.Core/Download/Clients/BlackholeProvider.cs b/NzbDrone.Core/Download/Clients/BlackholeProvider.cs index 43ab97916..cfd4e4d87 100644 --- a/NzbDrone.Core/Download/Clients/BlackholeProvider.cs +++ b/NzbDrone.Core/Download/Clients/BlackholeProvider.cs @@ -63,6 +63,14 @@ namespace NzbDrone.Core.Download.Clients } } + public bool IsConfigured + { + get + { + return !string.IsNullOrWhiteSpace(_configService.BlackholeFolder); + } + } + public IEnumerable GetQueue() { return new QueueItem[0]; diff --git a/NzbDrone.Core/Download/Clients/Nzbget/NzbgetClient.cs b/NzbDrone.Core/Download/Clients/Nzbget/NzbgetClient.cs index 27a281afc..566a07f31 100644 --- a/NzbDrone.Core/Download/Clients/Nzbget/NzbgetClient.cs +++ b/NzbDrone.Core/Download/Clients/Nzbget/NzbgetClient.cs @@ -57,6 +57,14 @@ namespace NzbDrone.Core.Download.Clients.Nzbget return false; } + public bool IsConfigured + { + get + { + return !string.IsNullOrWhiteSpace(_configService.NzbgetHost) && _configService.NzbgetPort != 0; + } + } + public virtual IEnumerable GetQueue() { var command = new JsonRequest diff --git a/NzbDrone.Core/Download/Clients/PneumaticClient.cs b/NzbDrone.Core/Download/Clients/PneumaticClient.cs index e66eebbef..2ac8749a6 100644 --- a/NzbDrone.Core/Download/Clients/PneumaticClient.cs +++ b/NzbDrone.Core/Download/Clients/PneumaticClient.cs @@ -68,6 +68,14 @@ namespace NzbDrone.Core.Download.Clients } } + public bool IsConfigured + { + get + { + return !string.IsNullOrWhiteSpace(_configService.PneumaticFolder); + } + } + public IEnumerable GetQueue() { return new QueueItem[0]; diff --git a/NzbDrone.Core/Download/Clients/Sabnzbd/SabnzbdClient.cs b/NzbDrone.Core/Download/Clients/Sabnzbd/SabnzbdClient.cs index 25967ea4a..059d7520c 100644 --- a/NzbDrone.Core/Download/Clients/Sabnzbd/SabnzbdClient.cs +++ b/NzbDrone.Core/Download/Clients/Sabnzbd/SabnzbdClient.cs @@ -24,7 +24,7 @@ namespace NzbDrone.Core.Download.Clients.Sabnzbd public IRestRequest AddToQueueRequest(RemoteEpisode remoteEpisode) { string cat = _configService.SabTvCategory; - int priority = (int)_configService.SabRecentTvPriority; + int priority = (int)_configService.SabRecentTvPriority; string name = remoteEpisode.Report.NzbUrl.Replace("&", "%26"); string nzbName = HttpUtility.UrlEncode(remoteEpisode.Report.Title); @@ -97,6 +97,15 @@ namespace NzbDrone.Core.Download.Clients.Sabnzbd return false; } + public bool IsConfigured + { + get + { + return !string.IsNullOrWhiteSpace(_configService.SabHost) + && _configService.SabPort != 0; + } + } + public IEnumerable GetQueue() { string action = String.Format("mode=queue&output=json&start={0}&limit={1}", 0, 0); diff --git a/NzbDrone.Core/Download/DownloadService.cs b/NzbDrone.Core/Download/DownloadService.cs index 9eb0b82c4..9637d4417 100644 --- a/NzbDrone.Core/Download/DownloadService.cs +++ b/NzbDrone.Core/Download/DownloadService.cs @@ -27,9 +27,15 @@ namespace NzbDrone.Core.Download public bool DownloadReport(RemoteEpisode remoteEpisode) { var downloadTitle = remoteEpisode.Report.Title; - var provider = _downloadClientProvider.GetDownloadClient(); + var downloadClient = _downloadClientProvider.GetDownloadClient(); - bool success = provider.DownloadNzb(remoteEpisode); + if (!downloadClient.IsConfigured) + { + _logger.Warn("Download client {0} isn't configured yet.", downloadClient.GetType().Name); + return false; + } + + bool success = downloadClient.DownloadNzb(remoteEpisode); if (success) { diff --git a/NzbDrone.Core/Download/IDownloadClient.cs b/NzbDrone.Core/Download/IDownloadClient.cs index 0cef19aca..6d3653c7e 100644 --- a/NzbDrone.Core/Download/IDownloadClient.cs +++ b/NzbDrone.Core/Download/IDownloadClient.cs @@ -6,6 +6,7 @@ namespace NzbDrone.Core.Download public interface IDownloadClient { bool DownloadNzb(RemoteEpisode remoteEpisode); + bool IsConfigured { get; } IEnumerable GetQueue(); }