2012-02-07 08:08:07 +03:00
|
|
|
using System.Linq;
|
|
|
|
using NLog;
|
|
|
|
using NzbDrone.Core.Model;
|
|
|
|
|
|
|
|
namespace NzbDrone.Core.Providers.DecisionEngine
|
|
|
|
{
|
|
|
|
public class UpgradeHistorySpecification
|
|
|
|
{
|
|
|
|
private readonly EpisodeProvider _episodeProvider;
|
|
|
|
private readonly HistoryProvider _historyProvider;
|
|
|
|
private readonly QualityUpgradeSpecification _qualityUpgradeSpecification;
|
|
|
|
private static readonly Logger logger = LogManager.GetCurrentClassLogger();
|
|
|
|
|
|
|
|
public UpgradeHistorySpecification(EpisodeProvider episodeProvider, HistoryProvider historyProvider, QualityUpgradeSpecification qualityUpgradeSpecification)
|
|
|
|
{
|
|
|
|
_episodeProvider = episodeProvider;
|
|
|
|
_historyProvider = historyProvider;
|
|
|
|
_qualityUpgradeSpecification = qualityUpgradeSpecification;
|
|
|
|
}
|
|
|
|
|
|
|
|
public UpgradeHistorySpecification()
|
|
|
|
{
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
public virtual bool IsSatisfiedBy(EpisodeParseResult subject)
|
|
|
|
{
|
2012-10-17 10:39:06 +03:00
|
|
|
foreach (var episode in subject.Episodes)
|
2012-02-07 08:08:07 +03:00
|
|
|
{
|
|
|
|
var bestQualityInHistory = _historyProvider.GetBestQualityInHistory(subject.Series.SeriesId, episode.SeasonNumber, episode.EpisodeNumber);
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|