1
0
mirror of https://github.com/Sonarr/Sonarr.git synced 2026-04-23 22:25:56 -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
@@ -23,14 +23,14 @@ namespace NzbDrone.Core.DecisionEngine
public class DownloadDecisionMaker : IMakeDownloadDecision
{
private readonly IEnumerable<IDecisionEngineSpecification> _specifications;
private readonly IEnumerable<IDownloadDecisionEngineSpecification> _specifications;
private readonly IParsingService _parsingService;
private readonly ICustomFormatCalculationService _formatCalculator;
private readonly IRemoteEpisodeAggregationService _aggregationService;
private readonly ISceneMappingService _sceneMappingService;
private readonly Logger _logger;
public DownloadDecisionMaker(IEnumerable<IDecisionEngineSpecification> specifications,
public DownloadDecisionMaker(IEnumerable<IDownloadDecisionEngineSpecification> specifications,
IParsingService parsingService,
ICustomFormatCalculationService formatService,
IRemoteEpisodeAggregationService aggregationService,
@@ -95,19 +95,20 @@ namespace NzbDrone.Core.DecisionEngine
if (remoteEpisode.Series == null)
{
var reason = "Unknown Series";
var matchingTvdbId = _sceneMappingService.FindTvdbId(parsedEpisodeInfo.SeriesTitle, parsedEpisodeInfo.ReleaseTitle, parsedEpisodeInfo.SeasonNumber);
if (matchingTvdbId.HasValue)
{
reason = $"{parsedEpisodeInfo.SeriesTitle} matches an alias for series with TVDB ID: {matchingTvdbId}";
decision = new DownloadDecision(remoteEpisode, new DownloadRejection(DownloadRejectionReason.MatchesAnotherSeries, $"{parsedEpisodeInfo.SeriesTitle} matches an alias for series with TVDB ID: {matchingTvdbId}"));
}
else
{
decision = new DownloadDecision(remoteEpisode, new DownloadRejection(DownloadRejectionReason.UnknownSeries, "Unknown Series"));
}
decision = new DownloadDecision(remoteEpisode, new Rejection(reason));
}
else if (remoteEpisode.Episodes.Empty())
{
decision = new DownloadDecision(remoteEpisode, new Rejection("Unable to identify correct episode(s) using release name and scene mappings"));
decision = new DownloadDecision(remoteEpisode, new DownloadRejection(DownloadRejectionReason.UnknownEpisode, "Unable to identify correct episode(s) using release name and scene mappings"));
}
else
{
@@ -141,7 +142,7 @@ namespace NzbDrone.Core.DecisionEngine
Languages = parsedEpisodeInfo.Languages
};
decision = new DownloadDecision(remoteEpisode, new Rejection("Unable to parse release"));
decision = new DownloadDecision(remoteEpisode, new DownloadRejection(DownloadRejectionReason.UnableToParse, "Unable to parse release"));
}
}
}
@@ -150,7 +151,7 @@ namespace NzbDrone.Core.DecisionEngine
_logger.Error(e, "Couldn't process release.");
var remoteEpisode = new RemoteEpisode { Release = report };
decision = new DownloadDecision(remoteEpisode, new Rejection("Unexpected error processing release"));
decision = new DownloadDecision(remoteEpisode, new DownloadRejection(DownloadRejectionReason.Error, "Unexpected error processing release"));
}
reportNumber++;
@@ -193,7 +194,7 @@ namespace NzbDrone.Core.DecisionEngine
private DownloadDecision GetDecisionForReport(RemoteEpisode remoteEpisode, SearchCriteriaBase searchCriteria = null)
{
var reasons = Array.Empty<Rejection>();
var reasons = Array.Empty<DownloadRejection>();
foreach (var specifications in _specifications.GroupBy(v => v.Priority).OrderBy(v => v.Key))
{
@@ -210,7 +211,7 @@ namespace NzbDrone.Core.DecisionEngine
return new DownloadDecision(remoteEpisode, reasons.ToArray());
}
private Rejection EvaluateSpec(IDecisionEngineSpecification spec, RemoteEpisode remoteEpisode, SearchCriteriaBase searchCriteriaBase = null)
private DownloadRejection EvaluateSpec(IDownloadDecisionEngineSpecification spec, RemoteEpisode remoteEpisode, SearchCriteriaBase searchCriteriaBase = null)
{
try
{
@@ -218,7 +219,7 @@ namespace NzbDrone.Core.DecisionEngine
if (!result.Accepted)
{
return new Rejection(result.Reason, spec.Type);
return new DownloadRejection(result.Reason, result.Message, spec.Type);
}
}
catch (Exception e)
@@ -226,7 +227,7 @@ namespace NzbDrone.Core.DecisionEngine
e.Data.Add("report", remoteEpisode.Release.ToJson());
e.Data.Add("parsed", remoteEpisode.ParsedEpisodeInfo.ToJson());
_logger.Error(e, "Couldn't evaluate decision on {0}", remoteEpisode.Release.Title);
return new Rejection($"{spec.GetType().Name}: {e.Message}");
return new DownloadRejection(DownloadRejectionReason.DecisionError, $"{spec.GetType().Name}: {e.Message}");
}
return null;