2013-03-07 00:19:49 +00:00
|
|
|
using NLog;
|
|
|
|
using NzbDrone.Core.History;
|
2013-08-07 03:18:05 +00:00
|
|
|
using NzbDrone.Core.IndexerSearch.Definitions;
|
2013-04-15 01:41:39 +00:00
|
|
|
using NzbDrone.Core.Parser.Model;
|
2013-03-07 00:19:49 +00:00
|
|
|
|
2013-08-12 06:00:40 +00:00
|
|
|
namespace NzbDrone.Core.DecisionEngine.Specifications.RssSync
|
2013-03-07 00:19:49 +00:00
|
|
|
{
|
2013-04-07 07:30:37 +00:00
|
|
|
public class UpgradeHistorySpecification : IDecisionEngineSpecification
|
2013-03-07 00:19:49 +00:00
|
|
|
{
|
|
|
|
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
|
|
|
|
{
|
|
|
|
return "Higher quality report exists in history";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-08-08 03:30:20 +00:00
|
|
|
public virtual bool IsSatisfiedBy(RemoteEpisode subject, SearchCriteriaBase searchCriteria)
|
2013-03-07 00:19:49 +00:00
|
|
|
{
|
2013-08-08 03:30:20 +00:00
|
|
|
if (searchCriteria != null)
|
|
|
|
{
|
|
|
|
_logger.Trace("Skipping history check during search");
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2013-03-07 00:19:49 +00:00
|
|
|
foreach (var episode in subject.Episodes)
|
|
|
|
{
|
2013-03-25 01:38:11 +00:00
|
|
|
var bestQualityInHistory = _historyService.GetBestQualityInHistory(episode.Id);
|
2013-03-07 00:19:49 +00:00
|
|
|
if (bestQualityInHistory != null)
|
|
|
|
{
|
|
|
|
_logger.Trace("Comparing history quality with report. History is {0}", bestQualityInHistory);
|
2013-04-28 19:46:13 +00:00
|
|
|
if (!_qualityUpgradableSpecification.IsUpgradable(subject.Series.QualityProfile, bestQualityInHistory, subject.ParsedEpisodeInfo.Quality))
|
2013-03-07 00:19:49 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|