1
0
mirror of https://github.com/Sonarr/Sonarr.git synced 2024-12-29 02:57:15 +02:00
Sonarr/NzbDrone.Core/DecisionEngine/Specifications/RssSync/UpgradeHistorySpecification.cs

52 lines
1.8 KiB
C#
Raw Normal View History

using NLog;
using NzbDrone.Core.History;
using NzbDrone.Core.IndexerSearch.Definitions;
using NzbDrone.Core.Parser.Model;
namespace NzbDrone.Core.DecisionEngine.Specifications.RssSync
{
2013-04-07 10:30:37 +03:00
public class UpgradeHistorySpecification : IDecisionEngineSpecification
{
private readonly IHistoryService _historyService;
private readonly QualityUpgradableSpecification _qualityUpgradableSpecification;
private readonly Logger _logger;
public UpgradeHistorySpecification(IHistoryService historyService, QualityUpgradableSpecification qualityUpgradableSpecification, Logger logger)
{
_historyService = historyService;
_qualityUpgradableSpecification = qualityUpgradableSpecification;
_logger = logger;
}
public string RejectionReason
{
get
{
2013-09-11 05:07:22 +03:00
return "Existing file in history is of equal or higher quality";
}
}
public virtual bool IsSatisfiedBy(RemoteEpisode subject, SearchCriteriaBase searchCriteria)
{
if (searchCriteria != null)
{
_logger.Trace("Skipping history check during search");
return true;
}
foreach (var episode in subject.Episodes)
{
2013-03-25 04:38:11 +03:00
var bestQualityInHistory = _historyService.GetBestQualityInHistory(episode.Id);
if (bestQualityInHistory != null)
{
_logger.Trace("Comparing history quality with report. History is {0}", bestQualityInHistory);
2013-09-11 05:07:22 +03:00
if (!_qualityUpgradableSpecification.IsUpgradable(bestQualityInHistory, subject.ParsedEpisodeInfo.Quality))
return false;
}
}
return true;
}
}
}