2013-01-26 01:58:01 +03:00
|
|
|
using System;
|
|
|
|
using System.Linq;
|
2012-02-07 08:08:07 +03:00
|
|
|
using NLog;
|
|
|
|
using NzbDrone.Core.Model;
|
|
|
|
|
|
|
|
namespace NzbDrone.Core.Providers.DecisionEngine
|
|
|
|
{
|
|
|
|
public class UpgradeDiskSpecification
|
|
|
|
{
|
|
|
|
private readonly QualityUpgradeSpecification _qualityUpgradeSpecification;
|
|
|
|
private static readonly Logger logger = LogManager.GetCurrentClassLogger();
|
|
|
|
|
2013-01-26 01:58:01 +03:00
|
|
|
public UpgradeDiskSpecification(QualityUpgradeSpecification qualityUpgradeSpecification)
|
2012-02-07 08:08:07 +03:00
|
|
|
{
|
|
|
|
_qualityUpgradeSpecification = qualityUpgradeSpecification;
|
|
|
|
}
|
|
|
|
|
|
|
|
public UpgradeDiskSpecification()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
public virtual bool IsSatisfiedBy(EpisodeParseResult subject)
|
|
|
|
{
|
2012-10-17 10:39:06 +03:00
|
|
|
foreach (var file in subject.Episodes.Select(c => c.EpisodeFile).Where(c => c != null))
|
2012-02-07 08:08:07 +03:00
|
|
|
{
|
|
|
|
logger.Trace("Comparing file quality with report. Existing file is {0} proper:{1}", file.Quality, file.Proper);
|
2012-10-14 03:36:16 +03:00
|
|
|
if (!_qualityUpgradeSpecification.IsSatisfiedBy(new QualityModel { Quality = file.Quality, Proper = file.Proper }, subject.Quality, subject.Series.QualityProfile.Cutoff))
|
2012-02-07 08:08:07 +03:00
|
|
|
return false;
|
2013-01-26 01:58:01 +03:00
|
|
|
|
|
|
|
if(subject.Quality.Proper && file.DateAdded < DateTime.Today.AddDays(-7))
|
|
|
|
{
|
|
|
|
logger.Trace("Proper for old file, skipping: {0}", subject);
|
|
|
|
return false;
|
|
|
|
}
|
2012-02-07 08:08:07 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|