cardigann: apply template text to switch cases (#14463)

* Revert "cardigann: parse result with template (#14462)"

This reverts commit 6aee6d732a.

* cardigann: apply template text to switch cases
This commit is contained in:
Bogdan
2023-06-15 23:36:47 +03:00
committed by GitHub
parent aa16e7424c
commit 84ca9a06d8

View File

@@ -1244,18 +1244,22 @@ namespace Jackett.Common.Indexers
if (Selector.Case != null) if (Selector.Case != null)
{ {
foreach (var Case in Selector.Case) foreach (var switchCase in Selector.Case)
{ {
if (selection.Matches(Case.Key) || QuerySelector(selection, Case.Key) != null) if (selection.Matches(switchCase.Key) || QuerySelector(selection, switchCase.Key) != null)
{ {
value = Case.Value; value = applyGoTemplateText(switchCase.Value, variables);
break; break;
} }
} }
if (value == null) if (value == null)
{ {
if (required) if (required)
throw new Exception(string.Format("None of the case selectors \"{0}\" matched {1}", string.Join(",", Selector.Case), selection.ToHtmlPretty())); {
throw new Exception($"None of the case selectors \"{string.Join(",", Selector.Case)}\" matched {selection.ToHtmlPretty()}");
}
return null; return null;
} }
} }
@@ -1292,15 +1296,22 @@ namespace Jackett.Common.Indexers
selectorSelector = JsonParseFieldSelector(parentObj, selectorSelector); selectorSelector = JsonParseFieldSelector(parentObj, selectorSelector);
JToken selection = null; JToken selection = null;
if (selectorSelector != null) if (selectorSelector != null)
{
selection = parentObj.SelectToken(selectorSelector); selection = parentObj.SelectToken(selectorSelector);
}
if (selection == null) if (selection == null)
{ {
if (required) if (required)
throw new Exception(string.Format("Selector \"{0}\" didn't match {1}", selectorSelector, parentObj.ToString())); {
throw new Exception($"Selector \"{selectorSelector}\" didn't match {parentObj}");
}
return null; return null;
} }
if (selection.Type is JTokenType.Array) if (selection.Type is JTokenType.Array)
{ {
// turn this json array into a comma delimited string // turn this json array into a comma delimited string
@@ -1308,23 +1319,29 @@ namespace Jackett.Common.Indexers
value = String.Join(",", valueArray); value = String.Join(",", valueArray);
} }
else else
{
value = selection.Value<string>(); value = selection.Value<string>();
}
} }
if (Selector.Case != null) if (Selector.Case != null)
{ {
foreach (var Case in Selector.Case) foreach (var switchCase in Selector.Case)
{ {
if (value.Equals(Case.Key) || Case.Key.Equals("*")) if ((value != null && value.Equals(switchCase.Key)) || switchCase.Key.Equals("*"))
{ {
value = Case.Value; value = applyGoTemplateText(switchCase.Value, variables);
break; break;
} }
} }
if (value == null) if (value == null)
{ {
if (required) if (required)
throw new Exception(string.Format("None of the case selectors \"{0}\" matched {1}", string.Join(",", Selector.Case), parentObj.ToString())); {
throw new Exception($"None of the case selectors \"{string.Join(",", Selector.Case)}\" matched {parentObj}");
}
return null; return null;
} }
} }
@@ -1778,10 +1795,6 @@ namespace Jackett.Common.Indexers
value = defaultValue; value = defaultValue;
} }
else
{
value = applyGoTemplateText(value, variables);
}
variables[variablesKey] = ParseFields(value, FieldName, release, FieldModifiers, searchUrlUri); variables[variablesKey] = ParseFields(value, FieldName, release, FieldModifiers, searchUrlUri);
} }