mirror of
https://github.com/Prowlarr/Prowlarr
synced 2026-04-16 01:40:47 +02:00
New: (Cardigann) Optional login selectorinputs and getselectorinputs
This commit is contained in:
parent
e2ce6437e9
commit
fedebca5e1
2 changed files with 25 additions and 22 deletions
|
|
@ -139,20 +139,13 @@ protected string HandleSelector(SelectorBlock selector, IElement dom, Dictionary
|
|||
{
|
||||
var selectorSelector = ApplyGoTemplateText(selector.Selector, variables);
|
||||
|
||||
if (dom.Matches(selectorSelector))
|
||||
{
|
||||
selection = dom;
|
||||
}
|
||||
else
|
||||
{
|
||||
selection = QuerySelector(dom, selectorSelector);
|
||||
}
|
||||
selection = dom.Matches(selectorSelector) ? dom : QuerySelector(dom, selectorSelector);
|
||||
|
||||
if (selection == null)
|
||||
{
|
||||
if (required)
|
||||
{
|
||||
throw new Exception(string.Format("Selector \"{0}\" didn't match {1}", selectorSelector, dom.ToHtmlPretty()));
|
||||
throw new Exception($"Selector \"{selectorSelector}\" didn't match {dom.ToHtmlPretty()}");
|
||||
}
|
||||
|
||||
return null;
|
||||
|
|
@ -195,7 +188,7 @@ protected string HandleSelector(SelectorBlock selector, IElement dom, Dictionary
|
|||
{
|
||||
if (required)
|
||||
{
|
||||
throw new Exception(string.Format("Attribute \"{0}\" is not set for element {1}", selector.Attribute, selection.ToHtmlPretty()));
|
||||
throw new Exception($"Attribute \"{selector.Attribute}\" is not set for element {selection.ToHtmlPretty()}");
|
||||
}
|
||||
|
||||
return null;
|
||||
|
|
|
|||
|
|
@ -332,37 +332,47 @@ public async Task DoLogin()
|
|||
}
|
||||
|
||||
// selector inputs
|
||||
if (login.Selectorinputs != null)
|
||||
if (login.Selectorinputs != null && login.Selectorinputs.Any())
|
||||
{
|
||||
foreach (var selectorinput in login.Selectorinputs)
|
||||
foreach (var selectorInput in login.Selectorinputs)
|
||||
{
|
||||
string value = null;
|
||||
try
|
||||
{
|
||||
value = HandleSelector(selectorinput.Value, landingResultDocument.FirstElementChild);
|
||||
pairs[selectorinput.Key] = value;
|
||||
var value = HandleSelector(selectorInput.Value, landingResultDocument.FirstElementChild, required: !selectorInput.Value.Optional);
|
||||
|
||||
if (selectorInput.Value.Optional && value == null)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
pairs[selectorInput.Key] = value;
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
throw new CardigannException(string.Format("Error while parsing selector input={0}, selector={1}, value={2}: {3}", selectorinput.Key, selectorinput.Value.Selector, value, ex.Message));
|
||||
throw new CardigannException($"Error while parsing selector input={selectorInput.Key}, selector={selectorInput.Value.Selector}: {ex.Message}", ex);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// getselector inputs
|
||||
if (login.Getselectorinputs != null)
|
||||
if (login.Getselectorinputs != null && login.Getselectorinputs.Any())
|
||||
{
|
||||
foreach (var selectorinput in login.Getselectorinputs)
|
||||
foreach (var selectorInput in login.Getselectorinputs)
|
||||
{
|
||||
string value = null;
|
||||
try
|
||||
{
|
||||
value = HandleSelector(selectorinput.Value, landingResultDocument.FirstElementChild);
|
||||
queryCollection[selectorinput.Key] = value;
|
||||
var value = HandleSelector(selectorInput.Value, landingResultDocument.FirstElementChild, required: !selectorInput.Value.Optional);
|
||||
|
||||
if (selectorInput.Value.Optional && value == null)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
queryCollection[selectorInput.Key] = value;
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
throw new CardigannException(string.Format("Error while parsing get selector input={0}, selector={1}, value={2}: {3}", selectorinput.Key, selectorinput.Value.Selector, value, ex.Message));
|
||||
throw new CardigannException($"Error while parsing get selector input={selectorInput.Key}, selector={selectorInput.Value.Selector}: {ex.Message}", ex);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue