2013-07-02 02:34:38 +00:00
|
|
|
using System;
|
|
|
|
using System.Linq;
|
|
|
|
using NLog;
|
|
|
|
using NzbDrone.Core.Configuration;
|
|
|
|
using NzbDrone.Core.Model;
|
|
|
|
using NzbDrone.Core.Parser;
|
|
|
|
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.";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public virtual bool IsSatisfiedBy(RemoteEpisode subject)
|
|
|
|
{
|
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-07-02 04:57:49 +00:00
|
|
|
if (subject.Report.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;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|