2013-04-15 01:41:39 +00:00
|
|
|
using System.Collections.Generic;
|
|
|
|
using System.Linq;
|
2013-07-31 05:49:41 +00:00
|
|
|
using NLog;
|
2013-03-07 00:19:49 +00:00
|
|
|
using NzbDrone.Core.Download;
|
2013-08-07 03:18:05 +00:00
|
|
|
using NzbDrone.Core.IndexerSearch.Definitions;
|
2013-04-15 01:41:39 +00:00
|
|
|
using NzbDrone.Core.Parser.Model;
|
2014-01-18 11:44:36 +00:00
|
|
|
using NzbDrone.Core.Qualities;
|
2014-04-19 15:09:22 +00:00
|
|
|
using NzbDrone.Core.Queue;
|
2013-03-07 00:19:49 +00:00
|
|
|
|
|
|
|
namespace NzbDrone.Core.DecisionEngine.Specifications
|
|
|
|
{
|
2013-04-07 07:30:37 +00:00
|
|
|
public class NotInQueueSpecification : IDecisionEngineSpecification
|
2013-03-07 00:19:49 +00:00
|
|
|
{
|
2014-04-19 15:09:22 +00:00
|
|
|
private readonly IQueueService _queueService;
|
2013-07-31 05:49:41 +00:00
|
|
|
private readonly Logger _logger;
|
2013-03-07 00:19:49 +00:00
|
|
|
|
2014-04-19 15:09:22 +00:00
|
|
|
public NotInQueueSpecification(IQueueService queueService, Logger logger)
|
2013-03-07 00:19:49 +00:00
|
|
|
{
|
2014-04-19 15:09:22 +00:00
|
|
|
_queueService = queueService;
|
2013-07-31 05:49:41 +00:00
|
|
|
_logger = logger;
|
2013-03-07 00:19:49 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
public string RejectionReason
|
|
|
|
{
|
|
|
|
get
|
|
|
|
{
|
|
|
|
return "Already in download queue.";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-08-08 03:30:20 +00:00
|
|
|
public bool IsSatisfiedBy(RemoteEpisode subject, SearchCriteriaBase searchCriteria)
|
2013-03-07 00:19:49 +00:00
|
|
|
{
|
2014-04-19 15:09:22 +00:00
|
|
|
var queue = _queueService.GetQueue().Select(q => q.RemoteEpisode);
|
2013-04-15 01:41:39 +00:00
|
|
|
|
2014-02-06 00:55:19 +00:00
|
|
|
if (IsInQueue(subject, queue))
|
|
|
|
{
|
2014-03-13 20:12:42 +00:00
|
|
|
_logger.Debug("Already in queue, rejecting.");
|
2014-02-06 07:43:58 +00:00
|
|
|
return false;
|
2014-02-06 00:55:19 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
2013-04-15 01:41:39 +00:00
|
|
|
}
|
|
|
|
|
2013-10-09 06:58:29 +00:00
|
|
|
private bool IsInQueue(RemoteEpisode newEpisode, IEnumerable<RemoteEpisode> queue)
|
2013-04-15 01:41:39 +00:00
|
|
|
{
|
2013-10-09 06:07:09 +00:00
|
|
|
var matchingSeries = queue.Where(q => q.Series.Id == newEpisode.Series.Id);
|
2014-01-18 11:44:36 +00:00
|
|
|
var matchingSeriesAndQuality = matchingSeries.Where(q => new QualityModelComparer(q.Series.QualityProfile).Compare(q.ParsedEpisodeInfo.Quality, newEpisode.ParsedEpisodeInfo.Quality) >= 0);
|
2013-04-15 01:41:39 +00:00
|
|
|
|
2013-10-09 06:58:29 +00:00
|
|
|
return matchingSeriesAndQuality.Any(q => q.Episodes.Select(e => e.Id).Intersect(newEpisode.Episodes.Select(e => e.Id)).Any());
|
2013-03-07 00:19:49 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|