2013-09-11 05:07:22 +03:00
|
|
|
using System;
|
2013-03-07 03:19:49 +03:00
|
|
|
using NLog;
|
2013-08-12 09:00:40 +03:00
|
|
|
using NzbDrone.Core.Configuration;
|
2013-03-07 03:19:49 +03:00
|
|
|
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-03-07 03:19:49 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
public class QualityUpgradableSpecification : IQualityUpgradableSpecification
|
|
|
|
{
|
2013-08-12 09:00:40 +03:00
|
|
|
private readonly IConfigService _configService;
|
2013-03-07 03:19:49 +03:00
|
|
|
private readonly Logger _logger;
|
|
|
|
|
2013-08-12 09:00:40 +03:00
|
|
|
public QualityUpgradableSpecification(IConfigService configService, Logger logger)
|
2013-03-07 03:19:49 +03:00
|
|
|
{
|
2013-08-12 09:00:40 +03:00
|
|
|
_configService = configService;
|
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-08-12 09:00:40 +03:00
|
|
|
if (currentQuality.Quality == newQuality.Quality && newQuality.Proper && _configService.AutoDownloadPropers)
|
2013-03-07 03:19:49 +03:00
|
|
|
{
|
|
|
|
_logger.Trace("Upgrading existing item to proper.");
|
|
|
|
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)
|
|
|
|
{
|
|
|
|
_logger.Trace("Existing item meets cut-off. skipping.");
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|