capmonster-python 4.0.0__py3-none-any.whl → 5.1.0__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (37) hide show
  1. capmonster_python/__init__.py +29 -0
  2. capmonster_python/_deprecation.py +24 -0
  3. capmonster_python/client.py +232 -32
  4. capmonster_python/methods.py +25 -0
  5. capmonster_python/tasks/__init__.py +46 -3
  6. capmonster_python/tasks/alibaba.py +69 -0
  7. capmonster_python/tasks/altcha.py +48 -0
  8. capmonster_python/tasks/amazon.py +54 -0
  9. capmonster_python/tasks/arcaptcha.py +23 -0
  10. capmonster_python/tasks/castle.py +53 -0
  11. capmonster_python/tasks/complex_image_recognition.py +30 -6
  12. capmonster_python/tasks/datadome.py +8 -0
  13. capmonster_python/tasks/fengkongcloud.py +39 -0
  14. capmonster_python/tasks/friendly.py +43 -0
  15. capmonster_python/tasks/funcaptcha.py +45 -0
  16. capmonster_python/tasks/heytap.py +40 -0
  17. capmonster_python/tasks/hunt.py +80 -0
  18. capmonster_python/tasks/imperva.py +40 -7
  19. capmonster_python/tasks/mtcaptcha.py +36 -0
  20. capmonster_python/tasks/proton.py +40 -0
  21. capmonster_python/tasks/recaptcha_click.py +39 -0
  22. capmonster_python/tasks/recaptcha_v2.py +4 -0
  23. capmonster_python/tasks/recaptcha_v2_enterprise.py +7 -1
  24. capmonster_python/tasks/recaptcha_v3.py +4 -0
  25. capmonster_python/tasks/recaptcha_v3_enterprise.py +30 -0
  26. capmonster_python/tasks/temu.py +7 -0
  27. capmonster_python/tasks/tendi.py +18 -2
  28. capmonster_python/tasks/tspd.py +44 -0
  29. capmonster_python/tasks/turnstile.py +34 -7
  30. capmonster_python/tasks/yidun.py +49 -0
  31. capmonster_python-5.1.0.dist-info/METADATA +247 -0
  32. capmonster_python-5.1.0.dist-info/RECORD +43 -0
  33. {capmonster_python-4.0.0.dist-info → capmonster_python-5.1.0.dist-info}/WHEEL +1 -1
  34. capmonster_python-4.0.0.dist-info/METADATA +0 -150
  35. capmonster_python-4.0.0.dist-info/RECORD +0 -26
  36. {capmonster_python-4.0.0.dist-info → capmonster_python-5.1.0.dist-info}/licenses/LICENSE +0 -0
  37. {capmonster_python-4.0.0.dist-info → capmonster_python-5.1.0.dist-info}/top_level.txt +0 -0
@@ -1,32 +1,61 @@
1
1
  from .client import CapmonsterClient
2
+ from .methods import TaskResult
2
3
  from .exceptions import *
3
4
  from .tasks import *
4
5
 
5
6
  __all__ = [
6
7
  "CapmonsterClient",
8
+ "TaskResult",
7
9
  "VanillaTaskPayload",
8
10
  "ProxyPayload",
9
11
  "UserAgentPayload",
12
+ "AlibabaTask",
13
+ "AlibabaMetadata",
14
+ "AltchaTask",
15
+ "AltchaMetadata",
16
+ "AmazonTask",
17
+ "ARCaptchaTask",
10
18
  "BasiliskTask",
11
19
  "BinanceTask",
20
+ "CastleTask",
21
+ "CastleMetadata",
12
22
  "ComplexImageRecaptchaTask",
13
23
  "ComplexImageRecaptchaMetadata",
14
24
  "ComplexImageRecognitionTask",
15
25
  "DataDomeTask",
16
26
  "DataDomeMetadata",
27
+ "FengkongCloudTask",
28
+ "FengkongCloudMetadata",
29
+ "FriendlyTask",
30
+ "FriendlyMetadata",
31
+ "FunCaptchaTask",
17
32
  "GeeTestV3Task",
18
33
  "GeeTestV4Task",
34
+ "HeyTapTask",
35
+ "HeyTapMetadata",
36
+ "HuntTask",
37
+ "HuntMetadata",
19
38
  "ImageToTextTask",
20
39
  "ImpervaTask",
21
40
  "ImpervaTaskMetadata",
41
+ "MTCaptchaTask",
22
42
  "ProsopoTask",
43
+ "ProtonTask",
44
+ "ProtonMetadata",
45
+ "RecaptchaClickTask",
23
46
  "RecaptchaV2Task",
24
47
  "RecaptchaV2EnterpriseTask",
25
48
  "RecaptchaV3Task",
49
+ "RecaptchaV3EnterpriseTask",
26
50
  "TemuTask",
27
51
  "TenDITask",
52
+ "TenDIMetadata",
53
+ "TSPDTask",
54
+ "TSPDMetadata",
28
55
  "TurnstileTask",
29
56
  "TurnstileCloudFlareTask",
57
+ "TurnstileWaitingRoomTask",
58
+ "YidunTask",
30
59
  "CapmonsterException",
31
60
  "CapmonsterAPIException",
32
61
  "CapmonsterValidationException"
@@ -0,0 +1,24 @@
1
+ import warnings
2
+
3
+
4
+ def warn_deprecated(message: str, stacklevel: int = 3) -> None:
5
+ """
6
+ Emits a DeprecationWarning pointing at the caller's code.
7
+
8
+ Args:
9
+ message: What is deprecated and what to use instead.
10
+ stacklevel: How many frames up the warning should point to.
11
+ """
12
+ warnings.warn(message, DeprecationWarning, stacklevel=stacklevel)
13
+
14
+
15
+ def warn_proxy_required(task: str, stacklevel: int = 3) -> None:
16
+ """
17
+ Emits a UserWarning when a task that the API documents as proxy-only is created without a proxy.
18
+
19
+ Args:
20
+ task: Name of the task class.
21
+ stacklevel: How many frames up the warning should point to.
22
+ """
23
+ warnings.warn(f"{task}: CapMonster Cloud requires your own proxy for this task; "
24
+ f"the request will likely be rejected without one.", UserWarning, stacklevel=stacklevel)
@@ -5,7 +5,8 @@ from typing import Optional
5
5
  from httpx import Response, AsyncClient, Client
6
6
 
7
7
  from .exceptions import CapmonsterAPIException, CapmonsterException
8
- from .methods import GetBalancePayload, GetTaskResultPayload, CreateTaskPayload
8
+ from .methods import GetBalancePayload, GetTaskResultPayload, CreateTaskPayload, ReportIncorrectCaptchaPayload, \
9
+ TaskResult
9
10
  from .tasks.task import TaskPayload
10
11
 
11
12
 
@@ -14,14 +15,31 @@ class CapmonsterClient:
14
15
  __BALANCE_URL = "/getBalance"
15
16
  __TASK_RESULT_URL = "/getTaskResult"
16
17
  __CREATE_TASK_URL = "/createTask"
17
- __MAX_RETRY = 120
18
- __PER_RETRY_DELAY = 1
19
18
 
20
- def __init__(self, api_key: str, timeout: Optional[float] = 30.0) -> None:
19
+ __REPORT_IMAGE_URL = "/reportIncorrectImageCaptcha"
20
+ __REPORT_TOKEN_URL = "/reportIncorrectTokenCaptcha"
21
+ __USER_AGENT_URL = "https://capmonster.cloud/api/useragent/actual"
22
+
23
+ def __init__(self, api_key: str, timeout: Optional[float] = 30.0,
24
+ max_retries: int = 120, retry_delay: float = 2.0) -> None:
21
25
  self.api_key = api_key
26
+ self.__max_retries = max_retries
27
+ self.__retry_delay = retry_delay
22
28
  self.__async_client = AsyncClient(timeout=timeout, base_url=self.__BASE_URL)
23
29
  self.__sync_client = Client(timeout=timeout, base_url=self.__BASE_URL)
24
30
 
31
+ def __enter__(self) -> "CapmonsterClient":
32
+ return self
33
+
34
+ def __exit__(self, *args) -> None:
35
+ self.__sync_client.close()
36
+
37
+ async def __aenter__(self) -> "CapmonsterClient":
38
+ return self
39
+
40
+ async def __aexit__(self, *args) -> None:
41
+ await self.__async_client.aclose()
42
+
25
43
  def get_balance(self) -> float:
26
44
  """
27
45
  Fetches the current balance using the provided API key.
@@ -84,7 +102,7 @@ class CapmonsterClient:
84
102
  Asynchronously creates a task based on the provided payload and returns the task ID.
85
103
 
86
104
  This method is responsible for initiating a task by preparing the request with the
87
- provided task details and optional callback URL, sending a synchronous request to the
105
+ provided task details and optional callback URL, sending an asynchronous request to the
88
106
  task creation endpoint, and parsing the response to retrieve the task ID.
89
107
 
90
108
  Args:
@@ -123,9 +141,22 @@ class CapmonsterClient:
123
141
  result API endpoint. If the solution is not found in the response, an empty
124
142
  dictionary is returned.
125
143
  """
144
+ return self.get_task_result_detailed(task_id).solution
145
+
146
+ def get_task_result_detailed(self, task_id: int) -> TaskResult:
147
+ """
148
+ Fetches the full result of a specific task by its identifier, including its status and cost.
149
+
150
+ Args:
151
+ task_id (int): An integer representing the unique identifier of the task.
152
+
153
+ Returns:
154
+ TaskResult: The status, solution and cost of the task. The solution is an empty
155
+ dictionary and the cost is None while the task is processing.
156
+ """
126
157
  payload = GetTaskResultPayload(clientKey=self.api_key, taskId=task_id).model_dump()
127
158
  response = self.__make_sync_request(self.__TASK_RESULT_URL, payload).json()
128
- return response.get("solution", {})
159
+ return TaskResult.from_response(response)
129
160
 
130
161
  async def get_task_result_async(self, task_id: int) -> dict:
131
162
  """
@@ -145,10 +176,22 @@ class CapmonsterClient:
145
176
  result API endpoint. If the solution is not found in the response, an empty
146
177
  dictionary is returned.
147
178
  """
179
+ return (await self.get_task_result_detailed_async(task_id)).solution
180
+
181
+ async def get_task_result_detailed_async(self, task_id: int) -> TaskResult:
182
+ """
183
+ Asynchronously fetches the full result of a specific task by its identifier, including its status and cost.
184
+
185
+ Args:
186
+ task_id (int): An integer representing the unique identifier of the task.
187
+
188
+ Returns:
189
+ TaskResult: The status, solution and cost of the task. The solution is an empty
190
+ dictionary and the cost is None while the task is processing.
191
+ """
148
192
  payload = GetTaskResultPayload(clientKey=self.api_key, taskId=task_id).model_dump()
149
193
  request = await self.__make_async_request(self.__TASK_RESULT_URL, payload)
150
- response = request.json()
151
- return response.get("solution", {})
194
+ return TaskResult.from_response(request.json())
152
195
 
153
196
  def join_task_result(self, task_id: int) -> dict:
154
197
  """
@@ -166,16 +209,31 @@ class CapmonsterClient:
166
209
  CapmonsterException:
167
210
  If the maximum retry limit is exceeded without obtaining the task result.
168
211
  """
169
- for _ in range(0, self.__MAX_RETRY + 1):
170
- result = self.get_task_result(task_id)
171
- if result:
212
+ return self.join_task_result_detailed(task_id).solution
213
+
214
+ def join_task_result_detailed(self, task_id: int) -> TaskResult:
215
+ """
216
+ Polls the result of a task like `join_task_result`, but returns its status and cost too.
217
+
218
+ Args:
219
+ task_id: The identifier of the task for which the result needs to be retrieved.
220
+
221
+ Returns:
222
+ TaskResult: The status, solution and cost of the completed task.
223
+
224
+ Raises:
225
+ CapmonsterException:
226
+ If the maximum retry limit is exceeded without obtaining the task result.
227
+ """
228
+ for _ in range(0, self.__max_retries + 1):
229
+ result = self.get_task_result_detailed(task_id)
230
+ if result.solution:
172
231
  return result
173
- elif not result:
174
- sleep(self.__PER_RETRY_DELAY)
232
+ sleep(self.__retry_delay)
175
233
  raise CapmonsterAPIException(
176
234
  61, "ERROR_MAXIMUM_TIME_EXCEED", "Maximum time is exceed.")
177
235
 
178
- async def join_task_result_async(self, task_id: int):
236
+ async def join_task_result_async(self, task_id: int) -> dict:
179
237
  """
180
238
  Asynchronously joins and retrieves the result of a task given its ID, retrying a specified number
181
239
  of times if the result is not immediately available.
@@ -191,19 +249,172 @@ class CapmonsterClient:
191
249
  CapmonsterException:
192
250
  If the maximum retry limit is exceeded without obtaining the task result.
193
251
  """
194
- for _ in range(0, self.__MAX_RETRY + 1):
195
- result = await self.get_task_result_async(task_id)
196
- if result:
252
+ return (await self.join_task_result_detailed_async(task_id)).solution
253
+
254
+ async def join_task_result_detailed_async(self, task_id: int) -> TaskResult:
255
+ """
256
+ Asynchronously polls the result of a task like `join_task_result_async`, but returns its status and cost too.
257
+
258
+ Args:
259
+ task_id: The identifier of the task for which the result needs to be retrieved.
260
+
261
+ Returns:
262
+ TaskResult: The status, solution and cost of the completed task.
263
+
264
+ Raises:
265
+ CapmonsterException:
266
+ If the maximum retry limit is exceeded without obtaining the task result.
267
+ """
268
+ for _ in range(0, self.__max_retries + 1):
269
+ result = await self.get_task_result_detailed_async(task_id)
270
+ if result.solution:
197
271
  return result
198
- elif not result:
199
- await asyncio.sleep(self.__PER_RETRY_DELAY)
272
+ await asyncio.sleep(self.__retry_delay)
200
273
  raise CapmonsterAPIException(
201
274
  61, "ERROR_MAXIMUM_TIME_EXCEED", "Maximum time is exceed.")
202
275
 
276
+ def solve(self, task: TaskPayload, callback_url: Optional[str] = None) -> dict:
277
+ """
278
+ Convenience method that creates a task and polls for its result.
279
+
280
+ Equivalent to calling create_task() followed by join_task_result().
281
+
282
+ Args:
283
+ task: The task configuration payload.
284
+ callback_url: An optional callback URL for task completion.
285
+
286
+ Returns:
287
+ dict: The solution dictionary from the completed task.
288
+ """
289
+ return self.solve_detailed(task, callback_url).solution
290
+
291
+ def solve_detailed(self, task: TaskPayload, callback_url: Optional[str] = None) -> TaskResult:
292
+ """
293
+ Creates a task and polls for its result like `solve`, but returns its status and cost too.
294
+
295
+ Args:
296
+ task: The task configuration payload.
297
+ callback_url: An optional callback URL for task completion.
298
+
299
+ Returns:
300
+ TaskResult: The status, solution and cost of the completed task.
301
+ """
302
+ task_id = self.create_task(task, callback_url)
303
+ return self.join_task_result_detailed(task_id)
304
+
305
+ async def solve_async(self, task: TaskPayload, callback_url: Optional[str] = None) -> dict:
306
+ """
307
+ Async convenience method that creates a task and polls for its result.
308
+
309
+ Equivalent to calling create_task_async() followed by join_task_result_async().
310
+
311
+ Args:
312
+ task: The task configuration payload.
313
+ callback_url: An optional callback URL for task completion.
314
+
315
+ Returns:
316
+ dict: The solution dictionary from the completed task.
317
+ """
318
+ return (await self.solve_detailed_async(task, callback_url)).solution
319
+
320
+ async def solve_detailed_async(self, task: TaskPayload, callback_url: Optional[str] = None) -> TaskResult:
321
+ """
322
+ Async version of `solve_detailed`: creates a task and polls for its result, including its status and cost.
323
+
324
+ Args:
325
+ task: The task configuration payload.
326
+ callback_url: An optional callback URL for task completion.
327
+
328
+ Returns:
329
+ TaskResult: The status, solution and cost of the completed task.
330
+ """
331
+ task_id = await self.create_task_async(task, callback_url)
332
+ return await self.join_task_result_detailed_async(task_id)
333
+
334
+ def report_incorrect_image(self, task_id: int) -> None:
335
+ """
336
+ Reports an incorrect image captcha solution.
337
+
338
+ Args:
339
+ task_id: The identifier of the task to report.
340
+
341
+ Raises:
342
+ CapmonsterAPIException: If the API returns an error.
343
+ """
344
+ payload = ReportIncorrectCaptchaPayload(clientKey=self.api_key, taskId=task_id).model_dump()
345
+ self.__make_sync_request(self.__REPORT_IMAGE_URL, payload)
346
+
347
+ async def report_incorrect_image_async(self, task_id: int) -> None:
348
+ """
349
+ Asynchronously reports an incorrect image captcha solution.
350
+
351
+ Args:
352
+ task_id: The identifier of the task to report.
353
+
354
+ Raises:
355
+ CapmonsterAPIException: If the API returns an error.
356
+ """
357
+ payload = ReportIncorrectCaptchaPayload(clientKey=self.api_key, taskId=task_id).model_dump()
358
+ await self.__make_async_request(self.__REPORT_IMAGE_URL, payload)
359
+
360
+ def report_incorrect_token(self, task_id: int) -> None:
361
+ """
362
+ Reports an incorrect token captcha solution (reCAPTCHA, GeeTest, Turnstile, etc.).
363
+
364
+ Args:
365
+ task_id: The identifier of the task to report.
366
+
367
+ Raises:
368
+ CapmonsterAPIException: If the API returns an error.
369
+ """
370
+ payload = ReportIncorrectCaptchaPayload(clientKey=self.api_key, taskId=task_id).model_dump()
371
+ self.__make_sync_request(self.__REPORT_TOKEN_URL, payload)
372
+
373
+ async def report_incorrect_token_async(self, task_id: int) -> None:
374
+ """
375
+ Asynchronously reports an incorrect token captcha solution (reCAPTCHA, GeeTest, Turnstile, etc.).
376
+
377
+ Args:
378
+ task_id: The identifier of the task to report.
379
+
380
+ Raises:
381
+ CapmonsterAPIException: If the API returns an error.
382
+ """
383
+ payload = ReportIncorrectCaptchaPayload(clientKey=self.api_key, taskId=task_id).model_dump()
384
+ await self.__make_async_request(self.__REPORT_TOKEN_URL, payload)
385
+
386
+ def get_user_agent(self) -> str:
387
+ """
388
+ Fetches the current valid Windows User-Agent string from CapMonster Cloud.
389
+
390
+ Returns:
391
+ str: The current User-Agent string to use with captcha tasks.
392
+ """
393
+ try:
394
+ response = self.__sync_client.get(self.__USER_AGENT_URL)
395
+ return response.text
396
+ except Exception as e:
397
+ raise CapmonsterException(-1, type(e).__name__, str(e))
398
+
399
+ async def get_user_agent_async(self) -> str:
400
+ """
401
+ Asynchronously fetches the current valid Windows User-Agent string from CapMonster Cloud.
402
+
403
+ Returns:
404
+ str: The current User-Agent string to use with captcha tasks.
405
+ """
406
+ try:
407
+ response = await self.__async_client.get(self.__USER_AGENT_URL)
408
+ return response.text
409
+ except Exception as e:
410
+ raise CapmonsterException(-1, type(e).__name__, str(e))
411
+
203
412
  def __make_sync_request(self, url: str, payload: dict) -> Response:
204
413
  try:
205
414
  response = self.__sync_client.post(url, json=payload)
206
415
  return self.__check_response(response)
416
+ except CapmonsterException:
417
+ raise
207
418
  except Exception as e:
208
419
  raise CapmonsterException(-1, type(e).__name__, str(e))
209
420
 
@@ -211,22 +422,11 @@ class CapmonsterClient:
211
422
  try:
212
423
  post = await self.__async_client.post(url, json=payload)
213
424
  return self.__check_response(post)
425
+ except CapmonsterException:
426
+ raise
214
427
  except Exception as e:
215
428
  raise CapmonsterException(-1, type(e).__name__, str(e))
216
429
 
217
- @staticmethod
218
- def __is_ready(response: dict):
219
- status = response.get("status")
220
- if status == "processing":
221
- return False
222
- elif status == "ready":
223
- return True
224
- else:
225
- raise CapmonsterAPIException(error_id=-1,
226
- error_code="CAPMONSTER_API_ERROR",
227
- error_description="Sometimes can be happen if Capmonster "
228
- "servers there is too much intensity")
229
-
230
430
  @staticmethod
231
431
  def __check_response(data: Response) -> Response:
232
432
  response = data.json()
@@ -21,6 +21,11 @@ class GetTaskResultPayload(BaseModel):
21
21
  taskId: int = Field(..., description="ID which was obtained from create task method.")
22
22
 
23
23
 
24
+ class ReportIncorrectCaptchaPayload(BaseModel):
25
+ clientKey: str = Field(..., description="Client key")
26
+ taskId: int = Field(..., description="ID of the task to report as incorrect.")
27
+
28
+
24
29
  class CreateTaskPayload(BaseModel):
25
30
  clientKey: str = Field(..., description="Client key")
26
31
  task: TaskPayload = Field(..., description="Task data")
@@ -30,3 +35,23 @@ class CreateTaskPayload(BaseModel):
30
35
  @field_serializer("task")
31
36
  def serialize_task(self, task: TaskPayload, _info) -> dict:
32
37
  return task.to_request()
38
+
39
+
40
+ class TaskResult(BaseModel):
41
+ """
42
+ Represents the full result of a task returned by getTaskResult.
43
+
44
+ Attributes:
45
+ status (str): "processing" while the task is being solved, "ready" when it is done.
46
+ solution (dict): The solution of the task; empty while the task is processing.
47
+ cost (Optional[float]): Cost of the task in USD; only returned when the task is ready.
48
+ """
49
+ status: str = Field(default="processing", description="Task status: processing or ready.")
50
+ solution: dict = Field(default_factory=dict, description="Task solution.")
51
+ cost: Optional[float] = Field(default=None, description="Cost of the task in USD.")
52
+
53
+ @classmethod
54
+ def from_response(cls, response: dict) -> "TaskResult":
55
+ return cls(status=response.get("status") or "processing",
56
+ solution=response.get("solution") or {},
57
+ cost=response.get("cost"))
@@ -1,42 +1,85 @@
1
+ from .alibaba import AlibabaTask, AlibabaMetadata
2
+ from .altcha import AltchaTask, AltchaMetadata
3
+ from .amazon import AmazonTask
4
+ from .arcaptcha import ARCaptchaTask
1
5
  from .basilisk import BasiliskTask
2
6
  from .binance import BinanceTask
7
+ from .castle import CastleTask, CastleMetadata
3
8
  from .complex_image_recaptcha import ComplexImageRecaptchaTask, ComplexImageRecaptchaMetadata
4
9
  from .complex_image_recognition import ComplexImageRecognitionTask
5
10
  from .datadome import DataDomeTask, DataDomeMetadata
11
+ from .fengkongcloud import FengkongCloudTask, FengkongCloudMetadata
12
+ from .friendly import FriendlyTask, FriendlyMetadata
13
+ from .funcaptcha import FunCaptchaTask
6
14
  from .geetest import GeeTestV4Task, GeeTestV3Task
15
+ from .heytap import HeyTapTask, HeyTapMetadata
16
+ from .hunt import HuntTask, HuntMetadata
7
17
  from .image_to_text import ImageToTextTask
8
18
  from .imperva import ImpervaTask, ImpervaTaskMetadata
19
+ from .mtcaptcha import MTCaptchaTask
9
20
  from .prosopo import ProsopoTask
21
+ from .proton import ProtonTask, ProtonMetadata
22
+ from .recaptcha_click import RecaptchaClickTask
10
23
  from .recaptcha_v2 import RecaptchaV2Task
11
24
  from .recaptcha_v2_enterprise import RecaptchaV2EnterpriseTask
12
25
  from .recaptcha_v3 import RecaptchaV3Task
26
+ from .recaptcha_v3_enterprise import RecaptchaV3EnterpriseTask
13
27
  from .task import VanillaTaskPayload, ProxyPayload, UserAgentPayload
14
28
  from .temu import TemuTask
15
- from .tendi import TenDITask
16
- from .turnstile import TurnstileTask, TurnstileCloudFlareTask
29
+ from .tendi import TenDITask, TenDIMetadata
30
+ from .tspd import TSPDTask, TSPDMetadata
31
+ from .turnstile import TurnstileTask, TurnstileCloudFlareTask, TurnstileWaitingRoomTask
32
+ from .yidun import YidunTask
17
33
 
18
34
  __all__ = [
19
35
  "VanillaTaskPayload",
20
36
  "ProxyPayload",
21
37
  "UserAgentPayload",
38
+ "AlibabaTask",
39
+ "AlibabaMetadata",
40
+ "AltchaTask",
41
+ "AltchaMetadata",
42
+ "AmazonTask",
43
+ "ARCaptchaTask",
22
44
  "BasiliskTask",
23
45
  "BinanceTask",
46
+ "CastleTask",
47
+ "CastleMetadata",
24
48
  "ComplexImageRecaptchaTask",
25
49
  "ComplexImageRecaptchaMetadata",
26
50
  "ComplexImageRecognitionTask",
27
51
  "DataDomeTask",
28
52
  "DataDomeMetadata",
53
+ "FengkongCloudTask",
54
+ "FengkongCloudMetadata",
55
+ "FriendlyTask",
56
+ "FriendlyMetadata",
57
+ "FunCaptchaTask",
29
58
  "GeeTestV3Task",
30
59
  "GeeTestV4Task",
60
+ "HeyTapTask",
61
+ "HeyTapMetadata",
62
+ "HuntTask",
63
+ "HuntMetadata",
31
64
  "ImageToTextTask",
32
65
  "ImpervaTask",
33
66
  "ImpervaTaskMetadata",
67
+ "MTCaptchaTask",
34
68
  "ProsopoTask",
69
+ "ProtonTask",
70
+ "ProtonMetadata",
71
+ "RecaptchaClickTask",
35
72
  "RecaptchaV2Task",
36
73
  "RecaptchaV2EnterpriseTask",
37
74
  "RecaptchaV3Task",
75
+ "RecaptchaV3EnterpriseTask",
38
76
  "TemuTask",
39
77
  "TenDITask",
78
+ "TenDIMetadata",
79
+ "TSPDTask",
80
+ "TSPDMetadata",
40
81
  "TurnstileTask",
41
- "TurnstileCloudFlareTask"
82
+ "TurnstileCloudFlareTask",
83
+ "TurnstileWaitingRoomTask",
84
+ "YidunTask"
42
85
  ]
@@ -0,0 +1,69 @@
1
+ from typing import Any, Optional
2
+
3
+ from pydantic import Field, BaseModel, model_validator
4
+
5
+ from .task import TaskPayload, ProxyPayload, UserAgentPayload
6
+ from ..exceptions import CapmonsterValidationException
7
+
8
+
9
+ class AlibabaMetadata(BaseModel):
10
+ """
11
+ Metadata for Alibaba task.
12
+
13
+ `sceneId` and `prefix` are required unless `punishUrl` is given. Pass the other
14
+ fields only if the website uses them.
15
+
16
+ Attributes:
17
+ sceneId: The captcha scenario identifier.
18
+ prefix: Captcha initialization parameter (the subdomain of the captcha-open URL).
19
+ userId: Unique identifier of the user or session on the website side.
20
+ userUserId: Additional (secondary) user identifier.
21
+ verifyType: Version or type of the verification mechanism, e.g. "1.0".
22
+ region: Region that processes the captcha, e.g. "cn" or "sgp".
23
+ UserCertifyId: Verification ID of the current captcha session.
24
+ apiGetLib: Link to the captcha JS library used by the website.
25
+ punishUrl: Full URL of the /punish verification page, including its query string.
26
+ cookieRequired: Return cookies with the solution (for Alibaba WAF).
27
+ """
28
+ sceneId: Optional[str] = Field(default=None, description="The captcha scenario identifier.")
29
+ prefix: Optional[str] = Field(default=None, description="Captcha initialization parameter.")
30
+ userId: Optional[str] = Field(default=None, description="User or session identifier.")
31
+ userUserId: Optional[str] = Field(default=None, description="Secondary user identifier.")
32
+ verifyType: Optional[str] = Field(default=None, description="Verification mechanism version.")
33
+ region: Optional[str] = Field(default=None, description="Region that processes the captcha.")
34
+ UserCertifyId: Optional[str] = Field(default=None, description="Verification ID of the captcha session.")
35
+ apiGetLib: Optional[str] = Field(default=None, description="Link to the captcha JS library.")
36
+ punishUrl: Optional[str] = Field(default=None, description="Full URL of the /punish verification page.")
37
+ cookieRequired: Optional[bool] = Field(default=None, description="Return cookies with the solution.")
38
+
39
+ @model_validator(mode="after")
40
+ def check_required(self) -> "AlibabaMetadata":
41
+ if self.punishUrl is None and (self.sceneId is None or self.prefix is None):
42
+ raise CapmonsterValidationException("sceneId and prefix are required unless punishUrl is set",
43
+ task="AlibabaTask")
44
+ return self
45
+
46
+
47
+ class AlibabaTask(TaskPayload, UserAgentPayload):
48
+ """
49
+ Represents a task for solving Alibaba captcha challenges.
50
+
51
+ Uses CustomTask type with class "alibaba".
52
+
53
+ Attributes:
54
+ websiteURL: Full URL of the page with the captcha.
55
+ metadata: Alibaba-specific metadata.
56
+ proxy: Optional proxy settings.
57
+ """
58
+ type: str = Field(default="CustomTask", frozen=True)
59
+ class_: str = Field(default="alibaba", alias="class", frozen=True)
60
+ websiteURL: str = Field(..., description='Full URL of the page with the captcha.')
61
+ metadata: AlibabaMetadata = Field(..., description='Alibaba-specific metadata.')
62
+ proxy: Optional[ProxyPayload] = Field(default=None, description='Proxy settings.')
63
+
64
+ def to_request(self) -> dict[str, Any]:
65
+ base = self.model_dump(exclude_none=True, by_alias=True)
66
+ proxy_dict = base.pop("proxy", {})
67
+ if proxy_dict:
68
+ base.update(proxy_dict)
69
+ return base
@@ -0,0 +1,48 @@
1
+ from typing import Any, Optional
2
+
3
+ from pydantic import Field, BaseModel
4
+
5
+ from .task import TaskPayload, ProxyPayload, UserAgentPayload
6
+
7
+
8
+ class AltchaMetadata(BaseModel):
9
+ """
10
+ Metadata for Altcha task.
11
+
12
+ Attributes:
13
+ challenge: Unique task identifier obtained from the website.
14
+ iterations: Number of iterations (corresponds to maxnumber value).
15
+ salt: Salt obtained from the site, used for hash generation.
16
+ signature: Digital signature of the request.
17
+ """
18
+ challenge: str = Field(..., description='Unique task identifier obtained from the website.')
19
+ iterations: str = Field(..., description='Number of iterations (corresponds to maxnumber value).')
20
+ salt: str = Field(..., description='Salt obtained from the site, used for hash generation.')
21
+ signature: str = Field(..., description='Digital signature of the request.')
22
+
23
+
24
+ class AltchaTask(TaskPayload, UserAgentPayload):
25
+ """
26
+ Represents a task for solving Altcha challenges.
27
+
28
+ Uses CustomTask type with class "altcha".
29
+
30
+ Attributes:
31
+ websiteURL: Main page URL where Altcha is located.
32
+ websiteKey: For this task, sending an empty string is allowed.
33
+ metadata: Altcha-specific metadata (challenge, iterations, salt, signature).
34
+ proxy: Optional proxy settings.
35
+ """
36
+ type: str = Field(default="CustomTask", frozen=True)
37
+ class_: str = Field(default="altcha", alias="class", frozen=True)
38
+ websiteURL: str = Field(..., description='Main page URL where Altcha is located.')
39
+ websiteKey: str = Field(default="", description='For this task, sending an empty string is allowed.')
40
+ metadata: AltchaMetadata = Field(..., description='Altcha-specific metadata.')
41
+ proxy: Optional[ProxyPayload] = Field(default=None, description='Proxy settings.')
42
+
43
+ def to_request(self) -> dict[str, Any]:
44
+ base = self.model_dump(exclude_none=True, by_alias=True)
45
+ proxy_dict = base.pop("proxy", {})
46
+ if proxy_dict:
47
+ base.update(proxy_dict)
48
+ return base