2012-02-07 06:08:07 +01:00
|
|
|
|
using System.Linq;
|
|
|
|
|
using NLog;
|
2013-02-23 22:29:22 +01:00
|
|
|
|
using NzbDrone.Core.History;
|
2012-02-07 06:08:07 +01:00
|
|
|
|
using NzbDrone.Core.Model;
|
2013-02-19 03:19:38 +01:00
|
|
|
|
using NzbDrone.Core.Providers;
|
2012-02-07 06:08:07 +01:00
|
|
|
|
|
2013-02-19 03:19:38 +01:00
|
|
|
|
namespace NzbDrone.Core.DecisionEngine
|
2012-02-07 06:08:07 +01:00
|
|
|
|
{
|
|
|
|
|
public class UpgradeHistorySpecification
|
|
|
|
|
{
|
2013-02-24 21:24:31 +01:00
|
|
|
|
private readonly IHistoryService _historyService;
|
2012-02-07 06:08:07 +01:00
|
|
|
|
private readonly QualityUpgradeSpecification _qualityUpgradeSpecification;
|
|
|
|
|
private static readonly Logger logger = LogManager.GetCurrentClassLogger();
|
|
|
|
|
|
2013-02-24 21:24:31 +01:00
|
|
|
|
public UpgradeHistorySpecification(IHistoryService historyService, QualityUpgradeSpecification qualityUpgradeSpecification)
|
2012-02-07 06:08:07 +01:00
|
|
|
|
{
|
2013-02-23 22:29:22 +01:00
|
|
|
|
_historyService = historyService;
|
2012-02-07 06:08:07 +01:00
|
|
|
|
_qualityUpgradeSpecification = qualityUpgradeSpecification;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public UpgradeHistorySpecification()
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public virtual bool IsSatisfiedBy(EpisodeParseResult subject)
|
|
|
|
|
{
|
2012-10-17 09:39:06 +02:00
|
|
|
|
foreach (var episode in subject.Episodes)
|
2012-02-07 06:08:07 +01:00
|
|
|
|
{
|
2013-02-26 04:58:57 +01:00
|
|
|
|
var bestQualityInHistory = _historyService.GetBestQualityInHistory(subject.Series.Id, episode.SeasonNumber, episode.EpisodeNumber);
|
2012-02-07 06:08:07 +01:00
|
|
|
|
if (bestQualityInHistory != null)
|
|
|
|
|
{
|
|
|
|
|
logger.Trace("Comparing history quality with report. History is {0}", bestQualityInHistory);
|
|
|
|
|
if (!_qualityUpgradeSpecification.IsSatisfiedBy(bestQualityInHistory, subject.Quality, subject.Series.QualityProfile.Cutoff))
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|