parent
9a1022386a
commit
fa5bfc3742
|
@ -14,6 +14,7 @@ namespace NzbDrone.Core.Download
|
||||||
public interface IProcessDownloadDecisions
|
public interface IProcessDownloadDecisions
|
||||||
{
|
{
|
||||||
Task<ProcessedDecisions> ProcessDecisions(List<DownloadDecision> decisions);
|
Task<ProcessedDecisions> ProcessDecisions(List<DownloadDecision> decisions);
|
||||||
|
Task<ProcessedDecisionResult> ProcessDecision(DownloadDecision decision, int? downloadClientId);
|
||||||
}
|
}
|
||||||
|
|
||||||
public class ProcessDownloadDecisions : IProcessDownloadDecisions
|
public class ProcessDownloadDecisions : IProcessDownloadDecisions
|
||||||
|
@ -49,7 +50,6 @@ namespace NzbDrone.Core.Download
|
||||||
|
|
||||||
foreach (var report in prioritizedDecisions)
|
foreach (var report in prioritizedDecisions)
|
||||||
{
|
{
|
||||||
var remoteEpisode = report.RemoteEpisode;
|
|
||||||
var downloadProtocol = report.RemoteEpisode.Release.DownloadProtocol;
|
var downloadProtocol = report.RemoteEpisode.Release.DownloadProtocol;
|
||||||
|
|
||||||
// Skip if already grabbed
|
// Skip if already grabbed
|
||||||
|
@ -71,22 +71,30 @@ namespace NzbDrone.Core.Download
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
try
|
var result = await ProcessDecisionInternal(report);
|
||||||
|
|
||||||
|
switch (result)
|
||||||
|
{
|
||||||
|
case ProcessedDecisionResult.Grabbed:
|
||||||
{
|
{
|
||||||
_logger.Trace("Grabbing from Indexer {0} at priority {1}.", remoteEpisode.Release.Indexer, remoteEpisode.Release.IndexerPriority);
|
|
||||||
await _downloadService.DownloadReport(remoteEpisode, null);
|
|
||||||
grabbed.Add(report);
|
grabbed.Add(report);
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
catch (ReleaseUnavailableException)
|
|
||||||
|
case ProcessedDecisionResult.Pending:
|
||||||
|
{
|
||||||
|
PreparePending(pendingAddQueue, grabbed, pending, report, PendingReleaseReason.Delay);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
case ProcessedDecisionResult.Rejected:
|
||||||
{
|
{
|
||||||
_logger.Warn("Failed to download release from indexer, no longer available. " + remoteEpisode);
|
|
||||||
rejected.Add(report);
|
rejected.Add(report);
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
catch (Exception ex)
|
|
||||||
|
case ProcessedDecisionResult.Failed:
|
||||||
{
|
{
|
||||||
if (ex is DownloadClientUnavailableException || ex is DownloadClientAuthenticationException)
|
|
||||||
{
|
|
||||||
_logger.Debug(ex, "Failed to send release to download client, storing until later. " + remoteEpisode);
|
|
||||||
PreparePending(pendingAddQueue, grabbed, pending, report, PendingReleaseReason.DownloadClientUnavailable);
|
PreparePending(pendingAddQueue, grabbed, pending, report, PendingReleaseReason.DownloadClientUnavailable);
|
||||||
|
|
||||||
if (downloadProtocol == DownloadProtocol.Usenet)
|
if (downloadProtocol == DownloadProtocol.Usenet)
|
||||||
|
@ -97,10 +105,13 @@ namespace NzbDrone.Core.Download
|
||||||
{
|
{
|
||||||
torrentFailed = true;
|
torrentFailed = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
else
|
|
||||||
|
case ProcessedDecisionResult.Skipped:
|
||||||
{
|
{
|
||||||
_logger.Warn(ex, "Couldn't add report to download queue. " + remoteEpisode);
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -113,6 +124,30 @@ namespace NzbDrone.Core.Download
|
||||||
return new ProcessedDecisions(grabbed, pending, rejected);
|
return new ProcessedDecisions(grabbed, pending, rejected);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public async Task<ProcessedDecisionResult> ProcessDecision(DownloadDecision decision, int? downloadClientId)
|
||||||
|
{
|
||||||
|
if (decision == null)
|
||||||
|
{
|
||||||
|
return ProcessedDecisionResult.Skipped;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (decision.TemporarilyRejected)
|
||||||
|
{
|
||||||
|
_pendingReleaseService.Add(decision, PendingReleaseReason.Delay);
|
||||||
|
|
||||||
|
return ProcessedDecisionResult.Pending;
|
||||||
|
}
|
||||||
|
|
||||||
|
var result = await ProcessDecisionInternal(decision, downloadClientId);
|
||||||
|
|
||||||
|
if (result == ProcessedDecisionResult.Failed)
|
||||||
|
{
|
||||||
|
_pendingReleaseService.Add(decision, PendingReleaseReason.DownloadClientUnavailable);
|
||||||
|
}
|
||||||
|
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
internal List<DownloadDecision> GetQualifiedReports(IEnumerable<DownloadDecision> decisions)
|
internal List<DownloadDecision> GetQualifiedReports(IEnumerable<DownloadDecision> decisions)
|
||||||
{
|
{
|
||||||
// Process both approved and temporarily rejected
|
// Process both approved and temporarily rejected
|
||||||
|
@ -147,5 +182,38 @@ namespace NzbDrone.Core.Download
|
||||||
queue.Add(Tuple.Create(report, reason));
|
queue.Add(Tuple.Create(report, reason));
|
||||||
pending.Add(report);
|
pending.Add(report);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private async Task<ProcessedDecisionResult> ProcessDecisionInternal(DownloadDecision decision, int? downloadClientId = null)
|
||||||
|
{
|
||||||
|
var remoteEpisode = decision.RemoteEpisode;
|
||||||
|
|
||||||
|
try
|
||||||
|
{
|
||||||
|
_logger.Trace("Grabbing from Indexer {0} at priority {1}.", remoteEpisode.Release.Indexer, remoteEpisode.Release.IndexerPriority);
|
||||||
|
await _downloadService.DownloadReport(remoteEpisode, downloadClientId);
|
||||||
|
|
||||||
|
return ProcessedDecisionResult.Grabbed;
|
||||||
|
}
|
||||||
|
catch (ReleaseUnavailableException)
|
||||||
|
{
|
||||||
|
_logger.Warn("Failed to download release from indexer, no longer available. " + remoteEpisode);
|
||||||
|
return ProcessedDecisionResult.Rejected;
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
if (ex is DownloadClientUnavailableException || ex is DownloadClientAuthenticationException)
|
||||||
|
{
|
||||||
|
_logger.Debug(ex,
|
||||||
|
"Failed to send release to download client, storing until later. " + remoteEpisode);
|
||||||
|
|
||||||
|
return ProcessedDecisionResult.Failed;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
_logger.Warn(ex, "Couldn't add report to download queue. " + remoteEpisode);
|
||||||
|
return ProcessedDecisionResult.Skipped;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1,11 @@
|
||||||
|
namespace NzbDrone.Core.Download
|
||||||
|
{
|
||||||
|
public enum ProcessedDecisionResult
|
||||||
|
{
|
||||||
|
Grabbed,
|
||||||
|
Pending,
|
||||||
|
Rejected,
|
||||||
|
Failed,
|
||||||
|
Skipped
|
||||||
|
}
|
||||||
|
}
|
|
@ -57,22 +57,23 @@ namespace Sonarr.Api.V3.Indexers
|
||||||
|
|
||||||
ResolveIndexer(info);
|
ResolveIndexer(info);
|
||||||
|
|
||||||
List<DownloadDecision> decisions;
|
DownloadDecision decision;
|
||||||
|
|
||||||
lock (PushLock)
|
lock (PushLock)
|
||||||
{
|
{
|
||||||
decisions = _downloadDecisionMaker.GetRssDecision(new List<ReleaseInfo> { info });
|
var decisions = _downloadDecisionMaker.GetRssDecision(new List<ReleaseInfo> { info });
|
||||||
_downloadDecisionProcessor.ProcessDecisions(decisions).GetAwaiter().GetResult();
|
|
||||||
|
decision = decisions.FirstOrDefault();
|
||||||
|
|
||||||
|
_downloadDecisionProcessor.ProcessDecision(decision, release.DownloadClientId).GetAwaiter().GetResult();
|
||||||
}
|
}
|
||||||
|
|
||||||
var firstDecision = decisions.FirstOrDefault();
|
if (decision?.RemoteEpisode.ParsedEpisodeInfo == null)
|
||||||
|
|
||||||
if (firstDecision?.RemoteEpisode.ParsedEpisodeInfo == null)
|
|
||||||
{
|
{
|
||||||
throw new ValidationException(new List<ValidationFailure> { new ValidationFailure("Title", "Unable to parse", release.Title) });
|
throw new ValidationException(new List<ValidationFailure> { new ValidationFailure("Title", "Unable to parse", release.Title) });
|
||||||
}
|
}
|
||||||
|
|
||||||
return MapDecisions(new[] { firstDecision });
|
return MapDecisions(new[] { decision });
|
||||||
}
|
}
|
||||||
|
|
||||||
private void ResolveIndexer(ReleaseInfo release)
|
private void ResolveIndexer(ReleaseInfo release)
|
||||||
|
|
Loading…
Reference in New Issue