New: Add tag support to indexers

(cherry picked from commit c3d54b312ef18b837d54605ea78f1a263fd6900b)
This commit is contained in:
6cUbi57z
2021-03-22 00:00:06 +00:00
committed by Bogdan
parent 10e230cc06
commit b97d63cb5b
21 changed files with 454 additions and 25 deletions
@@ -0,0 +1,39 @@
using System.Linq;
using NLog;
using NzbDrone.Common.Extensions;
using NzbDrone.Core.Indexers;
using NzbDrone.Core.IndexerSearch.Definitions;
using NzbDrone.Core.Parser.Model;
namespace NzbDrone.Core.DecisionEngine.Specifications.RssSync
{
public class IndexerTagSpecification : IDecisionEngineSpecification
{
private readonly Logger _logger;
private readonly IIndexerRepository _indexerRepository;
public IndexerTagSpecification(Logger logger, IIndexerRepository indexerRepository)
{
_logger = logger;
_indexerRepository = indexerRepository;
}
public SpecificationPriority Priority => SpecificationPriority.Default;
public RejectionType Type => RejectionType.Permanent;
public virtual Decision IsSatisfiedBy(RemoteBook subject, SearchCriteriaBase searchCriteria)
{
// If indexer has tags, check that at least one of them is present on the author
var indexerTags = _indexerRepository.Get(subject.Release.IndexerId).Tags;
if (indexerTags.Any() && indexerTags.Intersect(subject.Author.Tags).Empty())
{
_logger.Debug("Indexer {0} has tags. None of these are present on author {1}. Rejecting", subject.Release.Indexer, subject.Author);
return Decision.Reject("Author tags do not match any of the indexer tags");
}
return Decision.Accept();
}
}
}