1
0
mirror of https://github.com/Sonarr/Sonarr.git synced 2024-11-01 08:22:35 +01:00
Sonarr/NzbDrone.Core/DecisionEngine/Specifications/UpgradeDiskSpecification.cs

49 lines
1.5 KiB
C#
Raw Normal View History

using System;
using System.Linq;
using NLog;
using NzbDrone.Core.Parser.Model;
namespace NzbDrone.Core.DecisionEngine.Specifications
{
2013-04-07 09:30:37 +02:00
public class UpgradeDiskSpecification : IDecisionEngineSpecification
{
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";
}
}
public virtual bool IsSatisfiedBy(RemoteEpisode subject)
{
foreach (var file in subject.Episodes.Select(c => c.EpisodeFile).Where(c => c != null))
{
2013-04-01 08:22:16 +02:00
_logger.Trace("Comparing file quality with report. Existing file is {0}", file.Quality);
if (!_qualityUpgradableSpecification.IsUpgradable(subject.Series.QualityProfile, file.Quality, subject.ParsedEpisodeInfo.Quality))
{
return false;
}
if (subject.ParsedEpisodeInfo.Quality.Proper && file.DateAdded < DateTime.Today.AddDays(-7))
{
_logger.Trace("Proper for old file, skipping: {0}", subject);
return false;
}
}
return true;
}
}
}