1
0
mirror of https://github.com/Sonarr/Sonarr.git synced 2024-12-16 11:37:58 +02:00
Sonarr/NzbDrone.Core/DecisionEngine/UpgradeHistorySpecification.cs

43 lines
1.5 KiB
C#
Raw Normal View History

using System.Linq;
using NLog;
2013-02-24 00:29:22 +03:00
using NzbDrone.Core.History;
using NzbDrone.Core.Model;
2013-02-19 05:19:38 +03:00
using NzbDrone.Core.Providers;
2013-02-19 05:19:38 +03:00
namespace NzbDrone.Core.DecisionEngine
{
public class UpgradeHistorySpecification
{
2013-02-24 23:24:31 +03:00
private readonly IHistoryService _historyService;
private readonly QualityUpgradeSpecification _qualityUpgradeSpecification;
private static readonly Logger logger = LogManager.GetCurrentClassLogger();
2013-02-24 23:24:31 +03:00
public UpgradeHistorySpecification(IHistoryService historyService, QualityUpgradeSpecification qualityUpgradeSpecification)
{
2013-02-24 00:29:22 +03:00
_historyService = historyService;
_qualityUpgradeSpecification = qualityUpgradeSpecification;
}
public UpgradeHistorySpecification()
{
}
public virtual bool IsSatisfiedBy(EpisodeParseResult subject)
{
foreach (var episode in subject.Episodes)
{
var bestQualityInHistory = _historyService.GetBestQualityInHistory(subject.Series.Id, 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;
}
}
}