summaryrefslogtreecommitdiffhomepage
path: root/libs/python_anticaptcha
diff options
context:
space:
mode:
authormorpheus65535 <[email protected]>2022-11-07 13:06:49 -0500
committermorpheus65535 <[email protected]>2022-11-07 13:08:27 -0500
commitbbe2483e21c2c1549ceeed16f021f9581b899f70 (patch)
treebcc2bef2f55789ec6e6c64809c07fb4f4d3d9c86 /libs/python_anticaptcha
parent708fbfcd8ec0620647975be39a1f6acbbf08f767 (diff)
downloadbazarr-bbe2483e21c2c1549ceeed16f021f9581b899f70.tar.gz
bazarr-bbe2483e21c2c1549ceeed16f021f9581b899f70.zip
Updated vendored dependencies.
Diffstat (limited to 'libs/python_anticaptcha')
-rw-r--r--libs/python_anticaptcha/__init__.py29
-rw-r--r--libs/python_anticaptcha/base.py3
-rw-r--r--libs/python_anticaptcha/fields.py199
-rw-r--r--libs/python_anticaptcha/tasks.py275
4 files changed, 195 insertions, 311 deletions
diff --git a/libs/python_anticaptcha/__init__.py b/libs/python_anticaptcha/__init__.py
index ec175a175..2dc4d939a 100644
--- a/libs/python_anticaptcha/__init__.py
+++ b/libs/python_anticaptcha/__init__.py
@@ -1,29 +1,24 @@
from .base import AnticaptchaClient
from pkg_resources import get_distribution, DistributionNotFound
from .tasks import (
- NoCaptchaTask,
NoCaptchaTaskProxylessTask,
- FunCaptchaTask,
+ RecaptchaV2TaskProxyless,
+ NoCaptchaTask,
+ RecaptchaV2Task,
FunCaptchaProxylessTask,
+ FunCaptchaTask,
+ ImageToTextTask,
RecaptchaV3TaskProxyless,
- HCaptchaTask,
HCaptchaTaskProxyless,
- SquareNetTask,
- ImageToTextTask,
- CustomCaptchaTask,
+ HCaptchaTask,
+ RecaptchaV2EnterpriseTaskProxyless,
+ RecaptchaV2EnterpriseTask,
+ GeeTestTaskProxyless,
+ GeeTestTask,
+ AntiGateTaskProxyless,
+ AntiGateTask
)
from .exceptions import AnticaptchaException
-from .fields import (
- SimpleText,
- Image,
- WebLink,
- TextInput,
- Textarea,
- Checkbox,
- Select,
- Radio,
- ImageUpload,
-)
AnticatpchaException = AnticaptchaException
diff --git a/libs/python_anticaptcha/base.py b/libs/python_anticaptcha/base.py
index 45830ae25..7e93a4f7d 100644
--- a/libs/python_anticaptcha/base.py
+++ b/libs/python_anticaptcha/base.py
@@ -30,6 +30,9 @@ class Job(object):
def get_solution_response(self): # Recaptcha
return self._last_result["solution"]["gRecaptchaResponse"]
+ def get_solution(self):
+ return self._last_result["solution"]
+
def get_token_response(self): # Funcaptcha
return self._last_result["solution"]["token"]
diff --git a/libs/python_anticaptcha/fields.py b/libs/python_anticaptcha/fields.py
deleted file mode 100644
index 9a42cdbab..000000000
--- a/libs/python_anticaptcha/fields.py
+++ /dev/null
@@ -1,199 +0,0 @@
-import six
-from python_anticaptcha.exceptions import InvalidWidthException, MissingNameException
-
-
-class BaseField(object):
- label = None
- labelHint = None
-
- def serialize(self, name=None):
- data = {}
- if self.label:
- data["label"] = self.label or False
- if self.labelHint:
- data["labelHint"] = self.labelHint or False
- return data
-
-
-class NameBaseField(BaseField):
- name = None
-
- def serialize(self, name=None):
- data = super(NameBaseField, self).serialize(name)
- if name:
- data["name"] = name
- elif self.name:
- data["name"] = self.name
- else:
- raise MissingNameException(cls=self.__class__)
- return data
-
-
-class SimpleText(BaseField):
- contentType = "text"
-
- def __init__(self, content, label=None, labelHint=None, width=None):
- self.label = label
- self.labelHint = labelHint
-
- self.content = content
- self.width = width
-
- def serialize(self, name=None):
- data = super(SimpleText, self).serialize(name)
- data["contentType"] = self.contentType
- data["content"] = self.content
-
- if self.width:
- if self.width not in [100, 50, 33, 25]:
- raise InvalidWidthException(self.width)
- data["inputOptions"] = {}
- data["width"] = self.width
- return data
-
-
-class Image(BaseField):
- contentType = "image"
-
- def __init__(self, imageUrl, label=None, labelHint=None):
- self.label = label
- self.labelHint = labelHint
- self.imageUrl = imageUrl
-
- def serialize(self, name=None):
- data = super(Image, self).serialize(name)
- data["contentType"] = self.contentType
- data["content"] = self.imageUrl
- return data
-
-
-class WebLink(BaseField):
- contentType = "link"
-
- def __init__(self, linkText, linkUrl, label=None, labelHint=None, width=None):
- self.label = label
- self.labelHint = labelHint
-
- self.linkText = linkText
- self.linkUrl = linkUrl
-
- self.width = width
-
- def serialize(self, name=None):
- data = super(WebLink, self).serialize(name)
- data["contentType"] = self.contentType
-
- if self.width:
- if self.width not in [100, 50, 33, 25]:
- raise InvalidWidthException(self.width)
- data["inputOptions"] = {}
- data["width"] = self.width
-
- data.update({"content": {"url": self.linkUrl, "text": self.linkText}})
-
- return data
-
-
-class TextInput(NameBaseField):
- def __init__(self, placeHolder=None, label=None, labelHint=None, width=None):
- self.label = label
- self.labelHint = labelHint
-
- self.placeHolder = placeHolder
-
- self.width = width
-
- def serialize(self, name=None):
- data = super(TextInput, self).serialize(name)
- data["inputType"] = "text"
-
- data["inputOptions"] = {}
-
- if self.width:
- if self.width not in [100, 50, 33, 25]:
- raise InvalidWidthException(self.width)
-
- data["inputOptions"]["width"] = str(self.width)
-
- if self.placeHolder:
- data["inputOptions"]["placeHolder"] = self.placeHolder
- return data
-
-
-class Textarea(NameBaseField):
- def __init__(
- self, placeHolder=None, rows=None, label=None, width=None, labelHint=None
- ):
- self.label = label
- self.labelHint = labelHint
-
- self.placeHolder = placeHolder
- self.rows = rows
- self.width = width
-
- def serialize(self, name=None):
- data = super(Textarea, self).serialize(name)
- data["inputType"] = "textarea"
- data["inputOptions"] = {}
- if self.rows:
- data["inputOptions"]["rows"] = str(self.rows)
- if self.placeHolder:
- data["inputOptions"]["placeHolder"] = self.placeHolder
- if self.width:
- data["inputOptions"]["width"] = str(self.width)
- return data
-
-
-class Checkbox(NameBaseField):
- def __init__(self, text, label=None, labelHint=None):
- self.label = label
- self.labelHint = labelHint
-
- self.text = text
-
- def serialize(self, name=None):
- data = super(Checkbox, self).serialize(name)
- data["inputType"] = "checkbox"
- data["inputOptions"] = {"label": self.text}
- return data
-
-
-class Select(NameBaseField):
- type = "select"
-
- def __init__(self, label=None, choices=None, labelHint=None):
- self.label = label
- self.labelHint = labelHint
- self.choices = choices or ()
-
- def get_choices(self):
- for choice in self.choices:
- if isinstance(choice, six.text_type):
- yield choice, choice
- else:
- yield choice
-
- def serialize(self, name=None):
- data = super(Select, self).serialize(name)
- data["inputType"] = self.type
-
- data["inputOptions"] = []
- for value, caption in self.get_choices():
- data["inputOptions"].append({"value": value, "caption": caption})
-
- return data
-
-
-class Radio(Select):
- type = "radio"
-
-
-class ImageUpload(NameBaseField):
- def __init__(self, label=None, labelHint=None):
- self.label = label
- self.labelHint = labelHint
-
- def serialize(self, name=None):
- data = super(ImageUpload, self).serialize(name)
- data["inputType"] = "imageUpload"
- return data
diff --git a/libs/python_anticaptcha/tasks.py b/libs/python_anticaptcha/tasks.py
index aa0fbdb1c..a48963bb2 100644
--- a/libs/python_anticaptcha/tasks.py
+++ b/libs/python_anticaptcha/tasks.py
@@ -1,36 +1,57 @@
import base64
-from .fields import BaseField
class BaseTask(object):
+ type = None
+
def serialize(self, **result):
+ result["type"] = self.type
return result
+class UserAgentMixin(BaseTask):
+ def __init__(self, *args, **kwargs):
+ self.userAgent = kwargs.pop("user_agent")
+ super(UserAgentMixin, self).__init__(*args, **kwargs)
+
+ def serialize(self, **result):
+ data = super(UserAgentMixin, self).serialize(**result)
+ data["userAgent"] = self.userAgent
+ return data
+
+
+class CookieMixin(BaseTask):
+ def __init__(self, *args, **kwargs):
+ self.cookies = kwargs.pop("cookies", "")
+ super(CookieMixin, self).__init__(*args, **kwargs)
+
+ def serialize(self, **result):
+ data = super(CookieMixin, self).serialize(**result)
+ if self.cookies:
+ data["cookies"] = self.cookies
+ return data
+
+
class ProxyMixin(BaseTask):
def __init__(self, *args, **kwargs):
self.proxyType = kwargs.pop("proxy_type")
- self.userAgent = kwargs.pop("user_agent")
self.proxyAddress = kwargs.pop("proxy_address")
self.proxyPort = kwargs.pop("proxy_port")
self.proxyLogin = kwargs.pop("proxy_login")
self.proxyPassword = kwargs.pop("proxy_password")
-
- self.cookies = kwargs.pop("cookies", "")
super(ProxyMixin, self).__init__(*args, **kwargs)
def serialize(self, **result):
- result = super(ProxyMixin, self).serialize(**result)
- result["userAgent"] = self.userAgent
- result["proxyType"] = self.proxyType
- result["proxyAddress"] = self.proxyAddress
- result["proxyPort"] = self.proxyPort
+ data = super(ProxyMixin, self).serialize(**result)
+ data["proxyType"] = self.proxyType
+ data["proxyAddress"] = self.proxyAddress
+ data["proxyPort"] = self.proxyPort
if self.proxyLogin:
- result["proxyLogin"] = self.proxyLogin
- result["proxyPassword"] = self.proxyPassword
+ data["proxyLogin"] = self.proxyLogin
+ data["proxyPassword"] = self.proxyPassword
if self.cookies:
- result["cookies"] = self.cookies
- return result
+ data["cookies"] = self.cookies
+ return data
class NoCaptchaTaskProxylessTask(BaseTask):
@@ -47,19 +68,20 @@ class NoCaptchaTaskProxylessTask(BaseTask):
website_s_token=None,
is_invisible=None,
recaptcha_data_s_value=None,
+ *args,
+ **kwargs
):
self.websiteURL = website_url
self.websiteKey = website_key
self.websiteSToken = website_s_token
self.recaptchaDataSValue = recaptcha_data_s_value
self.isInvisible = is_invisible
+ super(NoCaptchaTaskProxylessTask, self).__init__(*args, **kwargs)
- def serialize(self):
- data = {
- "type": self.type,
- "websiteURL": self.websiteURL,
- "websiteKey": self.websiteKey,
- }
+ def serialize(self, **result):
+ data = super(NoCaptchaTaskProxylessTask, self).serialize(**result)
+ data["websiteURL"] = self.websiteURL
+ data["websiteKey"] = self.websiteKey
if self.websiteSToken is not None:
data["websiteSToken"] = self.websiteSToken
if self.isInvisible is not None:
@@ -69,37 +91,52 @@ class NoCaptchaTaskProxylessTask(BaseTask):
return data
-class NoCaptchaTask(ProxyMixin, NoCaptchaTaskProxylessTask):
+class RecaptchaV2TaskProxyless(NoCaptchaTaskProxylessTask):
+ type = "RecaptchaV2TaskProxyless"
+
+
+class NoCaptchaTask(
+ ProxyMixin, UserAgentMixin, CookieMixin, NoCaptchaTaskProxylessTask
+):
type = "NoCaptchaTask"
+class RecaptchaV2Task(NoCaptchaTask):
+ type = "RecaptchaV2Task"
+
+
class FunCaptchaProxylessTask(BaseTask):
type = "FunCaptchaTaskProxyless"
websiteURL = None
websiteKey = None
+ funcaptchaApiJSSubdomain = None
+ data = None
- def __init__(self, website_url, website_key, *args, **kwargs):
+ def __init__(
+ self, website_url, website_key, subdomain=None, data=None, *args, **kwargs
+ ):
self.websiteURL = website_url
self.websiteKey = website_key
+ self.funcaptchaApiJSSubdomain = subdomain
+ self.data = data
super(FunCaptchaProxylessTask, self).__init__(*args, **kwargs)
def serialize(self, **result):
- result = super(FunCaptchaProxylessTask, self).serialize(**result)
- result.update(
- {
- "type": self.type,
- "websiteURL": self.websiteURL,
- "websitePublicKey": self.websiteKey,
- }
- )
- return result
+ data = super(FunCaptchaProxylessTask, self).serialize(**result)
+ data["websiteURL"] = self.websiteURL
+ data["websitePublicKey"] = self.websiteKey
+ if self.funcaptchaApiJSSubdomain:
+ data["funcaptchaApiJSSubdomain"] = self.funcaptchaApiJSSubdomain
+ if self.data:
+ data["data"] = self.data
+ return data
-class FunCaptchaTask(ProxyMixin, FunCaptchaProxylessTask):
+class FunCaptchaTask(ProxyMixin, UserAgentMixin, CookieMixin, FunCaptchaProxylessTask):
type = "FunCaptchaTask"
-class ImageToTextTask(object):
+class ImageToTextTask(BaseTask):
type = "ImageToTextTask"
fp = None
phrase = None
@@ -108,6 +145,8 @@ class ImageToTextTask(object):
math = None
minLength = None
maxLength = None
+ comment = None
+ websiteUrl = None
def __init__(
self,
@@ -118,6 +157,9 @@ class ImageToTextTask(object):
math=None,
min_length=None,
max_length=None,
+ comment=None,
+ website_url=None,
+ *args, **kwargs
):
self.fp = fp
self.phrase = phrase
@@ -126,46 +168,21 @@ class ImageToTextTask(object):
self.math = math
self.minLength = min_length
self.maxLength = max_length
+ self.comment = comment
+ self.websiteUrl = website_url
+ super(ImageToTextTask, self).__init__(*args, **kwargs)
- def serialize(self):
- return {
- "type": self.type,
- "body": base64.b64encode(self.fp.read()).decode("utf-8"),
- "phrase": self.phrase,
- "case": self.case,
- "numeric": self.numeric,
- "math": self.math,
- "minLength": self.minLength,
- "maxLength": self.maxLength,
- }
-
-
-class CustomCaptchaTask(BaseTask):
- type = "CustomCaptchaTask"
- imageUrl = None
- assignment = None
- form = None
-
- def __init__(self, imageUrl, form=None, assignment=None):
- self.imageUrl = imageUrl
- self.form = form or {}
- self.assignment = assignment
-
- def serialize(self):
- data = super(CustomCaptchaTask, self).serialize()
- data.update({"type": self.type, "imageUrl": self.imageUrl})
- if self.form:
- forms = []
- for name, field in self.form.items():
- if isinstance(field, BaseField):
- forms.append(field.serialize(name))
- else:
- field = field.copy()
- field["name"] = name
- forms.append(field)
- data["forms"] = forms
- if self.assignment:
- data["assignment"] = self.assignment
+ def serialize(self, **result):
+ data = super(ImageToTextTask, self).serialize(**result)
+ data["body"] = base64.b64encode(self.fp.read()).decode("utf-8")
+ data["phrase"] = self.phrase
+ data["case"] = self.case
+ data["numeric"] = self.numeric
+ data["math"] = self.math
+ data["minLength"] = self.minLength
+ data["maxLength"] = self.maxLength
+ data["comment"] = self.comment
+ data["websiteUrl"] = self.websiteUrl
return data
@@ -175,20 +192,25 @@ class RecaptchaV3TaskProxyless(BaseTask):
websiteKey = None
minScore = None
pageAction = None
+ isEnterprise = False
- def __init__(self, website_url, website_key, min_score, page_action):
+ def __init__(
+ self, website_url, website_key, min_score, page_action, is_enterprise=False, *args, **kwargs
+ ):
self.websiteURL = website_url
self.websiteKey = website_key
self.minScore = min_score
self.pageAction = page_action
+ self.isEnterprise = is_enterprise
+ super(RecaptchaV3TaskProxyless, self).__init__(*args, **kwargs)
- def serialize(self):
- data = super(RecaptchaV3TaskProxyless, self).serialize()
- data["type"] = self.type
+ def serialize(self, **result):
+ data = super(RecaptchaV3TaskProxyless, self).serialize(**result)
data["websiteURL"] = self.websiteURL
data["websiteKey"] = self.websiteKey
data["minScore"] = self.minScore
data["pageAction"] = self.pageAction
+ data["isEnterprise"] = self.isEnterprise
return data
@@ -204,34 +226,97 @@ class HCaptchaTaskProxyless(BaseTask):
def serialize(self, **result):
data = super(HCaptchaTaskProxyless, self).serialize(**result)
- data["type"] = self.type
data["websiteURL"] = self.websiteURL
data["websiteKey"] = self.websiteKey
return data
-class HCaptchaTask(ProxyMixin, HCaptchaTaskProxyless):
+class HCaptchaTask(ProxyMixin, UserAgentMixin, CookieMixin, HCaptchaTaskProxyless):
type = "HCaptchaTask"
-class SquareNetTask(BaseTask):
- type = "SquareNetTask"
- fp = None
- objectName = None
- rowsCount = None
- columnsCount = None
+class RecaptchaV2EnterpriseTaskProxyless(BaseTask):
+ type = "RecaptchaV2EnterpriseTaskProxyless"
+ websiteURL = None
+ websiteKey = None
+ enterprisePayload = None
+ apiDomain = None
- def __init__(self, fp, objectName, rowsCount, columnsCount):
- self.fp = fp
- self.objectName = objectName
- self.rowsCount = rowsCount
- self.columnsCount = columnsCount
+ def __init__(self, website_url, website_key, enterprise_payload, api_domain, *args, **kwargs):
+ self.websiteURL = website_url
+ self.websiteKey = website_key
+ self.enterprisePayload = enterprise_payload
+ self.apiDomain = api_domain
+ super(RecaptchaV2EnterpriseTaskProxyless, self).__init__(*args, **kwargs)
- def serialize(self):
- data = super(SquareNetTask, self).serialize()
- data["type"] = self.type
- data["body"] = base64.b64encode(self.fp.read()).decode("utf-8")
- data["objectName"] = self.objectName
- data["rowsCount"] = self.rowsCount
- data["columnsCount"] = self.columnsCount
+ def serialize(self, **result):
+ data = super(RecaptchaV2EnterpriseTaskProxyless, self).serialize(**result)
+ data["websiteURL"] = self.websiteURL
+ data["websiteKey"] = self.websiteKey
+ if self.enterprisePayload:
+ data["enterprisePayload"] = self.enterprisePayload
+ if self.apiDomain:
+ data["apiDomain"] = self.apiDomain
return data
+
+
+class RecaptchaV2EnterpriseTask(ProxyMixin, UserAgentMixin, CookieMixin, BaseTask):
+ type = "RecaptchaV2EnterpriseTask"
+
+
+class GeeTestTaskProxyless(BaseTask):
+ type = "GeeTestTaskProxyless"
+ websiteURL = None
+ gt = None
+ challenge = None
+ geetestApiServerSubdomain = None
+ geetestGetLib = None
+
+ def __init__(
+ self, website_url, gt, challenge, subdomain=None, lib=None, *args, **kwargs
+ ):
+ self.websiteURL = website_url
+ self.gt = gt
+ self.challenge = challenge
+ self.geetestApiServerSubdomain = subdomain
+ self.geetestGetLib = lib
+ super(GeeTestTaskProxyless).__init__(*args, **kwargs)
+
+ def serialize(self, **result):
+ data = super(GeeTestTaskProxyless, self).serialize(**result)
+ data["websiteURL"] = self.websiteURL
+ data["gt"] = self.gt
+ data["challenge"] = self.challenge
+ if self.geetestApiServerSubdomain:
+ data["geetestApiServerSubdomain"] = self.geetestApiServerSubdomain
+ if self.geetestGetLib:
+ data["geetestGetLib"] = self.geetestGetLib
+ return data
+
+
+class GeeTestTask(ProxyMixin, UserAgentMixin, GeeTestTaskProxyless):
+ pass
+
+
+class AntiGateTaskProxyless(BaseTask):
+ type = "AntiGateTask"
+ websiteURL = None
+ templateName = None
+ variables = None
+
+ def __init__(self, website_url, template_name, variables, *args, **kwargs):
+ self.websiteURL = website_url
+ self.templateName = template_name
+ self.variables = variables
+ super(AntiGateTaskProxyless).__init__(*args, **kwargs)
+
+ def serialize(self, **result):
+ data = super(AntiGateTaskProxyless, self).serialize(**result)
+ data["websiteURL"] = self.websiteURL
+ data["templateName"] = self.templateName
+ data["variables"] = self.variables
+ return data
+
+
+class AntiGateTask(ProxyMixin, AntiGateTaskProxyless):
+ pass