2018-03-14 20:41:36 +00:00
|
|
|
using System.Linq;
|
2018-02-01 13:18:52 +00:00
|
|
|
using NLog;
|
|
|
|
using NzbDrone.Core.Datastore;
|
|
|
|
using NzbDrone.Core.Indexers;
|
|
|
|
using NzbDrone.Core.IndexerSearch.Definitions;
|
|
|
|
using NzbDrone.Core.Parser.Model;
|
|
|
|
|
|
|
|
namespace NzbDrone.Core.DecisionEngine.Specifications.Search
|
|
|
|
{
|
|
|
|
public class RequiredIndexerFlagsSpecification : IDecisionEngineSpecification
|
|
|
|
{
|
|
|
|
private readonly IIndexerFactory _indexerFactory;
|
|
|
|
private readonly Logger _logger;
|
|
|
|
|
|
|
|
public RequiredIndexerFlagsSpecification(IIndexerFactory indexerFactory, Logger logger)
|
|
|
|
{
|
|
|
|
_indexerFactory = indexerFactory;
|
|
|
|
_logger = logger;
|
|
|
|
}
|
|
|
|
|
|
|
|
//public SpecificationPriority Priority => SpecificationPriority.Default;
|
|
|
|
public RejectionType Type => RejectionType.Permanent;
|
|
|
|
|
2018-03-14 20:41:36 +00:00
|
|
|
public Decision IsSatisfiedBy(RemoteMovie subject, SearchCriteriaBase searchCriteria)
|
2018-02-01 13:18:52 +00:00
|
|
|
{
|
2018-03-14 20:41:36 +00:00
|
|
|
var torrentInfo = subject.Release;
|
2018-02-01 13:18:52 +00:00
|
|
|
|
2018-08-05 14:28:05 +00:00
|
|
|
if (torrentInfo == null || torrentInfo.IndexerSettings == null)
|
2018-02-01 13:18:52 +00:00
|
|
|
{
|
|
|
|
return Decision.Accept();
|
|
|
|
}
|
|
|
|
|
2018-08-05 14:28:05 +00:00
|
|
|
var torrentIndexerSettings = torrentInfo.IndexerSettings as ITorrentIndexerSettings;
|
2018-02-01 13:18:52 +00:00
|
|
|
|
|
|
|
if (torrentIndexerSettings != null)
|
|
|
|
{
|
|
|
|
var requiredFlags = torrentIndexerSettings.RequiredFlags;
|
|
|
|
var requiredFlag = (IndexerFlags) 0;
|
|
|
|
|
2018-02-01 15:00:55 +00:00
|
|
|
if (requiredFlags == null || requiredFlags.Count() == 0)
|
2018-02-01 13:18:52 +00:00
|
|
|
{
|
|
|
|
return Decision.Accept();
|
|
|
|
}
|
|
|
|
|
|
|
|
foreach (var flag in requiredFlags)
|
|
|
|
{
|
|
|
|
if (torrentInfo.IndexerFlags.HasFlag((IndexerFlags)flag))
|
|
|
|
{
|
|
|
|
return Decision.Accept();
|
|
|
|
}
|
|
|
|
requiredFlag |= (IndexerFlags)flag;
|
|
|
|
}
|
|
|
|
|
|
|
|
_logger.Debug("None of the required indexer flags {0} where found. Found flags: {1}", requiredFlag, torrentInfo.IndexerFlags);
|
|
|
|
return Decision.Reject("None of the required indexer flags {0} where found. Found flags: {1}", requiredFlag, torrentInfo.IndexerFlags);
|
|
|
|
}
|
|
|
|
|
|
|
|
return Decision.Accept();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|