2013-03-07 03:19:49 +03:00
|
|
|
using NLog;
|
|
|
|
using NzbDrone.Core.Qualities;
|
|
|
|
using NzbDrone.Core.Tv;
|
|
|
|
|
|
|
|
namespace NzbDrone.Core.DecisionEngine
|
|
|
|
{
|
|
|
|
public interface IQualityUpgradableSpecification
|
|
|
|
{
|
2013-09-11 05:07:22 +03:00
|
|
|
bool IsUpgradable(QualityModel currentQuality, QualityModel newQuality = null);
|
|
|
|
bool CutoffNotMet(QualityProfile profile, QualityModel currentQuality, QualityModel newQuality = null);
|
2013-09-11 08:45:08 +03:00
|
|
|
bool IsProperUpgrade(QualityModel currentQuality, QualityModel newQuality);
|
2013-03-07 03:19:49 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
public class QualityUpgradableSpecification : IQualityUpgradableSpecification
|
|
|
|
{
|
|
|
|
private readonly Logger _logger;
|
|
|
|
|
2013-09-11 08:45:08 +03:00
|
|
|
public QualityUpgradableSpecification(Logger logger)
|
2013-03-07 03:19:49 +03:00
|
|
|
{
|
|
|
|
_logger = logger;
|
|
|
|
}
|
|
|
|
|
2013-09-11 05:07:22 +03:00
|
|
|
public bool IsUpgradable(QualityModel currentQuality, QualityModel newQuality = null)
|
2013-03-07 03:19:49 +03:00
|
|
|
{
|
|
|
|
if (newQuality != null)
|
|
|
|
{
|
|
|
|
if (currentQuality >= newQuality)
|
|
|
|
{
|
|
|
|
_logger.Trace("existing item has better or equal quality. skipping");
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2013-09-11 08:45:08 +03:00
|
|
|
if (IsProperUpgrade(currentQuality, newQuality))
|
2013-03-07 03:19:49 +03:00
|
|
|
{
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-09-11 05:07:22 +03:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
public bool CutoffNotMet(QualityProfile profile, QualityModel currentQuality, QualityModel newQuality = null)
|
|
|
|
{
|
2013-03-07 03:19:49 +03:00
|
|
|
if (currentQuality.Quality >= profile.Cutoff)
|
|
|
|
{
|
2013-09-11 08:45:08 +03:00
|
|
|
if (newQuality != null && IsProperUpgrade(currentQuality, newQuality))
|
|
|
|
{
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2013-03-07 03:19:49 +03:00
|
|
|
_logger.Trace("Existing item meets cut-off. skipping.");
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
2013-09-11 08:45:08 +03:00
|
|
|
|
|
|
|
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;
|
|
|
|
}
|
2013-03-07 03:19:49 +03:00
|
|
|
}
|
|
|
|
}
|