2013-07-02 05:34:38 +03:00
|
|
|
using System;
|
|
|
|
using NLog;
|
|
|
|
using NzbDrone.Core.Configuration;
|
|
|
|
using NzbDrone.Core.Parser.Model;
|
|
|
|
|
|
|
|
namespace NzbDrone.Core.DecisionEngine.Specifications
|
|
|
|
{
|
2013-07-05 07:52:20 +03:00
|
|
|
public class NotRestrictedReleaseSpecification : IDecisionEngineSpecification
|
2013-07-02 05:34:38 +03:00
|
|
|
{
|
|
|
|
private readonly IConfigService _configService;
|
|
|
|
private readonly Logger _logger;
|
|
|
|
|
2013-07-05 07:52:20 +03:00
|
|
|
public NotRestrictedReleaseSpecification(IConfigService configService, Logger logger)
|
2013-07-02 05:34:38 +03:00
|
|
|
{
|
|
|
|
_configService = configService;
|
|
|
|
_logger = logger;
|
|
|
|
}
|
|
|
|
|
|
|
|
public string RejectionReason
|
|
|
|
{
|
|
|
|
get
|
|
|
|
{
|
|
|
|
return "Contrains restricted term.";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public virtual bool IsSatisfiedBy(RemoteEpisode subject)
|
|
|
|
{
|
2013-07-05 07:52:20 +03:00
|
|
|
_logger.Trace("Checking if release contains any restricted terms: {0}", subject);
|
2013-07-02 05:34:38 +03:00
|
|
|
|
2013-07-05 07:52:20 +03:00
|
|
|
var restrictionsString = _configService.ReleaseRestrictions;
|
2013-07-02 05:34:38 +03: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 07:57:49 +03:00
|
|
|
if (subject.Report.Title.ToLowerInvariant().Contains(restriction.ToLowerInvariant()))
|
2013-07-02 05:34:38 +03:00
|
|
|
{
|
|
|
|
_logger.Trace("{0} is restricted: {1}", subject, restriction);
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
_logger.Trace("No restrictions apply, allowing: {0}", subject);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|