From 6aad279600c8b2914884bac2611433a02f7d8441 Mon Sep 17 00:00:00 2001 From: Florian Duguet Date: Tue, 10 Nov 2020 16:31:58 +0100 Subject: [PATCH] weboob.capabilities.captcha: Add HcaptchaQuestion and HcaptchaJob --- weboob/capabilities/captcha.py | 14 ++++++++++++-- weboob/exceptions.py | 10 ++++++++++ 2 files changed, 22 insertions(+), 2 deletions(-) diff --git a/weboob/capabilities/captcha.py b/weboob/capabilities/captcha.py index 5a505e7639..ecc6f9160c 100644 --- a/weboob/capabilities/captcha.py +++ b/weboob/capabilities/captcha.py @@ -21,13 +21,14 @@ from .base import Capability, BaseObject, StringField, UserError, BytesField from ..exceptions import ( - RecaptchaQuestion, RecaptchaV3Question, NocaptchaQuestion, FuncaptchaQuestion, ImageCaptchaQuestion + RecaptchaQuestion, RecaptchaV3Question, NocaptchaQuestion, FuncaptchaQuestion, + ImageCaptchaQuestion, HcaptchaQuestion, ) __all__ = [ 'CapCaptchaSolver', - 'SolverJob', 'RecaptchaJob', 'NocaptchaJob', 'ImageCaptchaJob', + 'SolverJob', 'RecaptchaJob', 'NocaptchaJob', 'ImageCaptchaJob', 'HcaptchaJob', 'CaptchaError', 'UnsolvableCaptcha', 'InvalidCaptcha', 'InsufficientFunds', 'exception_to_job', ] @@ -61,6 +62,11 @@ class FuncaptchaJob(SolverJob): sub_domain = StringField('Required for some complex cases, but Funcaptcha integrations run without it') +class HcaptchaJob(SolverJob): + site_url = StringField('Site URL for HCaptcha service') + site_key = StringField('Site key for HCaptcha service') + + class ImageCaptchaJob(SolverJob): image = BytesField('data of the image to solve') @@ -103,6 +109,10 @@ def exception_to_job(exc): elif isinstance(exc, ImageCaptchaQuestion): job = ImageCaptchaJob() job.image = exc.image_data + elif isinstance(exc, HcaptchaQuestion): + job = HcaptchaJob() + job.site_url = exc.website_url + job.site_key = exc.website_key else: raise NotImplementedError() diff --git a/weboob/exceptions.py b/weboob/exceptions.py index 94063021ab..731c87f498 100644 --- a/weboob/exceptions.py +++ b/weboob/exceptions.py @@ -171,6 +171,16 @@ def __init__(self, website_key, website_url, sub_domain=None): self.type, website_key=website_key, website_url=website_url, sub_domain=sub_domain) +class HcaptchaQuestion(CaptchaQuestion): + type = 'hcaptcha' + + website_key = None + website_url = None + + def __init__(self, website_key, website_url): + super(HcaptchaQuestion, self).__init__(self.type, website_key=website_key, website_url=website_url) + + class BrowserHTTPNotFound(Exception): pass -- GitLab