diff --git a/src/NzbDrone.Core/DecisionEngine/Specifications/ReleaseRestrictionsSpecification.cs b/src/NzbDrone.Core/DecisionEngine/Specifications/ReleaseRestrictionsSpecification.cs index 8358bf1c7..05fa7e40f 100644 --- a/src/NzbDrone.Core/DecisionEngine/Specifications/ReleaseRestrictionsSpecification.cs +++ b/src/NzbDrone.Core/DecisionEngine/Specifications/ReleaseRestrictionsSpecification.cs @@ -1,6 +1,7 @@ using System; using System.Collections.Generic; using System.Linq; +using System.Text.RegularExpressions; using NLog; using NzbDrone.Common.Extensions; using NzbDrone.Core.IndexerSearch.Definitions; @@ -43,11 +44,48 @@ namespace NzbDrone.Core.DecisionEngine.Specifications var required = restrictions.Where(r => r.Required.IsNotNullOrWhiteSpace()); var ignored = restrictions.Where(r => r.Ignored.IsNotNullOrWhiteSpace()); + var keyValueRegex = new Regex(@"\b\w+:\w+\b"); + foreach (var r in required) { var requiredTerms = r.Required.Split(new[] { ',' }, StringSplitOptions.RemoveEmptyEntries).ToList(); - var foundTerms = ContainsAny(requiredTerms, title); + // separate key-value terms and normal terms + var reqKeyValues = requiredTerms.Where(kv => keyValueRegex.IsMatch(kv)).ToList(); + var reqTitleTerms = requiredTerms.Where(t => !keyValueRegex.IsMatch(t)).ToList(); + + // check title terms + var foundTerms = ContainsAny(reqTitleTerms, title); + + // check key-value terms + foreach (var kv in reqKeyValues) + { + var key = kv.Split(':')[0]; + var value = kv.Split(':')[1]; + + switch (key) + { + case "origin": + var origin = subject.Release.Origin; + if (origin.IsNotNullOrWhiteSpace()) + { + if (string.Equals(origin, value, StringComparison.InvariantCultureIgnoreCase)) + { + foundTerms.Add(kv); + } + } + else + { + _logger.Debug("{0} not found in release", key); + } + break; + default: + _logger.Debug("{0} is not a supported key", key); + break; + } + + } + if (foundTerms.Empty()) { var terms = string.Join(", ", requiredTerms); @@ -56,6 +94,7 @@ namespace NzbDrone.Core.DecisionEngine.Specifications } } + foreach (var r in ignored) { var ignoredTerms = r.Ignored.Split(new[] { ',' }, StringSplitOptions.RemoveEmptyEntries).ToList();