2013-03-07 01:19:49 +01:00
|
|
|
using System;
|
|
|
|
using System.Linq;
|
|
|
|
using NLog;
|
2013-08-07 05:18:05 +02:00
|
|
|
using NzbDrone.Core.IndexerSearch.Definitions;
|
2013-04-15 03:41:39 +02:00
|
|
|
using NzbDrone.Core.Parser.Model;
|
2013-03-07 01:19:49 +01:00
|
|
|
|
|
|
|
namespace NzbDrone.Core.DecisionEngine.Specifications
|
|
|
|
{
|
2013-04-07 09:30:37 +02:00
|
|
|
public class UpgradeDiskSpecification : IDecisionEngineSpecification
|
2013-03-07 01:19:49 +01: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-08-08 05:30:20 +02:00
|
|
|
public virtual bool IsSatisfiedBy(RemoteEpisode subject, SearchCriteriaBase searchCriteria)
|
2013-03-07 01:19:49 +01:00
|
|
|
{
|
2013-05-13 02:36:23 +02:00
|
|
|
foreach (var file in subject.Episodes.Where(c => c.EpisodeFileId != 0).Select(c => c.EpisodeFile.Value))
|
2013-03-07 01:19:49 +01:00
|
|
|
{
|
2013-04-01 08:22:16 +02:00
|
|
|
_logger.Trace("Comparing file quality with report. Existing file is {0}", file.Quality);
|
2013-04-15 03:41:39 +02:00
|
|
|
|
2013-04-28 21:46:13 +02:00
|
|
|
if (!_qualityUpgradableSpecification.IsUpgradable(subject.Series.QualityProfile, file.Quality, subject.ParsedEpisodeInfo.Quality))
|
2013-04-15 03:41:39 +02:00
|
|
|
{
|
2013-03-07 01:19:49 +01:00
|
|
|
return false;
|
2013-04-15 03:41:39 +02:00
|
|
|
}
|
2013-03-07 01:19:49 +01:00
|
|
|
|
2013-08-24 06:05:37 +02:00
|
|
|
if (searchCriteria == null &&
|
|
|
|
subject.ParsedEpisodeInfo.Quality.Quality == file.Quality.Quality &&
|
|
|
|
subject.ParsedEpisodeInfo.Quality.Proper &&
|
|
|
|
file.DateAdded < DateTime.Today.AddDays(-7))
|
2013-03-07 01:19:49 +01:00
|
|
|
{
|
|
|
|
_logger.Trace("Proper for old file, skipping: {0}", subject);
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|