bazarr/libs/python_anticaptcha/tasks.py

323 lines
9.8 KiB
Python
Raw Normal View History

2019-04-06 12:26:42 +00:00
import base64
class BaseTask(object):
2022-11-07 18:06:49 +00:00
type = None
2019-04-06 12:26:42 +00:00
def serialize(self, **result):
2022-11-07 18:06:49 +00:00
result["type"] = self.type
2019-04-06 12:26:42 +00:00
return result
2022-11-07 18:06:49 +00:00
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
2019-04-06 12:26:42 +00:00
class ProxyMixin(BaseTask):
def __init__(self, *args, **kwargs):
self.proxyType = kwargs.pop("proxy_type")
self.proxyAddress = kwargs.pop("proxy_address")
self.proxyPort = kwargs.pop("proxy_port")
self.proxyLogin = kwargs.pop("proxy_login")
self.proxyPassword = kwargs.pop("proxy_password")
2019-04-06 12:26:42 +00:00
super(ProxyMixin, self).__init__(*args, **kwargs)
def serialize(self, **result):
2022-11-07 18:06:49 +00:00
data = super(ProxyMixin, self).serialize(**result)
data["proxyType"] = self.proxyType
data["proxyAddress"] = self.proxyAddress
data["proxyPort"] = self.proxyPort
if self.proxyLogin:
2022-11-07 18:06:49 +00:00
data["proxyLogin"] = self.proxyLogin
data["proxyPassword"] = self.proxyPassword
2019-04-06 12:26:42 +00:00
if self.cookies:
2022-11-07 18:06:49 +00:00
data["cookies"] = self.cookies
return data
2019-04-06 12:26:42 +00:00
class NoCaptchaTaskProxylessTask(BaseTask):
type = "NoCaptchaTaskProxyless"
websiteURL = None
websiteKey = None
websiteSToken = None
recaptchaDataSValue = None
def __init__(
self,
website_url,
website_key,
website_s_token=None,
is_invisible=None,
recaptcha_data_s_value=None,
2022-11-07 18:06:49 +00:00
*args,
**kwargs
):
2019-04-06 12:26:42 +00:00
self.websiteURL = website_url
self.websiteKey = website_key
self.websiteSToken = website_s_token
self.recaptchaDataSValue = recaptcha_data_s_value
2019-04-06 12:26:42 +00:00
self.isInvisible = is_invisible
2022-11-07 18:06:49 +00:00
super(NoCaptchaTaskProxylessTask, self).__init__(*args, **kwargs)
2019-04-06 12:26:42 +00:00
2022-11-07 18:06:49 +00:00
def serialize(self, **result):
data = super(NoCaptchaTaskProxylessTask, self).serialize(**result)
data["websiteURL"] = self.websiteURL
data["websiteKey"] = self.websiteKey
2019-04-06 12:26:42 +00:00
if self.websiteSToken is not None:
data["websiteSToken"] = self.websiteSToken
2019-04-06 12:26:42 +00:00
if self.isInvisible is not None:
data["isInvisible"] = self.isInvisible
if self.recaptchaDataSValue is not None:
data["recaptchaDataSValue"] = self.recaptchaDataSValue
2019-04-06 12:26:42 +00:00
return data
2022-11-07 18:06:49 +00:00
class RecaptchaV2TaskProxyless(NoCaptchaTaskProxylessTask):
type = "RecaptchaV2TaskProxyless"
class NoCaptchaTask(
ProxyMixin, UserAgentMixin, CookieMixin, NoCaptchaTaskProxylessTask
):
type = "NoCaptchaTask"
2022-11-07 18:06:49 +00:00
class RecaptchaV2Task(NoCaptchaTask):
type = "RecaptchaV2Task"
class FunCaptchaProxylessTask(BaseTask):
type = "FunCaptchaTaskProxyless"
2019-04-06 12:26:42 +00:00
websiteURL = None
websiteKey = None
2022-11-07 18:06:49 +00:00
funcaptchaApiJSSubdomain = None
data = None
2019-04-06 12:26:42 +00:00
2022-11-07 18:06:49 +00:00
def __init__(
self, website_url, website_key, subdomain=None, data=None, *args, **kwargs
):
2019-04-06 12:26:42 +00:00
self.websiteURL = website_url
self.websiteKey = website_key
2022-11-07 18:06:49 +00:00
self.funcaptchaApiJSSubdomain = subdomain
self.data = data
super(FunCaptchaProxylessTask, self).__init__(*args, **kwargs)
2019-04-06 12:26:42 +00:00
def serialize(self, **result):
2022-11-07 18:06:49 +00:00
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
2019-04-06 12:26:42 +00:00
2022-11-07 18:06:49 +00:00
class FunCaptchaTask(ProxyMixin, UserAgentMixin, CookieMixin, FunCaptchaProxylessTask):
type = "FunCaptchaTask"
2019-04-06 12:26:42 +00:00
2022-11-07 18:06:49 +00:00
class ImageToTextTask(BaseTask):
2019-04-06 12:26:42 +00:00
type = "ImageToTextTask"
fp = None
phrase = None
case = None
numeric = None
math = None
minLength = None
maxLength = None
2022-11-07 18:06:49 +00:00
comment = None
websiteUrl = None
2019-04-06 12:26:42 +00:00
def __init__(
self,
fp,
phrase=None,
case=None,
numeric=None,
math=None,
min_length=None,
max_length=None,
2022-11-07 18:06:49 +00:00
comment=None,
website_url=None,
*args, **kwargs
):
2019-04-06 12:26:42 +00:00
self.fp = fp
self.phrase = phrase
self.case = case
self.numeric = numeric
self.math = math
self.minLength = min_length
self.maxLength = max_length
2022-11-07 18:06:49 +00:00
self.comment = comment
self.websiteUrl = website_url
super(ImageToTextTask, self).__init__(*args, **kwargs)
2019-04-06 12:26:42 +00:00
2022-11-07 18:06:49 +00:00
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
class RecaptchaV3TaskProxyless(BaseTask):
type = "RecaptchaV3TaskProxyless"
websiteURL = None
websiteKey = None
minScore = None
pageAction = None
2022-11-07 18:06:49 +00:00
isEnterprise = False
2022-11-07 18:06:49 +00:00
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
2022-11-07 18:06:49 +00:00
self.isEnterprise = is_enterprise
super(RecaptchaV3TaskProxyless, self).__init__(*args, **kwargs)
2022-11-07 18:06:49 +00:00
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
2022-11-07 18:06:49 +00:00
data["isEnterprise"] = self.isEnterprise
return data
class HCaptchaTaskProxyless(BaseTask):
type = "HCaptchaTaskProxyless"
websiteURL = None
websiteKey = None
def __init__(self, website_url, website_key, *args, **kwargs):
self.websiteURL = website_url
self.websiteKey = website_key
super(HCaptchaTaskProxyless, self).__init__(*args, **kwargs)
def serialize(self, **result):
data = super(HCaptchaTaskProxyless, self).serialize(**result)
data["websiteURL"] = self.websiteURL
data["websiteKey"] = self.websiteKey
return data
2022-11-07 18:06:49 +00:00
class HCaptchaTask(ProxyMixin, UserAgentMixin, CookieMixin, HCaptchaTaskProxyless):
type = "HCaptchaTask"
2022-11-07 18:06:49 +00:00
class RecaptchaV2EnterpriseTaskProxyless(BaseTask):
type = "RecaptchaV2EnterpriseTaskProxyless"
websiteURL = None
websiteKey = None
enterprisePayload = None
apiDomain = None
2022-11-07 18:06:49 +00:00
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)
2022-11-07 18:06:49 +00:00
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
2019-04-06 12:26:42 +00:00
return data
2022-11-07 18:06:49 +00:00
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