1
0
Fork 0
mirror of https://github.com/lidarr/Lidarr synced 2024-12-27 10:07:10 +00:00
Lidarr/NzbDrone.Core/DecisionEngine/QualityUpgradableSpecification.cs

70 lines
2.1 KiB
C#
Raw Normal View History

using NLog;
using NzbDrone.Core.Qualities;
using NzbDrone.Core.Tv;
namespace NzbDrone.Core.DecisionEngine
{
public interface IQualityUpgradableSpecification
{
2013-09-11 02:07:22 +00:00
bool IsUpgradable(QualityModel currentQuality, QualityModel newQuality = null);
bool CutoffNotMet(QualityProfile profile, QualityModel currentQuality, QualityModel newQuality = null);
bool IsProperUpgrade(QualityModel currentQuality, QualityModel newQuality);
}
public class QualityUpgradableSpecification : IQualityUpgradableSpecification
{
private readonly Logger _logger;
public QualityUpgradableSpecification(Logger logger)
{
_logger = logger;
}
2013-09-11 02:07:22 +00:00
public bool IsUpgradable(QualityModel currentQuality, QualityModel newQuality = null)
{
if (newQuality != null)
{
if (currentQuality >= newQuality)
{
_logger.Trace("existing item has better or equal quality. skipping");
return false;
}
if (IsProperUpgrade(currentQuality, newQuality))
{
return true;
}
}
2013-09-11 02:07:22 +00:00
return true;
}
public bool CutoffNotMet(QualityProfile profile, QualityModel currentQuality, QualityModel newQuality = null)
{
if (currentQuality.Quality >= profile.Cutoff)
{
if (newQuality != null && IsProperUpgrade(currentQuality, newQuality))
{
return true;
}
_logger.Trace("Existing item meets cut-off. skipping.");
return false;
}
return true;
}
public bool IsProperUpgrade(QualityModel currentQuality, QualityModel newQuality)
{
if (currentQuality.Quality == newQuality.Quality && newQuality > currentQuality)
{
_logger.Trace("New quality is a proper for existing quality");
return true;
}
return false;
}
}
}