mirror of
https://github.com/Readarr/Readarr.git
synced 2026-04-21 22:04:31 -04:00
New: Rebuilt Completed/Failed download handling from scratch
This commit is contained in:
@@ -7,12 +7,14 @@ namespace NzbDrone.Core.DecisionEngine
|
||||
public Boolean Accepted { get; private set; }
|
||||
public String Reason { get; private set; }
|
||||
|
||||
private static readonly Decision AcceptDecision = new Decision { Accepted = true };
|
||||
private Decision()
|
||||
{
|
||||
}
|
||||
|
||||
public static Decision Accept()
|
||||
{
|
||||
return new Decision
|
||||
{
|
||||
Accepted = true
|
||||
};
|
||||
return AcceptDecision;
|
||||
}
|
||||
|
||||
public static Decision Reject(String reason, params object[] args)
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
using NLog;
|
||||
using NzbDrone.Core.Blacklisting;
|
||||
using NzbDrone.Core.Configuration;
|
||||
using NzbDrone.Core.Indexers;
|
||||
using NzbDrone.Core.IndexerSearch.Definitions;
|
||||
using NzbDrone.Core.Parser.Model;
|
||||
|
||||
@@ -9,13 +9,11 @@ namespace NzbDrone.Core.DecisionEngine.Specifications
|
||||
public class BlacklistSpecification : IDecisionEngineSpecification
|
||||
{
|
||||
private readonly IBlacklistService _blacklistService;
|
||||
private readonly IConfigService _configService;
|
||||
private readonly Logger _logger;
|
||||
|
||||
public BlacklistSpecification(IBlacklistService blacklistService, IConfigService configService, Logger logger)
|
||||
public BlacklistSpecification(IBlacklistService blacklistService, Logger logger)
|
||||
{
|
||||
_blacklistService = blacklistService;
|
||||
_configService = configService;
|
||||
_logger = logger;
|
||||
}
|
||||
|
||||
@@ -23,12 +21,12 @@ namespace NzbDrone.Core.DecisionEngine.Specifications
|
||||
|
||||
public Decision IsSatisfiedBy(RemoteEpisode subject, SearchCriteriaBase searchCriteria)
|
||||
{
|
||||
if (!_configService.EnableFailedDownloadHandling)
|
||||
if (subject.Release.DownloadProtocol == DownloadProtocol.Torrent)
|
||||
{
|
||||
_logger.Debug("Failed Download Handling is not enabled");
|
||||
return Decision.Accept();
|
||||
}
|
||||
|
||||
|
||||
if (_blacklistService.Blacklisted(subject.Series.Id, subject.Release.Title, subject.Release.PublishDate))
|
||||
{
|
||||
_logger.Debug("{0} is blacklisted, rejecting.", subject.Release.Title);
|
||||
|
||||
@@ -1,21 +1,21 @@
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using NLog;
|
||||
using NzbDrone.Core.Download;
|
||||
using NzbDrone.Core.IndexerSearch.Definitions;
|
||||
using NzbDrone.Core.Parser.Model;
|
||||
using NzbDrone.Core.Qualities;
|
||||
using NzbDrone.Core.Queue;
|
||||
|
||||
namespace NzbDrone.Core.DecisionEngine.Specifications
|
||||
{
|
||||
public class NotInQueueSpecification : IDecisionEngineSpecification
|
||||
{
|
||||
private readonly IDownloadTrackingService _downloadTrackingService;
|
||||
private readonly IQueueService _queueService;
|
||||
private readonly Logger _logger;
|
||||
|
||||
public NotInQueueSpecification(IDownloadTrackingService downloadTrackingService, Logger logger)
|
||||
public NotInQueueSpecification(IQueueService queueService, Logger logger)
|
||||
{
|
||||
_downloadTrackingService = downloadTrackingService;
|
||||
_queueService = queueService;
|
||||
_logger = logger;
|
||||
}
|
||||
|
||||
@@ -23,8 +23,7 @@ namespace NzbDrone.Core.DecisionEngine.Specifications
|
||||
|
||||
public Decision IsSatisfiedBy(RemoteEpisode subject, SearchCriteriaBase searchCriteria)
|
||||
{
|
||||
var queue = _downloadTrackingService.GetQueuedDownloads()
|
||||
.Where(v => v.State == TrackedDownloadState.Downloading)
|
||||
var queue = _queueService.GetQueue()
|
||||
.Select(q => q.RemoteEpisode).ToList();
|
||||
|
||||
if (IsInQueue(subject, queue))
|
||||
@@ -36,9 +35,9 @@ namespace NzbDrone.Core.DecisionEngine.Specifications
|
||||
return Decision.Accept();
|
||||
}
|
||||
|
||||
private bool IsInQueue(RemoteEpisode newEpisode, IEnumerable<RemoteEpisode> queue)
|
||||
private bool IsInQueue(RemoteEpisode newEpisode, IEnumerable<RemoteEpisode> episodesInQueue)
|
||||
{
|
||||
var matchingSeries = queue.Where(q => q.Series.Id == newEpisode.Series.Id);
|
||||
var matchingSeries = episodesInQueue.Where(q => q.Series.Id == newEpisode.Series.Id);
|
||||
var matchingSeriesAndQuality = matchingSeries.Where(q => new QualityModelComparer(q.Series.Profile).Compare(q.ParsedEpisodeInfo.Quality, newEpisode.ParsedEpisodeInfo.Quality) >= 0);
|
||||
|
||||
return matchingSeriesAndQuality.Any(q => q.Episodes.Select(e => e.Id).Intersect(newEpisode.Episodes.Select(e => e.Id)).Any());
|
||||
|
||||
@@ -1,57 +0,0 @@
|
||||
using System;
|
||||
using System.Linq;
|
||||
using NLog;
|
||||
using NzbDrone.Common.Extensions;
|
||||
using NzbDrone.Core.Configuration;
|
||||
using NzbDrone.Core.History;
|
||||
using NzbDrone.Core.IndexerSearch.Definitions;
|
||||
using NzbDrone.Core.Parser.Model;
|
||||
|
||||
namespace NzbDrone.Core.DecisionEngine.Specifications
|
||||
{
|
||||
public class RetrySpecification : IDecisionEngineSpecification
|
||||
{
|
||||
private readonly IHistoryService _historyService;
|
||||
private readonly IConfigService _configService;
|
||||
private readonly Logger _logger;
|
||||
|
||||
public RetrySpecification(IHistoryService historyService, IConfigService configService, Logger logger)
|
||||
{
|
||||
_historyService = historyService;
|
||||
_configService = configService;
|
||||
_logger = logger;
|
||||
}
|
||||
|
||||
public RejectionType Type { get { return RejectionType.Permanent; } }
|
||||
|
||||
public Decision IsSatisfiedBy(RemoteEpisode subject, SearchCriteriaBase searchCriteria)
|
||||
{
|
||||
if (!_configService.EnableFailedDownloadHandling)
|
||||
{
|
||||
_logger.Debug("Failed Download Handling is not enabled");
|
||||
return Decision.Accept();
|
||||
}
|
||||
|
||||
var history = _historyService.FindBySourceTitle(subject.Release.Title);
|
||||
|
||||
if (history.Count(h => h.EventType == HistoryEventType.Grabbed &&
|
||||
HasSamePublishedDate(h, subject.Release.PublishDate)) >
|
||||
_configService.BlacklistRetryLimit)
|
||||
{
|
||||
_logger.Debug("Release has been attempted more times than allowed, rejecting");
|
||||
return Decision.Reject("Retried too many times");
|
||||
}
|
||||
|
||||
return Decision.Accept();
|
||||
}
|
||||
|
||||
private bool HasSamePublishedDate(History.History item, DateTime publishedDate)
|
||||
{
|
||||
DateTime itemsPublishedDate;
|
||||
|
||||
if (!DateTime.TryParse(item.Data.GetValueOrDefault("PublishedDate", null), out itemsPublishedDate)) return true;
|
||||
|
||||
return itemsPublishedDate.AddDays(-2) <= publishedDate && itemsPublishedDate.AddDays(2) >= publishedDate;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user