2018-08-06 17:35:26 +00:00
|
|
|
using System;
|
2018-03-14 20:41:36 +00:00
|
|
|
using System.Linq;
|
2018-02-01 13:18:52 +00:00
|
|
|
using NLog;
|
|
|
|
using NzbDrone.Core.Indexers;
|
|
|
|
using NzbDrone.Core.IndexerSearch.Definitions;
|
|
|
|
using NzbDrone.Core.Parser.Model;
|
|
|
|
|
2018-09-10 19:25:10 +00:00
|
|
|
namespace NzbDrone.Core.DecisionEngine.Specifications
|
2018-02-01 13:18:52 +00:00
|
|
|
{
|
|
|
|
public class RequiredIndexerFlagsSpecification : IDecisionEngineSpecification
|
|
|
|
{
|
|
|
|
private readonly IIndexerFactory _indexerFactory;
|
|
|
|
private readonly Logger _logger;
|
|
|
|
|
|
|
|
public RequiredIndexerFlagsSpecification(IIndexerFactory indexerFactory, Logger logger)
|
|
|
|
{
|
|
|
|
_indexerFactory = indexerFactory;
|
|
|
|
_logger = logger;
|
|
|
|
}
|
|
|
|
|
2019-06-19 02:50:17 +00:00
|
|
|
public SpecificationPriority Priority => SpecificationPriority.Default;
|
2018-02-01 13:18:52 +00:00
|
|
|
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;
|
2019-12-22 22:08:53 +00:00
|
|
|
try
|
|
|
|
{
|
2018-08-06 17:35:26 +00:00
|
|
|
indexerSettings = _indexerFactory.Get(subject.Release.IndexerId)?.Settings as IIndexerSettings;
|
|
|
|
}
|
2019-06-14 03:54:25 +00:00
|
|
|
catch (Exception)
|
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;
|
2019-12-22 22:08:53 +00:00
|
|
|
var requiredFlag = (IndexerFlags)0;
|
2018-02-01 13:18:52 +00:00
|
|
|
|
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();
|
|
|
|
}
|
2019-12-22 22:08:53 +00:00
|
|
|
|
2018-02-01 13:18:52 +00:00
|
|
|
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();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|