basic key:value restriction matching outline
This commit is contained in:
parent
5cb1896af0
commit
adf8b5c813
|
@ -1,6 +1,7 @@
|
||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
|
using System.Text.RegularExpressions;
|
||||||
using NLog;
|
using NLog;
|
||||||
using NzbDrone.Common.Extensions;
|
using NzbDrone.Common.Extensions;
|
||||||
using NzbDrone.Core.IndexerSearch.Definitions;
|
using NzbDrone.Core.IndexerSearch.Definitions;
|
||||||
|
@ -43,11 +44,48 @@ namespace NzbDrone.Core.DecisionEngine.Specifications
|
||||||
var required = restrictions.Where(r => r.Required.IsNotNullOrWhiteSpace());
|
var required = restrictions.Where(r => r.Required.IsNotNullOrWhiteSpace());
|
||||||
var ignored = restrictions.Where(r => r.Ignored.IsNotNullOrWhiteSpace());
|
var ignored = restrictions.Where(r => r.Ignored.IsNotNullOrWhiteSpace());
|
||||||
|
|
||||||
|
var keyValueRegex = new Regex(@"\b\w+:\w+\b");
|
||||||
|
|
||||||
foreach (var r in required)
|
foreach (var r in required)
|
||||||
{
|
{
|
||||||
var requiredTerms = r.Required.Split(new[] { ',' }, StringSplitOptions.RemoveEmptyEntries).ToList();
|
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())
|
if (foundTerms.Empty())
|
||||||
{
|
{
|
||||||
var terms = string.Join(", ", requiredTerms);
|
var terms = string.Join(", ", requiredTerms);
|
||||||
|
@ -56,6 +94,7 @@ namespace NzbDrone.Core.DecisionEngine.Specifications
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
foreach (var r in ignored)
|
foreach (var r in ignored)
|
||||||
{
|
{
|
||||||
var ignoredTerms = r.Ignored.Split(new[] { ',' }, StringSplitOptions.RemoveEmptyEntries).ToList();
|
var ignoredTerms = r.Ignored.Split(new[] { ',' }, StringSplitOptions.RemoveEmptyEntries).ToList();
|
||||||
|
|
Loading…
Reference in New Issue