mirror of
https://github.com/Prowlarr/Prowlarr.git
synced 2025-12-28 00:53:26 +01:00
New: (Cardigann) Optional login selectorinputs and getselectorinputs
This commit is contained in:
@@ -139,20 +139,13 @@ namespace NzbDrone.Core.Indexers.Definitions.Cardigann
|
||||
{
|
||||
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 @@ namespace NzbDrone.Core.Indexers.Definitions.Cardigann
|
||||
{
|
||||
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 @@ namespace NzbDrone.Core.Indexers.Definitions.Cardigann
|
||||
}
|
||||
|
||||
// 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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user