2012-02-07 05:08:07 +00:00
|
|
|
|
using System.Linq;
|
|
|
|
|
using NLog;
|
2013-02-19 06:01:03 +00:00
|
|
|
|
using NzbDrone.Core.Tv;
|
2012-02-07 05:08:07 +00:00
|
|
|
|
using NzbDrone.Core.Model;
|
2013-02-19 02:19:38 +00:00
|
|
|
|
using NzbDrone.Core.Providers;
|
2012-02-07 05:08:07 +00:00
|
|
|
|
|
2013-02-19 02:19:38 +00:00
|
|
|
|
namespace NzbDrone.Core.DecisionEngine
|
2012-02-07 05:08:07 +00:00
|
|
|
|
{
|
|
|
|
|
public class UpgradeHistorySpecification
|
|
|
|
|
{
|
2013-02-20 02:05:15 +00:00
|
|
|
|
private readonly EpisodeService _episodeService;
|
2012-02-07 05:08:07 +00:00
|
|
|
|
private readonly HistoryProvider _historyProvider;
|
|
|
|
|
private readonly QualityUpgradeSpecification _qualityUpgradeSpecification;
|
|
|
|
|
private static readonly Logger logger = LogManager.GetCurrentClassLogger();
|
|
|
|
|
|
2013-02-20 02:05:15 +00:00
|
|
|
|
public UpgradeHistorySpecification(EpisodeService episodeService, HistoryProvider historyProvider, QualityUpgradeSpecification qualityUpgradeSpecification)
|
2012-02-07 05:08:07 +00:00
|
|
|
|
{
|
2013-02-20 02:05:15 +00:00
|
|
|
|
_episodeService = episodeService;
|
2012-02-07 05:08:07 +00:00
|
|
|
|
_historyProvider = historyProvider;
|
|
|
|
|
_qualityUpgradeSpecification = qualityUpgradeSpecification;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public UpgradeHistorySpecification()
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public virtual bool IsSatisfiedBy(EpisodeParseResult subject)
|
|
|
|
|
{
|
2012-10-17 07:39:06 +00:00
|
|
|
|
foreach (var episode in subject.Episodes)
|
2012-02-07 05:08:07 +00: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;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|