2013-03-07 03:19:49 +03:00
|
|
|
using System;
|
|
|
|
using System.Linq;
|
|
|
|
using NLog;
|
|
|
|
using NzbDrone.Core.Model;
|
|
|
|
using NzbDrone.Core.Tv;
|
|
|
|
|
|
|
|
namespace NzbDrone.Core.DecisionEngine.Specifications
|
|
|
|
{
|
2013-04-07 10:30:37 +03:00
|
|
|
public class UpgradeDiskSpecification : IDecisionEngineSpecification
|
2013-03-07 03:19:49 +03:00
|
|
|
{
|
|
|
|
private readonly QualityUpgradableSpecification _qualityUpgradableSpecification;
|
|
|
|
private readonly Logger _logger;
|
|
|
|
|
|
|
|
public UpgradeDiskSpecification(QualityUpgradableSpecification qualityUpgradableSpecification, Logger logger)
|
|
|
|
{
|
|
|
|
_qualityUpgradableSpecification = qualityUpgradableSpecification;
|
|
|
|
_logger = logger;
|
|
|
|
}
|
|
|
|
|
|
|
|
public string RejectionReason
|
|
|
|
{
|
|
|
|
get
|
|
|
|
{
|
|
|
|
return "Higher quality exists on disk";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-04-07 22:01:24 +03:00
|
|
|
public virtual bool IsSatisfiedBy(IndexerParseResult subject)
|
2013-03-07 03:19:49 +03:00
|
|
|
{
|
|
|
|
foreach (var file in subject.Episodes.Select(c => c.EpisodeFile).Where(c => c != null))
|
|
|
|
{
|
2013-04-01 09:22:16 +03:00
|
|
|
_logger.Trace("Comparing file quality with report. Existing file is {0}", file.Quality);
|
|
|
|
if (!_qualityUpgradableSpecification.IsUpgradable(subject.Series.QualityProfile, file.Quality, subject.Quality))
|
2013-03-07 03:19:49 +03:00
|
|
|
return false;
|
|
|
|
|
|
|
|
if (subject.Quality.Proper && file.DateAdded < DateTime.Today.AddDays(-7))
|
|
|
|
{
|
|
|
|
_logger.Trace("Proper for old file, skipping: {0}", subject);
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|