1
0
mirror of https://github.com/Sonarr/Sonarr.git synced 2026-04-21 22:05:38 -04:00

Add reason enum to decision engine rejections

This commit is contained in:
Mark McDowall
2024-11-11 10:03:18 -08:00
parent 160151c6e0
commit 8c67a3bdee
80 changed files with 634 additions and 458 deletions
@@ -8,7 +8,7 @@ using NzbDrone.Core.Qualities;
namespace NzbDrone.Core.DecisionEngine.Specifications.RssSync
{
public class DelaySpecification : IDecisionEngineSpecification
public class DelaySpecification : IDownloadDecisionEngineSpecification
{
private readonly IPendingReleaseService _pendingReleaseService;
private readonly IDelayProfileService _delayProfileService;
@@ -26,12 +26,12 @@ namespace NzbDrone.Core.DecisionEngine.Specifications.RssSync
public SpecificationPriority Priority => SpecificationPriority.Database;
public RejectionType Type => RejectionType.Temporary;
public virtual Decision IsSatisfiedBy(RemoteEpisode subject, SearchCriteriaBase searchCriteria)
public virtual DownloadSpecDecision IsSatisfiedBy(RemoteEpisode subject, SearchCriteriaBase searchCriteria)
{
if (searchCriteria != null && searchCriteria.UserInvokedSearch)
{
_logger.Debug("Ignoring delay for user invoked search");
return Decision.Accept();
return DownloadSpecDecision.Accept();
}
var qualityProfile = subject.Series.QualityProfile.Value;
@@ -42,7 +42,7 @@ namespace NzbDrone.Core.DecisionEngine.Specifications.RssSync
if (delay == 0)
{
_logger.Debug("QualityProfile does not require a waiting period before download for {0}.", subject.Release.DownloadProtocol);
return Decision.Accept();
return DownloadSpecDecision.Accept();
}
var qualityComparer = new QualityModelComparer(qualityProfile);
@@ -58,7 +58,7 @@ namespace NzbDrone.Core.DecisionEngine.Specifications.RssSync
if (qualityCompare == 0 && newQuality?.Revision.CompareTo(currentQuality.Revision) > 0)
{
_logger.Debug("New quality is a better revision for existing quality, skipping delay");
return Decision.Accept();
return DownloadSpecDecision.Accept();
}
}
}
@@ -72,7 +72,7 @@ namespace NzbDrone.Core.DecisionEngine.Specifications.RssSync
if (isBestInProfile && isPreferredProtocol)
{
_logger.Debug("Quality is highest in profile for preferred protocol, will not delay");
return Decision.Accept();
return DownloadSpecDecision.Accept();
}
}
@@ -85,7 +85,7 @@ namespace NzbDrone.Core.DecisionEngine.Specifications.RssSync
if (score >= minimum && isPreferredProtocol)
{
_logger.Debug("Custom format score ({0}) meets minimum ({1}) for preferred protocol, will not delay", score, minimum);
return Decision.Accept();
return DownloadSpecDecision.Accept();
}
}
@@ -95,16 +95,16 @@ namespace NzbDrone.Core.DecisionEngine.Specifications.RssSync
if (oldest != null && oldest.Release.AgeMinutes > delay)
{
return Decision.Accept();
return DownloadSpecDecision.Accept();
}
if (subject.Release.AgeMinutes < delay)
{
_logger.Debug("Waiting for better quality release, There is a {0} minute delay on {1}", delay, subject.Release.DownloadProtocol);
return Decision.Reject("Waiting for better quality release");
return DownloadSpecDecision.Reject(DownloadRejectionReason.MinimumAgeDelay, "Waiting for better quality release");
}
return Decision.Accept();
return DownloadSpecDecision.Accept();
}
}
}
@@ -10,7 +10,7 @@ using NzbDrone.Core.Tv;
namespace NzbDrone.Core.DecisionEngine.Specifications.RssSync
{
public class DeletedEpisodeFileSpecification : IDecisionEngineSpecification
public class DeletedEpisodeFileSpecification : IDownloadDecisionEngineSpecification
{
private readonly IDiskProvider _diskProvider;
private readonly IConfigService _configService;
@@ -26,17 +26,17 @@ namespace NzbDrone.Core.DecisionEngine.Specifications.RssSync
public SpecificationPriority Priority => SpecificationPriority.Disk;
public RejectionType Type => RejectionType.Temporary;
public virtual Decision IsSatisfiedBy(RemoteEpisode subject, SearchCriteriaBase searchCriteria)
public virtual DownloadSpecDecision IsSatisfiedBy(RemoteEpisode subject, SearchCriteriaBase searchCriteria)
{
if (!_configService.AutoUnmonitorPreviouslyDownloadedEpisodes)
{
return Decision.Accept();
return DownloadSpecDecision.Accept();
}
if (searchCriteria != null)
{
_logger.Debug("Skipping deleted episodefile check during search");
return Decision.Accept();
return DownloadSpecDecision.Accept();
}
var missingEpisodeFiles = subject.Episodes
@@ -54,10 +54,10 @@ namespace NzbDrone.Core.DecisionEngine.Specifications.RssSync
}
_logger.Debug("Files for this episode exist in the database but not on disk, will be unmonitored on next diskscan. skipping.");
return Decision.Reject("Series is not monitored");
return DownloadSpecDecision.Reject(DownloadRejectionReason.SeriesNotMonitored, "Series is not monitored");
}
return Decision.Accept();
return DownloadSpecDecision.Accept();
}
private bool IsEpisodeFileMissing(Series series, EpisodeFile episodeFile)
@@ -9,7 +9,7 @@ using NzbDrone.Core.Parser.Model;
namespace NzbDrone.Core.DecisionEngine.Specifications.RssSync
{
public class HistorySpecification : IDecisionEngineSpecification
public class HistorySpecification : IDownloadDecisionEngineSpecification
{
private readonly IHistoryService _historyService;
private readonly UpgradableSpecification _upgradableSpecification;
@@ -33,12 +33,12 @@ namespace NzbDrone.Core.DecisionEngine.Specifications.RssSync
public SpecificationPriority Priority => SpecificationPriority.Database;
public RejectionType Type => RejectionType.Permanent;
public virtual Decision IsSatisfiedBy(RemoteEpisode subject, SearchCriteriaBase searchCriteria)
public virtual DownloadSpecDecision IsSatisfiedBy(RemoteEpisode subject, SearchCriteriaBase searchCriteria)
{
if (searchCriteria != null)
{
_logger.Debug("Skipping history check during search");
return Decision.Accept();
return DownloadSpecDecision.Accept();
}
var cdhEnabled = _configService.EnableCompletedDownloadHandling;
@@ -81,10 +81,10 @@ namespace NzbDrone.Core.DecisionEngine.Specifications.RssSync
{
if (recent)
{
return Decision.Reject("Recent grab event in history already meets cutoff: {0}", mostRecent.Quality);
return DownloadSpecDecision.Reject(DownloadRejectionReason.HistoryRecentCutoffMet, "Recent grab event in history already meets cutoff: {0}", mostRecent.Quality);
}
return Decision.Reject("CDH is disabled and grab event in history already meets cutoff: {0}", mostRecent.Quality);
return DownloadSpecDecision.Reject(DownloadRejectionReason.HistoryCdhDisabledCutoffMet, "CDH is disabled and grab event in history already meets cutoff: {0}", mostRecent.Quality);
}
var rejectionSubject = recent ? "Recent" : "CDH is disabled and";
@@ -95,27 +95,27 @@ namespace NzbDrone.Core.DecisionEngine.Specifications.RssSync
continue;
case UpgradeableRejectReason.BetterQuality:
return Decision.Reject("{0} grab event in history is of equal or higher preference: {1}", rejectionSubject, mostRecent.Quality);
return DownloadSpecDecision.Reject(DownloadRejectionReason.HistoryHigherPreference, "{0} grab event in history is of equal or higher preference: {1}", rejectionSubject, mostRecent.Quality);
case UpgradeableRejectReason.BetterRevision:
return Decision.Reject("{0} grab event in history is of equal or higher revision: {1}", rejectionSubject, mostRecent.Quality.Revision);
return DownloadSpecDecision.Reject(DownloadRejectionReason.HistoryHigherRevision, "{0} grab event in history is of equal or higher revision: {1}", rejectionSubject, mostRecent.Quality.Revision);
case UpgradeableRejectReason.QualityCutoff:
return Decision.Reject("{0} grab event in history meets quality cutoff: {1}", rejectionSubject, qualityProfile.Items[qualityProfile.GetIndex(qualityProfile.Cutoff).Index]);
return DownloadSpecDecision.Reject(DownloadRejectionReason.HistoryCutoffMet, "{0} grab event in history meets quality cutoff: {1}", rejectionSubject, qualityProfile.Items[qualityProfile.GetIndex(qualityProfile.Cutoff).Index]);
case UpgradeableRejectReason.CustomFormatCutoff:
return Decision.Reject("{0} grab event in history meets Custom Format cutoff: {1}", rejectionSubject, qualityProfile.CutoffFormatScore);
return DownloadSpecDecision.Reject(DownloadRejectionReason.HistoryCustomFormatCutoffMet, "{0} grab event in history meets Custom Format cutoff: {1}", rejectionSubject, qualityProfile.CutoffFormatScore);
case UpgradeableRejectReason.CustomFormatScore:
return Decision.Reject("{0} grab event in history has an equal or higher Custom Format score: {1}", rejectionSubject, qualityProfile.CalculateCustomFormatScore(customFormats));
return DownloadSpecDecision.Reject(DownloadRejectionReason.HistoryCustomFormatScore, "{0} grab event in history has an equal or higher Custom Format score: {1}", rejectionSubject, qualityProfile.CalculateCustomFormatScore(customFormats));
case UpgradeableRejectReason.MinCustomFormatScore:
return Decision.Reject("{0} grab event in history has Custom Format score within Custom Format score increment: {1}", rejectionSubject, qualityProfile.MinUpgradeFormatScore);
return DownloadSpecDecision.Reject(DownloadRejectionReason.HistoryCustomFormatScoreIncrement, "{0} grab event in history has Custom Format score within Custom Format score increment: {1}", rejectionSubject, qualityProfile.MinUpgradeFormatScore);
}
}
}
return Decision.Accept();
return DownloadSpecDecision.Accept();
}
}
}
@@ -8,7 +8,7 @@ using NzbDrone.Core.Parser.Model;
namespace NzbDrone.Core.DecisionEngine.Specifications.RssSync
{
public class IndexerTagSpecification : IDecisionEngineSpecification
public class IndexerTagSpecification : IDownloadDecisionEngineSpecification
{
private readonly Logger _logger;
private readonly IIndexerFactory _indexerFactory;
@@ -22,11 +22,11 @@ namespace NzbDrone.Core.DecisionEngine.Specifications.RssSync
public SpecificationPriority Priority => SpecificationPriority.Default;
public RejectionType Type => RejectionType.Permanent;
public virtual Decision IsSatisfiedBy(RemoteEpisode subject, SearchCriteriaBase searchCriteria)
public virtual DownloadSpecDecision IsSatisfiedBy(RemoteEpisode subject, SearchCriteriaBase searchCriteria)
{
if (subject.Release == null || subject.Series?.Tags == null || subject.Release.IndexerId == 0)
{
return Decision.Accept();
return DownloadSpecDecision.Accept();
}
IndexerDefinition indexer;
@@ -37,7 +37,7 @@ namespace NzbDrone.Core.DecisionEngine.Specifications.RssSync
catch (ModelNotFoundException)
{
_logger.Debug("Indexer with id {0} does not exist, skipping indexer tags check", subject.Release.IndexerId);
return Decision.Accept();
return DownloadSpecDecision.Accept();
}
// If indexer has tags, check that at least one of them is present on the series
@@ -47,10 +47,10 @@ namespace NzbDrone.Core.DecisionEngine.Specifications.RssSync
{
_logger.Debug("Indexer {0} has tags. None of these are present on series {1}. Rejecting", subject.Release.Indexer, subject.Series);
return Decision.Reject("Series tags do not match any of the indexer tags");
return DownloadSpecDecision.Reject(DownloadRejectionReason.NoMatchingTag, "Series tags do not match any of the indexer tags");
}
return Decision.Accept();
return DownloadSpecDecision.Accept();
}
}
}
@@ -5,7 +5,7 @@ using NzbDrone.Core.Parser.Model;
namespace NzbDrone.Core.DecisionEngine.Specifications.RssSync
{
public class MonitoredEpisodeSpecification : IDecisionEngineSpecification
public class MonitoredEpisodeSpecification : IDownloadDecisionEngineSpecification
{
private readonly Logger _logger;
@@ -17,33 +17,33 @@ namespace NzbDrone.Core.DecisionEngine.Specifications.RssSync
public SpecificationPriority Priority => SpecificationPriority.Default;
public RejectionType Type => RejectionType.Permanent;
public virtual Decision IsSatisfiedBy(RemoteEpisode subject, SearchCriteriaBase searchCriteria)
public virtual DownloadSpecDecision IsSatisfiedBy(RemoteEpisode subject, SearchCriteriaBase searchCriteria)
{
if (searchCriteria != null)
{
if (!searchCriteria.MonitoredEpisodesOnly)
{
_logger.Debug("Skipping monitored check during search");
return Decision.Accept();
return DownloadSpecDecision.Accept();
}
}
if (!subject.Series.Monitored)
{
_logger.Debug("{0} is present in the DB but not tracked. Rejecting", subject.Series);
return Decision.Reject("Series is not monitored");
return DownloadSpecDecision.Reject(DownloadRejectionReason.SeriesNotMonitored, "Series is not monitored");
}
var monitoredCount = subject.Episodes.Count(episode => episode.Monitored);
if (monitoredCount == subject.Episodes.Count)
{
return Decision.Accept();
return DownloadSpecDecision.Accept();
}
if (subject.Episodes.Count == 1)
{
_logger.Debug("Episode is not monitored. Rejecting", monitoredCount, subject.Episodes.Count);
return Decision.Reject("Episode is not monitored");
return DownloadSpecDecision.Reject(DownloadRejectionReason.EpisodeNotMonitored, "Episode is not monitored");
}
if (monitoredCount == 0)
@@ -55,7 +55,7 @@ namespace NzbDrone.Core.DecisionEngine.Specifications.RssSync
_logger.Debug("Only {0}/{1} episodes in the release are monitored. Rejecting", monitoredCount, subject.Episodes.Count);
}
return Decision.Reject("One or more episodes is not monitored");
return DownloadSpecDecision.Reject(DownloadRejectionReason.EpisodeNotMonitored, "One or more episodes is not monitored");
}
}
}
@@ -8,7 +8,7 @@ using NzbDrone.Core.Qualities;
namespace NzbDrone.Core.DecisionEngine.Specifications.RssSync
{
public class ProperSpecification : IDecisionEngineSpecification
public class ProperSpecification : IDownloadDecisionEngineSpecification
{
private readonly UpgradableSpecification _upgradableSpecification;
private readonly IConfigService _configService;
@@ -24,11 +24,11 @@ namespace NzbDrone.Core.DecisionEngine.Specifications.RssSync
public SpecificationPriority Priority => SpecificationPriority.Default;
public RejectionType Type => RejectionType.Permanent;
public virtual Decision IsSatisfiedBy(RemoteEpisode subject, SearchCriteriaBase searchCriteria)
public virtual DownloadSpecDecision IsSatisfiedBy(RemoteEpisode subject, SearchCriteriaBase searchCriteria)
{
if (searchCriteria != null)
{
return Decision.Accept();
return DownloadSpecDecision.Accept();
}
var downloadPropersAndRepacks = _configService.DownloadPropersAndRepacks;
@@ -36,7 +36,7 @@ namespace NzbDrone.Core.DecisionEngine.Specifications.RssSync
if (downloadPropersAndRepacks == ProperDownloadTypes.DoNotPrefer)
{
_logger.Debug("Propers are not preferred, skipping check");
return Decision.Accept();
return DownloadSpecDecision.Accept();
}
foreach (var file in subject.Episodes.Where(c => c.EpisodeFileId != 0).Select(c => c.EpisodeFile.Value))
@@ -46,18 +46,18 @@ namespace NzbDrone.Core.DecisionEngine.Specifications.RssSync
if (downloadPropersAndRepacks == ProperDownloadTypes.DoNotUpgrade)
{
_logger.Debug("Auto downloading of propers is disabled");
return Decision.Reject("Proper downloading is disabled");
return DownloadSpecDecision.Reject(DownloadRejectionReason.PropersDisabled, "Proper downloading is disabled");
}
if (file.DateAdded < DateTime.Today.AddDays(-7))
{
_logger.Debug("Proper for old file, rejecting: {0}", subject);
return Decision.Reject("Proper for old file");
return DownloadSpecDecision.Reject(DownloadRejectionReason.ProperForOldFile, "Proper for old file");
}
}
}
return Decision.Accept();
return DownloadSpecDecision.Accept();
}
}
}