1
0
mirror of https://github.com/Radarr/Radarr.git synced 2026-04-20 21:55:03 -04:00
Files
Radarr/src/NzbDrone.Core/DecisionEngine/Specifications/NotInQueueSpecification.cs
T
Mark McDowall 74a38415cf Profiles
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
2014-07-25 23:21:44 -07:00

57 lines
2.0 KiB
C#

using System.Collections.Generic;
using System.Linq;
using NLog;
using NzbDrone.Core.Download;
using NzbDrone.Core.IndexerSearch.Definitions;
using NzbDrone.Core.Parser.Model;
using NzbDrone.Core.Qualities;
using NzbDrone.Core.Queue;
namespace NzbDrone.Core.DecisionEngine.Specifications
{
public class NotInQueueSpecification : IDecisionEngineSpecification
{
private readonly IDownloadTrackingService _downloadTrackingService;
private readonly Logger _logger;
public NotInQueueSpecification(IDownloadTrackingService downloadTrackingService, Logger logger)
{
_downloadTrackingService = downloadTrackingService;
_logger = logger;
}
public string RejectionReason
{
get
{
return "Already in download queue.";
}
}
public RejectionType Type { get { return RejectionType.Permanent; } }
public bool IsSatisfiedBy(RemoteEpisode subject, SearchCriteriaBase searchCriteria)
{
var queue = _downloadTrackingService.GetQueuedDownloads()
.Where(v => v.State == TrackedDownloadState.Downloading)
.Select(q => q.DownloadItem.RemoteEpisode).ToList();
if (IsInQueue(subject, queue))
{
_logger.Debug("Already in queue, rejecting.");
return false;
}
return true;
}
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.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());
}
}
}