mirror of https://github.com/Jackett/Jackett
cardigann: make login selectorinputs and getselectorinputs optional (#15435)
Co-authored-by: ilike2burnthing <59480337+ilike2burnthing@users.noreply.github.com>
This commit is contained in:
parent
ba4d8a64ff
commit
298fd02126
|
@ -496,11 +496,28 @@ login:
|
||||||
path: login.php
|
path: login.php
|
||||||
method: form
|
method: form
|
||||||
form: form[action$="/login.php"]
|
form: form[action$="/login.php"]
|
||||||
|
captcha:
|
||||||
|
type: image
|
||||||
|
selector: img[src^="profile.php?mode=confirm&id="]
|
||||||
|
input: cfmcd
|
||||||
inputs:
|
inputs:
|
||||||
login_username: "{{ .Config.username }}"
|
login_username: "{{ .Config.username }}"
|
||||||
login_password: "{{ .Config.password }}"
|
login_password: "{{ .Config.password }}"
|
||||||
autologin: 1
|
autologin: 1
|
||||||
redirect: index.php
|
redirect: index.php
|
||||||
|
selectorinputs:
|
||||||
|
cookie_test:
|
||||||
|
selector: input[name="cookie_test"]
|
||||||
|
attribute: value
|
||||||
|
optional: true
|
||||||
|
confirm_id:
|
||||||
|
selector: input[name="confirm_id"]
|
||||||
|
attribute: value
|
||||||
|
optional: true
|
||||||
|
sid:
|
||||||
|
selector: input[name="sid"]:not(input[id="dl-sid"])
|
||||||
|
attribute: value
|
||||||
|
optional: true
|
||||||
error:
|
error:
|
||||||
- selector: h4:contains("Вы ввели")
|
- selector: h4:contains("Вы ввели")
|
||||||
test:
|
test:
|
||||||
|
|
|
@ -672,37 +672,47 @@ namespace Jackett.Common.Indexers
|
||||||
}
|
}
|
||||||
|
|
||||||
// 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 Exception(string.Format("Error while parsing selector input={0}, selector={1}, value={2}: {3}", Selectorinput.Key, Selectorinput.Value.Selector, value, ex.Message));
|
throw new Exception($"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 Exception(string.Format("Error while parsing get selector input={0}, selector={1}, value={2}: {3}", Selectorinput.Key, Selectorinput.Value.Selector, value, ex.Message));
|
throw new Exception($"Error while parsing get selector input={selectorInput.Key}, selector={selectorInput.Value.Selector}: {ex.Message}", ex);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1245,14 +1255,16 @@ namespace Jackett.Common.Indexers
|
||||||
if (Selector.Selector != null)
|
if (Selector.Selector != null)
|
||||||
{
|
{
|
||||||
var selector_Selector = applyGoTemplateText(Selector.Selector, variables);
|
var selector_Selector = applyGoTemplateText(Selector.Selector, variables);
|
||||||
if (Dom.Matches(selector_Selector))
|
|
||||||
selection = Dom;
|
selection = Dom.Matches(selector_Selector) ? Dom : QuerySelector(Dom, selector_Selector);
|
||||||
else
|
|
||||||
selection = QuerySelector(Dom, selector_Selector);
|
|
||||||
if (selection == null)
|
if (selection == null)
|
||||||
{
|
{
|
||||||
if (required)
|
if (required)
|
||||||
throw new Exception(string.Format("Selector \"{0}\" didn't match {1}", selector_Selector, Dom.ToHtmlPretty()));
|
{
|
||||||
|
throw new Exception($"Selector \"{selector_Selector}\" didn't match {Dom.ToHtmlPretty()}");
|
||||||
|
}
|
||||||
|
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1292,7 +1304,10 @@ namespace Jackett.Common.Indexers
|
||||||
if (value == null)
|
if (value == null)
|
||||||
{
|
{
|
||||||
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;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue