mirror of
https://github.com/Prowlarr/Prowlarr.git
synced 2025-09-17 17:14:18 +02:00
V6 Cardigann Changes (#1045)
* V6 Cardigann Changes * fixup! * !fixup range * !fixup more cardigann tests
This commit is contained in:
@@ -28,7 +28,7 @@ namespace NzbDrone.Core.Indexers.Cardigann
|
||||
protected readonly IndexerCapabilitiesCategories _categories = new IndexerCapabilitiesCategories();
|
||||
protected readonly List<string> _defaultCategories = new List<string>();
|
||||
|
||||
protected readonly string[] OptionalFields = new string[] { "imdb", "imdbid", "rageid", "tmdbid", "tvdbid", "poster", "banner", "description" };
|
||||
protected readonly string[] OptionalFields = new string[] { "imdb", "imdbid", "rageid", "tmdbid", "tvdbid", "poster", "banner", "description", "doubanid" };
|
||||
|
||||
protected static readonly string[] _SupportedLogicFunctions =
|
||||
{
|
||||
@@ -338,9 +338,9 @@ namespace NzbDrone.Core.Indexers.Cardigann
|
||||
return variables;
|
||||
}
|
||||
|
||||
protected delegate string TemplateTextModifier(string str);
|
||||
public delegate string TemplateTextModifier(string str);
|
||||
|
||||
protected string ApplyGoTemplateText(string template, Dictionary<string, object> variables = null, TemplateTextModifier modifier = null)
|
||||
public string ApplyGoTemplateText(string template, Dictionary<string, object> variables = null, TemplateTextModifier modifier = null)
|
||||
{
|
||||
if (variables == null)
|
||||
{
|
||||
@@ -520,7 +520,7 @@ namespace NzbDrone.Core.Indexers.Cardigann
|
||||
}
|
||||
|
||||
// handle range expression
|
||||
var rangeRegex = new Regex(@"{{\s*range\s*(.+?)\s*}}(.*?){{\.}}(.*?){{end}}");
|
||||
var rangeRegex = new Regex(@"{{\s*range\s*(((?<index>\$.+?),)((\s*(?<element>.+?)\s*(:=)\s*)))?(?<variable>.+?)\s*}}(?<prefix>.*?){{\.}}(?<postfix>.*?){{end}}");
|
||||
var rangeRegexMatches = rangeRegex.Match(template);
|
||||
|
||||
while (rangeRegexMatches.Success)
|
||||
@@ -528,9 +528,13 @@ namespace NzbDrone.Core.Indexers.Cardigann
|
||||
var expanded = string.Empty;
|
||||
|
||||
var all = rangeRegexMatches.Groups[0].Value;
|
||||
var variable = rangeRegexMatches.Groups[1].Value;
|
||||
var prefix = rangeRegexMatches.Groups[2].Value;
|
||||
var postfix = rangeRegexMatches.Groups[3].Value;
|
||||
var index = rangeRegexMatches.Groups["index"].Value;
|
||||
var variable = rangeRegexMatches.Groups["variable"].Value;
|
||||
var prefix = rangeRegexMatches.Groups["prefix"].Value;
|
||||
var postfix = rangeRegexMatches.Groups["postfix"].Value;
|
||||
|
||||
var arrayIndex = 0;
|
||||
var indexReplace = "{{" + index + "}}";
|
||||
|
||||
foreach (var value in (ICollection<string>)variables[variable])
|
||||
{
|
||||
@@ -540,7 +544,16 @@ namespace NzbDrone.Core.Indexers.Cardigann
|
||||
newvalue = modifier(newvalue);
|
||||
}
|
||||
|
||||
expanded += prefix + newvalue + postfix;
|
||||
var indexValue = arrayIndex++;
|
||||
|
||||
if (index.IsNotNullOrWhiteSpace())
|
||||
{
|
||||
expanded += prefix.Replace(indexReplace, indexValue.ToString()) + newvalue + postfix.Replace(indexReplace, indexValue.ToString());
|
||||
}
|
||||
else
|
||||
{
|
||||
expanded += prefix + newvalue + postfix;
|
||||
}
|
||||
}
|
||||
|
||||
template = template.Replace(all, expanded);
|
||||
|
Reference in New Issue
Block a user