Indexes are created with the same uniqueness when copying a table

New: Non-English episode support
New: Renamed Quality Profiles to Profiles and made them more powerful
New: Configurable wait time before grabbing a release to wait for a better quality
This commit is contained in:
Mark McDowall
2014-06-08 01:22:55 -07:00
parent b72678a9ad
commit 74a38415cf
182 changed files with 2493 additions and 2433 deletions
@@ -1,3 +1,4 @@
using System;
using System.Linq;
using NLog;
using NzbDrone.Core.IndexerSearch.Definitions;
@@ -21,12 +22,14 @@ namespace NzbDrone.Core.DecisionEngine.Specifications
_logger = logger;
}
public string RejectionReason
public String RejectionReason
{
get { return "File size too big or small"; }
}
public virtual bool IsSatisfiedBy(RemoteEpisode subject, SearchCriteriaBase searchCriteria)
public RejectionType Type { get { return RejectionType.Permanent; } }
public bool IsSatisfiedBy(RemoteEpisode subject, SearchCriteriaBase searchCriteria)
{
_logger.Debug("Beginning size check for: {0}", subject);
@@ -27,6 +27,8 @@ namespace NzbDrone.Core.DecisionEngine.Specifications
}
}
public RejectionType Type { get { return RejectionType.Permanent; } }
public bool IsSatisfiedBy(RemoteEpisode subject, SearchCriteriaBase searchCriteria)
{
if (!_configService.EnableFailedDownloadHandling)
@@ -24,6 +24,8 @@ namespace NzbDrone.Core.DecisionEngine.Specifications
}
}
public RejectionType Type { get { return RejectionType.Permanent; } }
public virtual bool IsSatisfiedBy(RemoteEpisode subject, SearchCriteriaBase searchCriteria)
{
foreach (var file in subject.Episodes.Where(c => c.EpisodeFileId != 0).Select(c => c.EpisodeFile.Value))
@@ -31,7 +33,7 @@ namespace NzbDrone.Core.DecisionEngine.Specifications
_logger.Debug("Comparing file quality with report. Existing file is {0}", file.Quality);
if (!_qualityUpgradableSpecification.CutoffNotMet(subject.Series.QualityProfile, file.Quality, subject.ParsedEpisodeInfo.Quality))
if (!_qualityUpgradableSpecification.CutoffNotMet(subject.Series.Profile, file.Quality, subject.ParsedEpisodeInfo.Quality))
{
_logger.Debug("Cutoff already met, rejecting.");
return false;
@@ -1,37 +0,0 @@
using System.Collections.Generic;
using System.Linq;
using NzbDrone.Core.Parser.Model;
namespace NzbDrone.Core.DecisionEngine.Specifications
{
public class DownloadDecision
{
public RemoteEpisode RemoteEpisode { get; private set; }
public IEnumerable<string> Rejections { get; private set; }
public bool Approved
{
get
{
return !Rejections.Any();
}
}
public DownloadDecision(RemoteEpisode episode, params string[] rejections)
{
RemoteEpisode = episode;
Rejections = rejections.ToList();
}
public override string ToString()
{
if (Approved)
{
return "[OK] " + RemoteEpisode;
}
return "[Rejected " + Rejections.Count() + "]" + RemoteEpisode;
}
}
}
@@ -1,6 +1,5 @@
using NLog;
using NzbDrone.Core.IndexerSearch.Definitions;
using NzbDrone.Core.Parser;
using NzbDrone.Core.Parser.Model;
namespace NzbDrone.Core.DecisionEngine.Specifications
@@ -18,16 +17,21 @@ namespace NzbDrone.Core.DecisionEngine.Specifications
{
get
{
return "Not English";
return "Language is not wanted";
}
}
public RejectionType Type { get { return RejectionType.Permanent; } }
public virtual bool IsSatisfiedBy(RemoteEpisode subject, SearchCriteriaBase searchCriteria)
{
var wantedLanguage = subject.Series.Profile.Value.Language;
_logger.Debug("Checking if report meets language requirements. {0}", subject.ParsedEpisodeInfo.Language);
if (subject.ParsedEpisodeInfo.Language != Language.English)
if (subject.ParsedEpisodeInfo.Language != wantedLanguage)
{
_logger.Debug("Report Language: {0} rejected because it is not English", subject.ParsedEpisodeInfo.Language);
_logger.Debug("Report Language: {0} rejected because it is not wanted, wanted {1}", subject.ParsedEpisodeInfo.Language, wantedLanguage);
return false;
}
@@ -28,6 +28,8 @@ namespace NzbDrone.Core.DecisionEngine.Specifications
}
}
public RejectionType Type { get { return RejectionType.Permanent; } }
public bool IsSatisfiedBy(RemoteEpisode subject, SearchCriteriaBase searchCriteria)
{
var queue = _downloadTrackingService.GetQueuedDownloads()
@@ -46,7 +48,7 @@ namespace NzbDrone.Core.DecisionEngine.Specifications
private bool IsInQueue(RemoteEpisode newEpisode, IEnumerable<RemoteEpisode> queue)
{
var matchingSeries = queue.Where(q => q.Series.Id == newEpisode.Series.Id);
var matchingSeriesAndQuality = matchingSeries.Where(q => new QualityModelComparer(q.Series.QualityProfile).Compare(q.ParsedEpisodeInfo.Quality, newEpisode.ParsedEpisodeInfo.Quality) >= 0);
var matchingSeriesAndQuality = matchingSeries.Where(q => new QualityModelComparer(q.Series.Profile).Compare(q.ParsedEpisodeInfo.Quality, newEpisode.ParsedEpisodeInfo.Quality) >= 0);
return matchingSeriesAndQuality.Any(q => q.Episodes.Select(e => e.Id).Intersect(newEpisode.Episodes.Select(e => e.Id)).Any());
}
@@ -25,6 +25,8 @@ namespace NzbDrone.Core.DecisionEngine.Specifications
}
}
public RejectionType Type { get { return RejectionType.Permanent; } }
public virtual bool IsSatisfiedBy(RemoteEpisode subject, SearchCriteriaBase searchCriteria)
{
_logger.Debug("Checking if release contains any restricted terms: {0}", subject);
@@ -7,7 +7,9 @@ namespace NzbDrone.Core.DecisionEngine.Specifications
public class NotSampleSpecification : IDecisionEngineSpecification
{
private readonly Logger _logger;
public string RejectionReason { get { return "Sample"; } }
public RejectionType Type { get { return RejectionType.Permanent; } }
public NotSampleSpecification(Logger logger)
{
@@ -21,10 +21,12 @@ namespace NzbDrone.Core.DecisionEngine.Specifications
}
}
public RejectionType Type { get { return RejectionType.Permanent; } }
public virtual bool IsSatisfiedBy(RemoteEpisode subject, SearchCriteriaBase searchCriteria)
{
_logger.Debug("Checking if report meets quality requirements. {0}", subject.ParsedEpisodeInfo.Quality);
if (!subject.Series.QualityProfile.Value.Items.Exists(v => v.Allowed && v.Quality == subject.ParsedEpisodeInfo.Quality.Quality))
if (!subject.Series.Profile.Value.Items.Exists(v => v.Allowed && v.Quality == subject.ParsedEpisodeInfo.Quality.Quality))
{
_logger.Debug("Quality {0} rejected by Series' quality profile", subject.ParsedEpisodeInfo.Quality);
return false;
@@ -25,6 +25,8 @@ namespace NzbDrone.Core.DecisionEngine.Specifications
}
}
public RejectionType Type { get { return RejectionType.Permanent; } }
public virtual bool IsSatisfiedBy(RemoteEpisode subject, SearchCriteriaBase searchCriteria)
{
var age = subject.Release.Age;
@@ -30,6 +30,8 @@ namespace NzbDrone.Core.DecisionEngine.Specifications
}
}
public RejectionType Type { get { return RejectionType.Permanent; } }
public bool IsSatisfiedBy(RemoteEpisode subject, SearchCriteriaBase searchCriteria)
{
if (!_configService.EnableFailedDownloadHandling)
@@ -0,0 +1,116 @@
using System.Linq;
using NLog;
using NzbDrone.Core.Download.Pending;
using NzbDrone.Core.IndexerSearch.Definitions;
using NzbDrone.Core.Parser.Model;
using NzbDrone.Core.Profiles;
using NzbDrone.Core.Qualities;
namespace NzbDrone.Core.DecisionEngine.Specifications.RssSync
{
public class DelaySpecification : IDecisionEngineSpecification
{
private readonly IPendingReleaseService _pendingReleaseService;
private readonly Logger _logger;
public DelaySpecification(IPendingReleaseService pendingReleaseService, Logger logger)
{
_pendingReleaseService = pendingReleaseService;
_logger = logger;
}
public string RejectionReason
{
get
{
return "Waiting for better quality release";
}
}
public RejectionType Type { get { return RejectionType.Temporary; } }
public virtual bool IsSatisfiedBy(RemoteEpisode subject, SearchCriteriaBase searchCriteria)
{
//How do we want to handle drone being off and the automatic search being triggered?
//TODO: Add a flag to the search to state it is a "scheduled" search
if (searchCriteria != null)
{
_logger.Debug("Ignore delay for searches");
return true;
}
var profile = subject.Series.Profile.Value;
if (profile.GrabDelay == 0)
{
_logger.Debug("Profile does not delay before download");
return true;
}
var comparer = new QualityModelComparer(profile);
if (subject.ParsedEpisodeInfo.Quality.Proper)
{
foreach (var file in subject.Episodes.Where(c => c.EpisodeFileId != 0).Select(c => c.EpisodeFile.Value))
{
if (comparer.Compare(subject.ParsedEpisodeInfo.Quality, file.Quality) > 0)
{
var properCompare = subject.ParsedEpisodeInfo.Quality.Proper.CompareTo(file.Quality.Proper);
if (subject.ParsedEpisodeInfo.Quality.Quality == file.Quality.Quality && properCompare > 0)
{
_logger.Debug("New quality is a proper for existing quality, skipping delay");
return true;
}
}
}
}
//If quality meets or exceeds the best allowed quality in the profile accept it immediately
var bestQualityInProfile = new QualityModel(profile.Items.Last(q => q.Allowed).Quality);
var bestCompare = comparer.Compare(subject.ParsedEpisodeInfo.Quality, bestQualityInProfile);
if (bestCompare >= 0)
{
_logger.Debug("Quality is highest in profile, will not delay");
return true;
}
if (profile.GrabDelayMode == GrabDelayMode.Cutoff)
{
var cutoff = new QualityModel(profile.Cutoff);
var cutoffCompare = comparer.Compare(subject.ParsedEpisodeInfo.Quality, cutoff);
if (cutoffCompare >= 0)
{
_logger.Debug("Quality meets or exceeds the cutoff, will not delay");
return true;
}
}
if (profile.GrabDelayMode == GrabDelayMode.First)
{
var episodeIds = subject.Episodes.Select(e => e.Id);
var oldest = _pendingReleaseService.GetPendingRemoteEpisodes(subject.Series.Id)
.Where(r => r.Episodes.Select(e => e.Id).Intersect(episodeIds).Any())
.OrderByDescending(p => p.Release.AgeHours)
.FirstOrDefault();
if (oldest != null && oldest.Release.AgeHours > profile.GrabDelay)
{
return true;
}
}
if (subject.Release.AgeHours < profile.GrabDelay)
{
_logger.Debug("Age ({0}) is less than delay {1}, delaying", subject.Release.AgeHours, profile.GrabDelay);
return false;
}
return true;
}
}
}
@@ -34,6 +34,8 @@ namespace NzbDrone.Core.DecisionEngine.Specifications.RssSync
}
}
public RejectionType Type { get { return RejectionType.Permanent; } }
public virtual bool IsSatisfiedBy(RemoteEpisode subject, SearchCriteriaBase searchCriteria)
{
if (searchCriteria != null)
@@ -63,11 +65,11 @@ namespace NzbDrone.Core.DecisionEngine.Specifications.RssSync
foreach (var episode in subject.Episodes)
{
var bestQualityInHistory = _historyService.GetBestQualityInHistory(subject.Series.QualityProfile, episode.Id);
var bestQualityInHistory = _historyService.GetBestQualityInHistory(subject.Series.Profile, episode.Id);
if (bestQualityInHistory != null)
{
_logger.Debug("Comparing history quality with report. History is {0}", bestQualityInHistory);
if (!_qualityUpgradableSpecification.IsUpgradable(subject.Series.QualityProfile, bestQualityInHistory, subject.ParsedEpisodeInfo.Quality))
if (!_qualityUpgradableSpecification.IsUpgradable(subject.Series.Profile, bestQualityInHistory, subject.ParsedEpisodeInfo.Quality))
return false;
}
}
@@ -22,6 +22,8 @@ namespace NzbDrone.Core.DecisionEngine.Specifications.RssSync
}
}
public RejectionType Type { get { return RejectionType.Permanent; } }
public virtual bool IsSatisfiedBy(RemoteEpisode subject, SearchCriteriaBase searchCriteria)
{
if (searchCriteria != null)
@@ -28,6 +28,8 @@ namespace NzbDrone.Core.DecisionEngine.Specifications.RssSync
}
}
public RejectionType Type { get { return RejectionType.Permanent; } }
public virtual bool IsSatisfiedBy(RemoteEpisode subject, SearchCriteriaBase searchCriteria)
{
if (searchCriteria != null)
@@ -23,6 +23,9 @@ namespace NzbDrone.Core.DecisionEngine.Specifications.Search
return "Episode doesn't match";
}
}
public RejectionType Type { get { return RejectionType.Permanent; } }
public bool IsSatisfiedBy(RemoteEpisode remoteEpisode, SearchCriteriaBase searchCriteria)
{
if (searchCriteria == null)
@@ -23,6 +23,8 @@ namespace NzbDrone.Core.DecisionEngine.Specifications.Search
}
}
public RejectionType Type { get { return RejectionType.Permanent; } }
public bool IsSatisfiedBy(RemoteEpisode remoteEpisode, SearchCriteriaBase searchCriteria)
{
if (searchCriteria == null)
@@ -21,6 +21,8 @@ namespace NzbDrone.Core.DecisionEngine.Specifications.Search
}
}
public RejectionType Type { get { return RejectionType.Permanent; } }
public bool IsSatisfiedBy(RemoteEpisode remoteEpisode, SearchCriteriaBase searchCriteria)
{
if (searchCriteria == null)
@@ -21,6 +21,8 @@ namespace NzbDrone.Core.DecisionEngine.Specifications.Search
}
}
public RejectionType Type { get { return RejectionType.Permanent; } }
public bool IsSatisfiedBy(RemoteEpisode remoteEpisode, SearchCriteriaBase searchCriteria)
{
if (searchCriteria == null)
@@ -22,6 +22,8 @@ namespace NzbDrone.Core.DecisionEngine.Specifications.Search
}
}
public RejectionType Type { get { return RejectionType.Permanent; } }
public bool IsSatisfiedBy(RemoteEpisode remoteEpisode, SearchCriteriaBase searchCriteria)
{
if (searchCriteria == null)
@@ -24,13 +24,15 @@ namespace NzbDrone.Core.DecisionEngine.Specifications
}
}
public RejectionType Type { get { return RejectionType.Permanent; } }
public virtual bool IsSatisfiedBy(RemoteEpisode subject, SearchCriteriaBase searchCriteria)
{
foreach (var file in subject.Episodes.Where(c => c.EpisodeFileId != 0).Select(c => c.EpisodeFile.Value))
{
_logger.Debug("Comparing file quality with report. Existing file is {0}", file.Quality);
if (!_qualityUpgradableSpecification.IsUpgradable(subject.Series.QualityProfile, file.Quality, subject.ParsedEpisodeInfo.Quality))
if (!_qualityUpgradableSpecification.IsUpgradable(subject.Series.Profile, file.Quality, subject.ParsedEpisodeInfo.Quality))
{
return false;
}