1
0
mirror of https://github.com/Radarr/Radarr.git synced 2024-11-05 02:22:31 +01:00

skip queue check and adding new items if download client isn't configured correctly.

This commit is contained in:
kay.one 2013-07-30 22:49:41 -07:00
parent 1eb278c7f6
commit a5bb99367e
8 changed files with 73 additions and 5 deletions

View File

@ -6,6 +6,7 @@
using NzbDrone.Core.Parser.Model; using NzbDrone.Core.Parser.Model;
using NzbDrone.Core.Test.Framework; using NzbDrone.Core.Test.Framework;
using NzbDrone.Core.Tv; using NzbDrone.Core.Tv;
using NzbDrone.Test.Common;
namespace NzbDrone.Core.Test.Download namespace NzbDrone.Core.Test.Download
{ {
@ -28,9 +29,12 @@ public void Setup()
_parseResult = Builder<RemoteEpisode>.CreateNew() _parseResult = Builder<RemoteEpisode>.CreateNew()
.With(c => c.Series = Builder<Series>.CreateNew().Build()) .With(c => c.Series = Builder<Series>.CreateNew().Build())
.With(c=>c.Report = Builder<ReportInfo>.CreateNew().Build()) .With(c => c.Report = Builder<ReportInfo>.CreateNew().Build())
.With(c => c.Episodes = episodes) .With(c => c.Episodes = episodes)
.Build(); .Build();
Mocker.GetMock<IDownloadClient>().Setup(c => c.IsConfigured).Returns(true);
} }
private void WithSuccessfulAdd() private void WithSuccessfulAdd()
@ -76,5 +80,20 @@ public void Download_report_should_not_publish_on_failed_grab_event()
Subject.DownloadReport(_parseResult); Subject.DownloadReport(_parseResult);
VerifyEventNotPublished<EpisodeGrabbedEvent>(); VerifyEventNotPublished<EpisodeGrabbedEvent>();
} }
[Test]
public void should_not_attempt_download_if_client_isnt_configure()
{
Mocker.GetMock<IDownloadClient>().Setup(c => c.IsConfigured).Returns(false);
Subject.DownloadReport(_parseResult);
Mocker.GetMock<IDownloadClient>().Verify(c => c.DownloadNzb(It.IsAny<RemoteEpisode>()),Times.Never());
VerifyEventNotPublished<EpisodeGrabbedEvent>();
ExceptionVerification.ExpectedWarns(1);
}
} }
} }

View File

@ -1,6 +1,7 @@
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq; using System.Linq;
using NLog;
using NzbDrone.Core.Download; using NzbDrone.Core.Download;
using NzbDrone.Core.Parser.Model; using NzbDrone.Core.Parser.Model;
using NzbDrone.Core.Tv; using NzbDrone.Core.Tv;
@ -10,10 +11,12 @@ namespace NzbDrone.Core.DecisionEngine.Specifications
public class NotInQueueSpecification : IDecisionEngineSpecification public class NotInQueueSpecification : IDecisionEngineSpecification
{ {
private readonly IProvideDownloadClient _downloadClientProvider; private readonly IProvideDownloadClient _downloadClientProvider;
private readonly Logger _logger;
public NotInQueueSpecification(IProvideDownloadClient downloadClientProvider) public NotInQueueSpecification(IProvideDownloadClient downloadClientProvider, Logger logger)
{ {
_downloadClientProvider = downloadClientProvider; _downloadClientProvider = downloadClientProvider;
_logger = logger;
} }
public string RejectionReason public string RejectionReason
@ -28,6 +31,12 @@ public bool IsSatisfiedBy(RemoteEpisode subject)
{ {
var downloadClient = _downloadClientProvider.GetDownloadClient(); 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); var queue = downloadClient.GetQueue().Select(queueItem => Parser.Parser.ParseTitle(queueItem.Title)).Where(episodeInfo => episodeInfo != null);
return !IsInQueue(subject, queue); return !IsInQueue(subject, queue);

View File

@ -63,6 +63,14 @@ public bool DownloadNzb(RemoteEpisode remoteEpisode)
} }
} }
public bool IsConfigured
{
get
{
return !string.IsNullOrWhiteSpace(_configService.BlackholeFolder);
}
}
public IEnumerable<QueueItem> GetQueue() public IEnumerable<QueueItem> GetQueue()
{ {
return new QueueItem[0]; return new QueueItem[0];

View File

@ -57,6 +57,14 @@ public virtual bool DownloadNzb(RemoteEpisode remoteEpisode)
return false; return false;
} }
public bool IsConfigured
{
get
{
return !string.IsNullOrWhiteSpace(_configService.NzbgetHost) && _configService.NzbgetPort != 0;
}
}
public virtual IEnumerable<QueueItem> GetQueue() public virtual IEnumerable<QueueItem> GetQueue()
{ {
var command = new JsonRequest var command = new JsonRequest

View File

@ -68,6 +68,14 @@ public virtual bool DownloadNzb(RemoteEpisode remoteEpisode)
} }
} }
public bool IsConfigured
{
get
{
return !string.IsNullOrWhiteSpace(_configService.PneumaticFolder);
}
}
public IEnumerable<QueueItem> GetQueue() public IEnumerable<QueueItem> GetQueue()
{ {
return new QueueItem[0]; return new QueueItem[0];

View File

@ -24,7 +24,7 @@ public SabRequestBuilder(IConfigService configService)
public IRestRequest AddToQueueRequest(RemoteEpisode remoteEpisode) public IRestRequest AddToQueueRequest(RemoteEpisode remoteEpisode)
{ {
string cat = _configService.SabTvCategory; string cat = _configService.SabTvCategory;
int priority = (int)_configService.SabRecentTvPriority; int priority = (int)_configService.SabRecentTvPriority;
string name = remoteEpisode.Report.NzbUrl.Replace("&", "%26"); string name = remoteEpisode.Report.NzbUrl.Replace("&", "%26");
string nzbName = HttpUtility.UrlEncode(remoteEpisode.Report.Title); string nzbName = HttpUtility.UrlEncode(remoteEpisode.Report.Title);
@ -97,6 +97,15 @@ public virtual bool DownloadNzb(RemoteEpisode remoteEpisode)
return false; return false;
} }
public bool IsConfigured
{
get
{
return !string.IsNullOrWhiteSpace(_configService.SabHost)
&& _configService.SabPort != 0;
}
}
public IEnumerable<QueueItem> GetQueue() public IEnumerable<QueueItem> GetQueue()
{ {
string action = String.Format("mode=queue&output=json&start={0}&limit={1}", 0, 0); string action = String.Format("mode=queue&output=json&start={0}&limit={1}", 0, 0);

View File

@ -27,9 +27,15 @@ public DownloadService(IProvideDownloadClient downloadClientProvider,
public bool DownloadReport(RemoteEpisode remoteEpisode) public bool DownloadReport(RemoteEpisode remoteEpisode)
{ {
var downloadTitle = remoteEpisode.Report.Title; 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) if (success)
{ {

View File

@ -6,6 +6,7 @@ namespace NzbDrone.Core.Download
public interface IDownloadClient public interface IDownloadClient
{ {
bool DownloadNzb(RemoteEpisode remoteEpisode); bool DownloadNzb(RemoteEpisode remoteEpisode);
bool IsConfigured { get; }
IEnumerable<QueueItem> GetQueue(); IEnumerable<QueueItem> GetQueue();
} }