2018-08-06 17:35:26 +00:00
|
|
|
using System;
|
2018-08-07 15:29:03 +00:00
|
|
|
using System.Collections.Generic;
|
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-06 17:35:26 +00:00
|
|
|
|
|
|
|
IIndexerSettings indexerSettings = null;
|
|
|
|
try {
|
|
|
|
indexerSettings = _indexerFactory.Get(subject.Release.IndexerId)?.Settings as IIndexerSettings;
|
|
|
|
}
|
|
|
|
catch (Exception e)
|
2018-02-01 13:18:52 +00:00
|
|
|
{
|
2018-08-06 17:35:26 +00:00
|
|
|
_logger.Debug("Indexer with id {0} does not exist, skipping required indexer flags specs.", subject.Release.IndexerId);
|
2018-02-01 13:18:52 +00:00
|
|
|
}
|
|
|
|
|
2018-08-06 17:35:26 +00:00
|
|
|
if (torrentInfo == null || indexerSettings == null)
|
|
|
|
{
|
|
|
|
return Decision.Accept();
|
|
|
|
}
|
2018-02-01 13:18:52 +00:00
|
|
|
|
2018-08-06 17:35:26 +00:00
|
|
|
if (indexerSettings is ITorrentIndexerSettings torrentIndexerSettings)
|
2018-02-01 13:18:52 +00:00
|
|
|
{
|
|
|
|
var requiredFlags = torrentIndexerSettings.RequiredFlags;
|
|
|
|
var requiredFlag = (IndexerFlags) 0;
|
|
|
|
|
2018-08-07 15:29:03 +00:00
|
|
|
if (requiredFlags == null || !requiredFlags.Any())
|
2018-02-01 13:18:52 +00:00
|
|
|
{
|
|
|
|
return Decision.Accept();
|
|
|
|
}
|
2018-08-06 17:35:26 +00:00
|
|
|
|
2018-08-07 15:29:03 +00:00
|
|
|
foreach (var flag in requiredFlags)
|
2018-02-01 13:18:52 +00:00
|
|
|
{
|
|
|
|
if (torrentInfo.IndexerFlags.HasFlag((IndexerFlags)flag))
|
|
|
|
{
|
|
|
|
return Decision.Accept();
|
|
|
|
}
|
|
|
|
requiredFlag |= (IndexerFlags)flag;
|
|
|
|
}
|
2018-08-06 17:35:26 +00:00
|
|
|
|
2018-02-01 13:18:52 +00:00
|
|
|
_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();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|