mirror of
https://github.com/Prowlarr/Prowlarr.git
synced 2026-04-18 21:55:12 -04: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);
|
var selectorSelector = ApplyGoTemplateText(selector.Selector, variables);
|
||||||
|
|
||||||
if (dom.Matches(selectorSelector))
|
selection = dom.Matches(selectorSelector) ? dom : QuerySelector(dom, selectorSelector);
|
||||||
{
|
|
||||||
selection = dom;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
selection = QuerySelector(dom, selectorSelector);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (selection == null)
|
if (selection == null)
|
||||||
{
|
{
|
||||||
if (required)
|
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;
|
return null;
|
||||||
@@ -195,7 +188,7 @@ namespace NzbDrone.Core.Indexers.Definitions.Cardigann
|
|||||||
{
|
{
|
||||||
if (required)
|
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;
|
return null;
|
||||||
|
|||||||
@@ -332,37 +332,47 @@ namespace NzbDrone.Core.Indexers.Definitions.Cardigann
|
|||||||
}
|
}
|
||||||
|
|
||||||
// selector inputs
|
// 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
|
try
|
||||||
{
|
{
|
||||||
value = HandleSelector(selectorinput.Value, landingResultDocument.FirstElementChild);
|
var value = HandleSelector(selectorInput.Value, landingResultDocument.FirstElementChild, required: !selectorInput.Value.Optional);
|
||||||
pairs[selectorinput.Key] = value;
|
|
||||||
|
if (selectorInput.Value.Optional && value == null)
|
||||||
|
{
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
pairs[selectorInput.Key] = value;
|
||||||
}
|
}
|
||||||
catch (Exception ex)
|
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
|
// 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
|
try
|
||||||
{
|
{
|
||||||
value = HandleSelector(selectorinput.Value, landingResultDocument.FirstElementChild);
|
var value = HandleSelector(selectorInput.Value, landingResultDocument.FirstElementChild, required: !selectorInput.Value.Optional);
|
||||||
queryCollection[selectorinput.Key] = value;
|
|
||||||
|
if (selectorInput.Value.Optional && value == null)
|
||||||
|
{
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
queryCollection[selectorInput.Key] = value;
|
||||||
}
|
}
|
||||||
catch (Exception ex)
|
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