You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
72 lines
2.1 KiB
72 lines
2.1 KiB
using System;
|
|
using NLog;
|
|
using NzbDrone.Core.Configuration;
|
|
using NzbDrone.Core.Qualities;
|
|
using NzbDrone.Core.Tv;
|
|
|
|
namespace NzbDrone.Core.DecisionEngine
|
|
{
|
|
public interface IQualityUpgradableSpecification
|
|
{
|
|
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;
|
|
}
|
|
|
|
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;
|
|
}
|
|
}
|
|
|
|
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;
|
|
}
|
|
}
|
|
}
|