Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 14 additions & 2 deletions capmonstercloud_client/CapMonsterCloudClient.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,10 @@
((HuntCustomTaskRequest,), getHuntTimeouts),
((AlibabaCustomTaskRequest,), getAlibabaTimeouts),
((FriendlyCustomTaskRequest,), getFriendlyTimeouts),
((FengkongCloudCustomTaskRequest,), getFengkongCloudTimeouts),
((ArCaptchaRequest,), getArCaptchaTimeouts),
((HeyTapCustomTaskRequest,), getHeyTapTimeouts),
((ProtonCustomTaskRequest,), getProtonTimeouts),
)


Expand Down Expand Up @@ -110,7 +114,11 @@ async def solve_captcha(self, request: Union[
TspdCustomTaskRequest,
HuntCustomTaskRequest,
AlibabaCustomTaskRequest,
FriendlyCustomTaskRequest],
FriendlyCustomTaskRequest,
FengkongCloudCustomTaskRequest,
ArCaptchaRequest,
HeyTapCustomTaskRequest,
ProtonCustomTaskRequest],
) -> Dict[str, str]:
'''
Non-blocking method for captcha solving.
Expand Down Expand Up @@ -154,7 +162,11 @@ async def _solve(self, request: Union[
TspdCustomTaskRequest,
HuntCustomTaskRequest,
AlibabaCustomTaskRequest,
FriendlyCustomTaskRequest],
FriendlyCustomTaskRequest,
FengkongCloudCustomTaskRequest,
ArCaptchaRequest,
HeyTapCustomTaskRequest,
ProtonCustomTaskRequest],
timeouts: GetResultTimeouts,
) -> Dict[str, str]:

Expand Down
12 changes: 12 additions & 0 deletions capmonstercloud_client/GetResultTimeouts.py
Original file line number Diff line number Diff line change
Expand Up @@ -85,3 +85,15 @@ def getProsopoTimeouts() -> GetResultTimeouts:

def getTemuTimeouts() -> GetResultTimeouts:
return GetResultTimeouts(1, 10, 3, 180)

def getFengkongCloudTimeouts() -> GetResultTimeouts:
return GetResultTimeouts(1, 10, 3, 180)

def getArCaptchaTimeouts() -> GetResultTimeouts:
return GetResultTimeouts(1, 10, 3, 180)

def getHeyTapTimeouts() -> GetResultTimeouts:
return GetResultTimeouts(1, 10, 3, 180)

def getProtonTimeouts() -> GetResultTimeouts:
return GetResultTimeouts(1, 10, 3, 180)
34 changes: 34 additions & 0 deletions capmonstercloud_client/requests/ArCaptchaRequest.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
from typing import Dict, Optional, Union
from pydantic import Field

from .baseRequest import BaseRequest

class ArCaptchaRequest(BaseRequest):
"""
Represents a payload structure for solving ARCaptcha challenges.

Attributes:
websiteUrl: The URL of the webpage containing the ARCaptcha challenge.
websiteKey: The site key associated with the ARCaptcha on the webpage.
type: The constant string value identifying the task type as
"ArCaptchaTask".
isInvisible: True if the captcha is invisible (has a hidden
verification field).
userAgent: Browser User-Agent to emulate.
"""
websiteUrl: str = Field(..., description='Address of a webpage with ARCaptcha.')
websiteKey: str = Field(..., description='The site key associated with the ARCaptcha on the webpage.')
type: str = Field(default='ArCaptchaTask', description='The constant string value identifying the task type as "ArCaptchaTask".')
isInvisible: Optional[bool] = Field(default=None, description='True if the captcha is invisible (has a hidden verification field).')
userAgent: Optional[str] = Field(default=None, description='Browser User-Agent to emulate.')

def getTaskDict(self) -> Dict[str, Union[str, bool]]:
task = {}
task['type'] = self.type
task['websiteURL'] = self.websiteUrl
task['websiteKey'] = self.websiteKey
if self.isInvisible is not None:
task['isInvisible'] = self.isInvisible
if self.userAgent is not None:
task['userAgent'] = self.userAgent
return task
44 changes: 44 additions & 0 deletions capmonstercloud_client/requests/FengkongCloudCustomTaskRequest.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
from typing import Dict, Optional, Union
from pydantic import Field, field_validator

from .CustomTaskRequestBase import CustomTaskRequestBase

class FengkongCloudCustomTaskRequest(CustomTaskRequestBase):
"""
Represents a payload structure for solving FengkongCloud captcha
challenges via a custom module.

Attributes:
captchaClass: The class (subtype) identifier of the custom
module, constant "fengkongcloud" for this task.
websiteKey: The siteKey value found on the page (the appid
parameter of the /conf request).
metadata: Optional dictionary; the only allowed key is apiJsUrl,
the link to smcp.min.js.
"""

captchaClass: str = Field(default='fengkongcloud', description='Class (subtype) identifier of the custom module, constant "fengkongcloud".')
websiteKey: str = Field(..., description='The siteKey value found on the page.')
metadata: Optional[Dict[str, str]] = Field(default=None, description='Optional dictionary; the only allowed key is apiJsUrl, the link to smcp.min.js.')

@field_validator('metadata')
@classmethod
def validate_metadata(cls, value):
if value is None:
return value
allowed = {'apiJsUrl'}
if not set(value.keys()).issubset(allowed):
raise TypeError(f'Allowed keys for metadata are {sorted(allowed)}.')
return value

def getTaskDict(self) -> Dict[str, Union[str, int, bool]]:
task = {}
task['type'] = self.type
task['class'] = self.captchaClass
task['websiteURL'] = self.websiteUrl
task['websiteKey'] = self.websiteKey
if self.metadata is not None:
task['metadata'] = self.metadata
if self.userAgent is not None:
task['userAgent'] = self.userAgent
return task
48 changes: 48 additions & 0 deletions capmonstercloud_client/requests/HeyTapCustomTaskRequest.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
from typing import Dict, Optional, Union
from pydantic import Field, field_validator

from .CustomTaskRequestBase import CustomTaskRequestBase

class HeyTapCustomTaskRequest(CustomTaskRequestBase):
"""
Represents a payload structure for solving HeyTap captcha challenges
via a custom module.

Attributes:
captchaClass: The class (subtype) identifier of the custom
module, constant "heytap" for this task.
websiteKey: The siteKey value found on the page (the ak
parameter of the HeyTap captcha API request).
metadata: Optional dictionary; the only allowed key is apiServer,
the HeyTap API server domain without the https:// prefix
(needed only if it differs from the default server).
"""

captchaClass: str = Field(default='heytap', description='Class (subtype) identifier of the custom module, constant "heytap".')
websiteKey: str = Field(..., description='The siteKey value found on the page.')
metadata: Optional[Dict[str, str]] = Field(default=None, description='Optional dictionary; the only allowed key is apiServer, the HeyTap API server domain without the https:// prefix.')

@field_validator('metadata')
@classmethod
def validate_metadata(cls, value):
if value is None:
return value
allowed = {'apiServer'}
if not set(value.keys()).issubset(allowed):
raise TypeError(f'Allowed keys for metadata are {sorted(allowed)}.')
api_server = value.get('apiServer')
if api_server is not None and api_server.startswith(('https://', 'http://')):
raise TypeError(f'apiServer must be a domain without the https:// prefix.')
return value

def getTaskDict(self) -> Dict[str, Union[str, int, bool]]:
task = {}
task['type'] = self.type
task['class'] = self.captchaClass
task['websiteURL'] = self.websiteUrl
task['websiteKey'] = self.websiteKey
if self.metadata is not None:
task['metadata'] = self.metadata
if self.userAgent is not None:
task['userAgent'] = self.userAgent
return task
56 changes: 56 additions & 0 deletions capmonstercloud_client/requests/ProtonCustomTaskRequest.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
from typing import Dict, Union
from pydantic import Field, field_validator, model_validator

from .CustomTaskRequestBase import CustomTaskRequestBase

class ProtonCustomTaskRequest(CustomTaskRequestBase):
"""
Represents a payload structure for solving Proton Captcha challenges
via a custom module.

Attributes:
captchaClass: The class (subtype) identifier of the custom
module, constant "proton" for this task.
metadata: A dictionary with the required HumanVerificationToken
and pageAction ("login" or "signup").
proxy: Proxy settings to route the request through. Required for
this task type.
"""

captchaClass: str = Field(default='proton', description='Class (subtype) identifier of the custom module, constant "proton".')
metadata: Dict[str, str] = Field(..., description='A dictionary with the required HumanVerificationToken and pageAction ("login" or "signup").')

@field_validator('metadata')
@classmethod
def validate_metadata(cls, value):
allowed = {'HumanVerificationToken', 'pageAction'}
if not set(value.keys()).issubset(allowed):
raise TypeError(f'Allowed keys for metadata are {sorted(allowed)}.')
for key in sorted(allowed):
if value.get(key) is None:
raise TypeError(f'{key} must be defined inside metadata.')
if value['pageAction'] not in ('login', 'signup'):
raise TypeError(f'pageAction must be "login" or "signup".')
return value

@model_validator(mode='before')
def validate_proton_proxy(cls, values):
proxy = values.get('proxy')
if proxy is None:
raise RuntimeError(f'You are required to use your own proxies.')
return values

def getTaskDict(self) -> Dict[str, Union[str, int, bool]]:
task = {}
task['type'] = self.type
task['class'] = self.captchaClass
task['websiteURL'] = self.websiteUrl
task['metadata'] = self.metadata
task['proxyType'] = self.proxy.proxyType
task['proxyAddress'] = self.proxy.proxyAddress
task['proxyPort'] = self.proxy.proxyPort
task['proxyLogin'] = self.proxy.proxyLogin
task['proxyPassword'] = self.proxy.proxyPassword
if self.userAgent is not None:
task['userAgent'] = self.userAgent
return task
10 changes: 9 additions & 1 deletion capmonstercloud_client/requests/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,10 @@
from .HuntCustomTaskRequest import HuntCustomTaskRequest
from .AlibabaCustomTaskRequest import AlibabaCustomTaskRequest
from .FriendlyCustomTaskRequest import FriendlyCustomTaskRequest
from .FengkongCloudCustomTaskRequest import FengkongCloudCustomTaskRequest
from .ArCaptchaRequest import ArCaptchaRequest
from .HeyTapCustomTaskRequest import HeyTapCustomTaskRequest
from .ProtonCustomTaskRequest import ProtonCustomTaskRequest
from .proxy_info import ProxyInfo, ClientProxyInfo


Expand All @@ -54,5 +58,9 @@
'TspdCustomTaskRequest',
'HuntCustomTaskRequest',
'AlibabaCustomTaskRequest',
'FriendlyCustomTaskRequest'
'FriendlyCustomTaskRequest',
'FengkongCloudCustomTaskRequest',
'ArCaptchaRequest',
'HeyTapCustomTaskRequest',
'ProtonCustomTaskRequest'
]
2 changes: 1 addition & 1 deletion capmonstercloud_client/version.txt
Original file line number Diff line number Diff line change
@@ -1 +1 @@
4.3.4
4.4.0
35 changes: 35 additions & 0 deletions examples/arcaptcha.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
import os
import time
import asyncio

from capmonstercloudclient.requests import ArCaptchaRequest
from capmonstercloudclient import ClientOptions, CapMonsterClient

async def solve_captcha_sync(num_requests):
return [await cap_monster_client.solve_captcha(arcaptcha_request) for _ in range(num_requests)]

async def solve_captcha_async(num_requests):
tasks = [asyncio.create_task(cap_monster_client.solve_captcha(arcaptcha_request))
for _ in range(num_requests)]
return await asyncio.gather(*tasks, return_exceptions=True)

if __name__ == '__main__':
key = os.getenv('API_KEY')
client_options = ClientOptions(api_key=key)
cap_monster_client = CapMonsterClient(options=client_options)
arcaptcha_request = ArCaptchaRequest(websiteUrl='https://example.com/',
websiteKey='your-website-key',
isInvisible=False)
nums = 3

# Sync test
sync_start = time.time()
sync_responses = asyncio.run(solve_captcha_sync(nums))
print(f'average execution time sync {1/((time.time()-sync_start)/nums):0.2f} ' \
f'resp/sec\nsolution: {sync_responses[0]}')

# Async test
async_start = time.time()
async_responses = asyncio.run(solve_captcha_async(nums))
print(f'average execution time async {1/((time.time()-async_start)/nums):0.2f} ' \
f'resp/sec\nsolution: {async_responses[0]}')
36 changes: 36 additions & 0 deletions examples/fengkongcloud.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
import os
import time
import asyncio

from capmonstercloudclient.requests import FengkongCloudCustomTaskRequest
from capmonstercloudclient import ClientOptions, CapMonsterClient

async def solve_captcha_sync(num_requests):
return [await cap_monster_client.solve_captcha(fengkongcloud_request) for _ in range(num_requests)]

async def solve_captcha_async(num_requests):
tasks = [asyncio.create_task(cap_monster_client.solve_captcha(fengkongcloud_request))
for _ in range(num_requests)]
return await asyncio.gather(*tasks, return_exceptions=True)

if __name__ == '__main__':
key = os.getenv('API_KEY')
client_options = ClientOptions(api_key=key)
cap_monster_client = CapMonsterClient(options=client_options)
fengkongcloud_request = FengkongCloudCustomTaskRequest(
websiteUrl='https://www.example.com/',
websiteKey='your-website-key',
metadata={'apiJsUrl': 'https://example.com/path/to/script.js'})
nums = 3

# Sync test
sync_start = time.time()
sync_responses = asyncio.run(solve_captcha_sync(nums))
print(f'average execution time sync {1/((time.time()-sync_start)/nums):0.2f} ' \
f'resp/sec\nsolution: {sync_responses[0]}')

# Async test
async_start = time.time()
async_responses = asyncio.run(solve_captcha_async(nums))
print(f'average execution time async {1/((time.time()-async_start)/nums):0.2f} ' \
f'resp/sec\nsolution: {async_responses[0]}')
36 changes: 36 additions & 0 deletions examples/heytap.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
import os
import time
import asyncio

from capmonstercloudclient.requests import HeyTapCustomTaskRequest
from capmonstercloudclient import ClientOptions, CapMonsterClient

async def solve_captcha_sync(num_requests):
return [await cap_monster_client.solve_captcha(heytap_request) for _ in range(num_requests)]

async def solve_captcha_async(num_requests):
tasks = [asyncio.create_task(cap_monster_client.solve_captcha(heytap_request))
for _ in range(num_requests)]
return await asyncio.gather(*tasks, return_exceptions=True)

if __name__ == '__main__':
key = os.getenv('API_KEY')
client_options = ClientOptions(api_key=key)
cap_monster_client = CapMonsterClient(options=client_options)
heytap_request = HeyTapCustomTaskRequest(
websiteUrl='https://example.com/',
websiteKey='your-website-key',
metadata={'apiServer': 'api.example.com'})
nums = 3

# Sync test
sync_start = time.time()
sync_responses = asyncio.run(solve_captcha_sync(nums))
print(f'average execution time sync {1/((time.time()-sync_start)/nums):0.2f} ' \
f'resp/sec\nsolution: {sync_responses[0]}')

# Async test
async_start = time.time()
async_responses = asyncio.run(solve_captcha_async(nums))
print(f'average execution time async {1/((time.time()-async_start)/nums):0.2f} ' \
f'resp/sec\nsolution: {async_responses[0]}')
Loading
Loading