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