Cardigann: add support for text captcha

This commit is contained in:
kaso17
2018-01-10 18:20:11 +01:00
parent 26933d9286
commit 8a02403f83
20 changed files with 55 additions and 20 deletions

View File

@@ -557,6 +557,22 @@ namespace Jackett.Indexers
pairs[input] = CaptchaText.Value;
}
}
if (Captcha.Type == "text")
{
var CaptchaAnswer = (StringItem)configData.GetDynamic("CaptchaAnswer");
if (CaptchaAnswer != null)
{
var input = Captcha.Input;
if (Login.Selectors)
{
var inputElement = landingResultDocument.QuerySelector(Captcha.Input);
if (inputElement == null)
throw new ExceptionWithConfigData(string.Format("Login failed: No captcha input found using {0}", Captcha.Input), configData);
input = inputElement.GetAttribute("name");
}
pairs[input] = CaptchaAnswer.Value;
}
}
}
// clear landingResults/Document, otherwise we might use an old version for a new relogin (if GetConfigurationForSetup() wasn't called before)
@@ -716,7 +732,7 @@ namespace Jackett.Indexers
var Captcha = Login.Captcha;
if (Captcha.Type == "image")
{
var captchaElement = landingResultDocument.QuerySelector(Captcha.Image);
var captchaElement = landingResultDocument.QuerySelector(Captcha.Selector);
if (captchaElement != null)
{
hasCaptcha = true;
@@ -736,6 +752,24 @@ namespace Jackett.Indexers
logger.Debug(string.Format("CardigannIndexer ({0}): No captcha image found", ID));
}
}
else if (Captcha.Type == "text")
{
var captchaElement = landingResultDocument.QuerySelector(Captcha.Selector);
if (captchaElement != null)
{
hasCaptcha = true;
var CaptchaChallenge = new DisplayItem(captchaElement.TextContent) { Name = "Captcha Challenge" };
var CaptchaAnswer = new StringItem { Name = "Captcha Answer" };
configData.AddDynamic("CaptchaChallenge", CaptchaChallenge);
configData.AddDynamic("CaptchaAnswer", CaptchaAnswer);
}
else
{
logger.Debug(string.Format("CardigannIndexer ({0}): No captcha image found", ID));
}
}
else
{
throw new NotImplementedException(string.Format("Captcha type \"{0}\" is not implemented", Captcha.Type));