2013-07-02 02:34:38 +00:00
|
|
|
using System;
|
|
|
|
using NLog;
|
|
|
|
using NzbDrone.Core.Configuration;
|
2013-08-07 03:18:05 +00:00
|
|
|
using NzbDrone.Core.IndexerSearch.Definitions;
|
2013-07-02 02:34:38 +00:00
|
|
|
using NzbDrone.Core.Parser.Model;
|
|
|
|
|
|
|
|
namespace NzbDrone.Core.DecisionEngine.Specifications
|
|
|
|
{
|
2013-07-05 04:52:20 +00:00
|
|
|
public class NotRestrictedReleaseSpecification : IDecisionEngineSpecification
|
2013-07-02 02:34:38 +00:00
|
|
|
{
|
|
|
|
private readonly IConfigService _configService;
|
|
|
|
private readonly Logger _logger;
|
|
|
|
|
2013-07-05 04:52:20 +00:00
|
|
|
public NotRestrictedReleaseSpecification(IConfigService configService, Logger logger)
|
2013-07-02 02:34:38 +00:00
|
|
|
{
|
|
|
|
_configService = configService;
|
|
|
|
_logger = logger;
|
|
|
|
}
|
|
|
|
|
|
|
|
public string RejectionReason
|
|
|
|
{
|
|
|
|
get
|
|
|
|
{
|
|
|
|
return "Contrains restricted term.";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-08-08 03:30:20 +00:00
|
|
|
public virtual bool IsSatisfiedBy(RemoteEpisode subject, SearchCriteriaBase searchCriteria)
|
2013-07-02 02:34:38 +00:00
|
|
|
{
|
2013-07-05 04:52:20 +00:00
|
|
|
_logger.Trace("Checking if release contains any restricted terms: {0}", subject);
|
2013-07-02 02:34:38 +00:00
|
|
|
|
2013-07-05 04:52:20 +00:00
|
|
|
var restrictionsString = _configService.ReleaseRestrictions;
|
2013-07-02 02:34:38 +00:00
|
|
|
|
|
|
|
if (String.IsNullOrWhiteSpace(restrictionsString))
|
|
|
|
{
|
|
|
|
_logger.Trace("No restrictions configured, allowing: {0}", subject);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
var restrictions = restrictionsString.Split('\n');
|
|
|
|
|
|
|
|
foreach (var restriction in restrictions)
|
|
|
|
{
|
2013-09-13 23:17:58 +00:00
|
|
|
if (subject.Release.Title.ToLowerInvariant().Contains(restriction.ToLowerInvariant()))
|
2013-07-02 02:34:38 +00:00
|
|
|
{
|
|
|
|
_logger.Trace("{0} is restricted: {1}", subject, restriction);
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
_logger.Trace("No restrictions apply, allowing: {0}", subject);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|