Skip to content

Commit fcec35a

Browse files
committed
feat: integrate Kaleidoscope support
2 parents 23e9c9e + 84d28cb commit fcec35a

12 files changed

Lines changed: 347 additions & 29 deletions

‎README.md‎

Lines changed: 41 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -163,6 +163,7 @@ on the target page.
163163
| Image to Text | ✅ | - |
164164
| Yandex SmartCaptcha | ✅ | ✅ |
165165
| Yandex SmartCaptcha Image | ✅ | - |
166+
| Yandex SmartCaptcha Kaleidoscope | ✅ | - |
166167
| Coordinates (click captcha) | ✅ | - |
167168
| Tencent | ✅ | ✅ |
168169

@@ -215,8 +216,8 @@ solution -- wraps `create_task()` + `get_task_result()` so you don't poll by han
215216
| `language_pool` | `Optional[str]` | Worker pool selector, `"en"` or `"ru"`. |
216217
| `timeout` | `Optional[int]` | Overrides the client's default timeout for this call only, in seconds. Useful for captcha types that reliably take longer (e.g. classic reCAPTCHA v2, GeeTest, reCAPTCHA v3 with a high `minScore`). |
217218

218-
Returns the `solution` dict once `status` is `"ready"` -- its shape depends on
219-
the task type (see [Captcha Types](#captcha-types)).
219+
Returns the `solution` once `status` is `"ready"`. Most task types return a dict;
220+
Yandex SmartCaptcha Kaleidoscope returns a string.
220221
Raises `ValidationError` before any request if `task` is not a task object or a
221222
required task parameter is missing or empty. Otherwise raises `ApiError`,
222223
`CaptchaTimeoutError`, or `NetworkError`.
@@ -233,7 +234,7 @@ Raises `ValidationError` before any request if `task` is invalid (same rules as
233234

234235
Fetches the current status of a task created with `create_task()`. Always
235236
returns a dict with a `status` key (`"processing"` or `"ready"`); when
236-
`"ready"`, also has a `solution` dict. This is a single poll, not a wait --
237+
`"ready"`, also has a `solution` value. This is a single poll, not a wait --
237238
call it repeatedly (as `solve()` does) until `status` is `"ready"`.
238239
Raises `ApiError`, `CaptchaTimeoutError`, or `NetworkError`.
239240

@@ -512,7 +513,8 @@ With proxy, use `GeeTestTask` (same proxy fields as reCAPTCHA v2).
512513
<sup>[API method description.](https://captcha-solver.com/en/docs/captcha-types#yandex-smartcaptcha)</sup>
513514

514515
Use this method to solve the token-based Yandex SmartCaptcha and obtain a token
515-
for the widget on the target page. Use the dedicated image method for image challenges.
516+
for the widget on the target page. Use the dedicated image methods for visual
517+
SmartCaptcha and Kaleidoscope challenges.
516518

517519
`YandexSmartCaptchaTaskProxyless` / `YandexSmartCaptchaTask` -- token-based challenge.
518520

@@ -575,6 +577,40 @@ result = CaptchaClient("your_api_key").solve(task)
575577
print(result["coordinates"])
576578
```
577579

580+
#### Kaleidoscope puzzle
581+
582+
Use `YandexSmartCaptchaKaleidoscopeTask` for the image-based Kaleidoscope puzzle.
583+
Encode the captcha image as base64 and pass the puzzle steps as a JSON array string.
584+
The SDK sends API v2 type `PazlCaptchaTask`.
585+
586+
| Parameter | Required | Description |
587+
|---|---|---|
588+
| `image` | yes | Main captcha image, base64-encoded. |
589+
| `task` | yes | Puzzle steps serialized as a JSON array string, for example `"[15,24,4,13,10]"`. |
590+
591+
**Response:** a string containing the number of slider-arrow clicks required to
592+
solve the captcha.
593+
594+
```python
595+
import base64
596+
from captcha_solver_api import CaptchaClient
597+
from captcha_solver_api.tasks import YandexSmartCaptchaKaleidoscopeTask
598+
599+
with open("examples/assets/yandex-smartcaptcha-kaleidoscope.jpg", "rb") as f:
600+
image = base64.b64encode(f.read()).decode("utf-8")
601+
602+
task = YandexSmartCaptchaKaleidoscopeTask(
603+
image=image,
604+
task="[15,24,4,13,10]",
605+
)
606+
clicks = CaptchaClient("your_api_key").solve(task)
607+
print(clicks)
608+
```
609+
610+
Runnable examples:
611+
[sync](examples/sync/yandex_smartcaptcha_kaleidoscope.py) and
612+
[async](examples/async/yandex_smartcaptcha_kaleidoscope.py).
613+
578614
### Coordinates (click captcha)
579615

580616
<sup>[API method description.](https://captcha-solver.com/en/docs/captcha-types#coordinates)</sup>
@@ -839,6 +875,7 @@ python examples/sync/balance.py
839875
python examples/sync/image_to_text.py
840876
python examples/sync/coordinates.py
841877
python examples/sync/yandex_smartcaptcha_image.py
878+
python examples/sync/yandex_smartcaptcha_kaleidoscope.py
842879
```
843880

844881
Live checks with real parameters have exercised all supported task types.

‎captcha_solver_api/async_client.py‎

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -292,9 +292,8 @@ async def get_task_result(self, task_id: int) -> Dict[str, Any]:
292292
293293
Returns:
294294
The raw API response with `status` (`"processing"` or `"ready"`).
295-
Ready responses also contain a `solution` dict, e.g.
296-
`{"gRecaptchaResponse": "..."}` for reCAPTCHA or `{"text": "..."}`
297-
for `ImageToTextTask`.
295+
Ready responses also contain a `solution` value whose shape depends
296+
on the task type.
298297
299298
Raises:
300299
ApiError: The API reports an error for the task.
@@ -346,7 +345,7 @@ async def solve(
346345
task: Any,
347346
language_pool: Optional[str] = None,
348347
timeout: Optional[int] = None,
349-
) -> Dict[str, Any]:
348+
) -> Dict[str, Any] | str:
350349
"""Submit a task and asynchronously poll until its solution is ready.
351350
352351
This is the main entry point for the async client. It combines
@@ -366,9 +365,8 @@ async def solve(
366365
not a strict deadline for the entire call.
367366
368367
Returns:
369-
The `solution` dict once `status` is `"ready"`. Its shape depends on
370-
the task type -- see the per-type docstrings in `captcha_solver_api.tasks`
371-
or the README's method reference.
368+
The `solution` once `status` is `"ready"`. Most task types return a
369+
dict; `YandexSmartCaptchaKaleidoscopeTask` returns a string.
372370
373371
Raises:
374372
ValidationError: `task` is not a task object, or a required task
@@ -420,13 +418,12 @@ async def solve(
420418
raise
421419
continue
422420
poll_failures = 0
423-
424421
if result.get("status") == "ready":
425422
final_result = result
426423
solution = result["solution"]
427-
if not isinstance(solution, dict):
424+
if not isinstance(solution, (dict, str)) or solution == "":
428425
raise NetworkError(
429-
"API returned a ready task without a solution object",
426+
"API returned a ready task without a valid solution",
430427
task_id=task_id,
431428
)
432429
solved = True

‎captcha_solver_api/client.py‎

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -277,9 +277,8 @@ def get_task_result(self, task_id: int) -> Dict[str, Any]:
277277
278278
Returns:
279279
The raw API response. Always has a `status` key (`"processing"` or
280-
`"ready"`); when `"ready"`, also has a `solution` dict whose shape
281-
depends on the task type (e.g. `{"gRecaptchaResponse": "..."}` for
282-
reCAPTCHA, `{"text": "..."}` for `ImageToTextTask`).
280+
`"ready"`); when `"ready"`, also has a `solution` value whose shape
281+
depends on the task type.
283282
284283
Raises:
285284
ApiError: The API reports an error for this task (e.g. it expired).
@@ -329,7 +328,7 @@ def solve(
329328
task: Any,
330329
language_pool: Optional[str] = None,
331330
timeout: Optional[int] = None,
332-
) -> Dict[str, Any]:
331+
) -> Dict[str, Any] | str:
333332
"""Submits `task` and polls until it's solved. This is the main entry point --
334333
it wraps `create_task()` and `get_task_result()` so you don't have to poll
335334
by hand.
@@ -344,9 +343,8 @@ def solve(
344343
not a strict deadline for the entire call.
345344
346345
Returns:
347-
The `solution` dict once `status` is `"ready"`. Its shape depends on
348-
the task type -- see the per-type docstrings in `captcha_solver_api.tasks`
349-
or the README's method reference.
346+
The `solution` once `status` is `"ready"`. Most task types return a
347+
dict; `YandexSmartCaptchaKaleidoscopeTask` returns a string.
350348
351349
Raises:
352350
ValidationError: `task` is not a task object, or a required task
@@ -398,13 +396,12 @@ def solve(
398396
raise
399397
continue
400398
poll_failures = 0
401-
402399
if result.get("status") == "ready":
403400
final_result = result
404401
solution = result["solution"]
405-
if not isinstance(solution, dict):
402+
if not isinstance(solution, (dict, str)) or solution == "":
406403
raise NetworkError(
407-
"API returned a ready task without a solution object",
404+
"API returned a ready task without a valid solution",
408405
task_id=task_id,
409406
)
410407
solved = True

‎captcha_solver_api/tasks.py‎

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
from __future__ import annotations
1414

1515
import inspect
16+
import json
1617
from typing import Any, Dict, Optional
1718

1819
from .exceptions import ValidationError
@@ -928,6 +929,47 @@ def __init__(
928929
self.comment = comment
929930

930931

932+
class YandexSmartCaptchaKaleidoscopeTask(BaseTask):
933+
"""Image-based Yandex SmartCaptcha Kaleidoscope puzzle, sent as API type
934+
`PazlCaptchaTask`. No proxy variant exists because the image is submitted directly.
935+
936+
Args:
937+
image: Required. Main Kaleidoscope challenge image, base64-encoded
938+
without a `data:image/...;base64,` prefix.
939+
task: Required. Puzzle-step sequence captured from the same challenge,
940+
as a JSON array string or a list of integers. Preserve the original
941+
order; the sequence is challenge-specific.
942+
943+
Returns (`solution` from `solve()`):
944+
A string containing the number of slider-arrow clicks required to solve
945+
the puzzle.
946+
947+
Example:
948+
from captcha_solver_api.tasks import YandexSmartCaptchaKaleidoscopeTask
949+
950+
task = YandexSmartCaptchaKaleidoscopeTask(
951+
image="BASE64_IMAGE",
952+
task="[15,24,4,13,10]",
953+
)
954+
clicks = client.solve(task)
955+
"""
956+
957+
type = "PazlCaptchaTask"
958+
959+
def __init__(self, image: str, task: str | list[int]) -> None:
960+
"""Create a Kaleidoscope puzzle task.
961+
962+
Args:
963+
image: Main challenge image encoded as a pure Base64 string, without
964+
a data-URL prefix.
965+
task: Challenge-specific puzzle steps as a JSON array string or a list
966+
of integers, for example `"[15,24,4,13,10]"` or
967+
`[15, 24, 4, 13, 10]`. Keep the captured order unchanged.
968+
"""
969+
self.image = image
970+
self.task = json.dumps(task, separators=(",", ":")) if isinstance(task, list) else task
971+
972+
931973
class TencentTaskProxyless(BaseTask):
932974
"""Tencent captcha without proxy.
933975

‎examples/README.md‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,7 @@ script demonstrates exactly one task variant.
6767
| GeeTest v4 (proxyless / proxy) | [proxyless](sync/geetest_v4_proxyless.py) / [proxy](sync/geetest_v4_proxy.py) | [proxyless](async/geetest_v4_proxyless.py) / [proxy](async/geetest_v4_proxy.py) | `captcha_output` and related fields |
6868
| Yandex SmartCaptcha (proxyless / proxy) | [proxyless](sync/yandex_smartcaptcha_proxyless.py) / [proxy](sync/yandex_smartcaptcha_proxy.py) | [proxyless](async/yandex_smartcaptcha_proxyless.py) / [proxy](async/yandex_smartcaptcha_proxy.py) | `token` |
6969
| Yandex SmartCaptcha image | [yandex_smartcaptcha_image.py](sync/yandex_smartcaptcha_image.py) | [yandex_smartcaptcha_image.py](async/yandex_smartcaptcha_image.py) | `coordinates` |
70+
| Yandex SmartCaptcha Kaleidoscope | [yandex_smartcaptcha_kaleidoscope.py](sync/yandex_smartcaptcha_kaleidoscope.py) | [yandex_smartcaptcha_kaleidoscope.py](async/yandex_smartcaptcha_kaleidoscope.py) | `str` slider-arrow click count |
7071
| Coordinates / click captcha | [coordinates.py](sync/coordinates.py) | [coordinates.py](async/coordinates.py) | `coordinates` |
7172
| Tencent (proxyless / proxy) | [proxyless](sync/tencent_proxyless.py) / [proxy](sync/tencent_proxy.py) | [proxyless](async/tencent_proxyless.py) / [proxy](async/tencent_proxy.py) | `appid`, `ret`, `ticket`, `randstr` |
7273

@@ -77,6 +78,7 @@ Run commands from the repository root so local imports and bundled assets resolv
7778
```bash
7879
python examples/sync/balance.py
7980
python examples/sync/image_to_text.py
81+
python examples/sync/yandex_smartcaptcha_kaleidoscope.py
8082
python examples/async/recaptcha_v2_proxyless.py
8183
```
8284

104 KB
Loading
Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
"""Example: Solve an image-based Yandex SmartCaptcha Kaleidoscope asynchronously.
2+
3+
This example reads the bundled Kaleidoscope challenge image, encodes it as
4+
Base64, sends it together with the puzzle-step sequence without a proxy, and
5+
prints how many times to click the slider arrow. It uses
6+
YandexSmartCaptchaKaleidoscopeTask and AsyncCaptchaClient.solve().
7+
8+
How it works:
9+
STEP-01 - Configure AsyncCaptchaClient and locate the bundled challenge image.
10+
STEP-02 - Encode the image and create a task with the captured puzzle steps.
11+
STEP-03 - Await solve(), which creates the task and polls for its solution.
12+
STEP-04 - Print the slider-arrow click count, or report the error.
13+
14+
Prerequisites:
15+
Set the CAPTCHA_API_KEY environment variable.
16+
The sample image is bundled in examples/assets/.
17+
"""
18+
19+
import asyncio
20+
import os
21+
import sys
22+
from base64 import b64encode
23+
24+
try:
25+
from dotenv import load_dotenv
26+
except ModuleNotFoundError as exc:
27+
if exc.name != "dotenv":
28+
raise
29+
load_dotenv = None
30+
31+
repo_root = os.path.dirname(os.path.dirname(os.path.dirname(os.path.realpath(__file__))))
32+
sys.path.append(repo_root)
33+
if load_dotenv is not None:
34+
load_dotenv(os.path.join(repo_root, ".env"))
35+
36+
from captcha_solver_api import AsyncCaptchaClient
37+
from captcha_solver_api.tasks import YandexSmartCaptchaKaleidoscopeTask
38+
39+
40+
def encode_image(filename: str) -> str:
41+
"""Return an image from examples/assets as a Base64 string."""
42+
path = os.path.join(repo_root, "examples", "assets", filename)
43+
with open(path, "rb") as image_file:
44+
return b64encode(image_file.read()).decode("utf-8")
45+
46+
47+
async def main() -> None:
48+
# STEP-01: Configure AsyncCaptchaClient and locate the bundled challenge image.
49+
api_key = os.getenv("CAPTCHA_API_KEY", "YOUR_API_KEY")
50+
async with AsyncCaptchaClient(api_key) as solver:
51+
# STEP-02: Encode the image and create a task with the captured puzzle steps.
52+
# STEP-03: Await solve(), which creates the task and polls for its solution.
53+
clicks = await solver.solve(
54+
YandexSmartCaptchaKaleidoscopeTask(
55+
# Base64-encoded Kaleidoscope image (required).
56+
image=encode_image("yandex-smartcaptcha-kaleidoscope.jpg"),
57+
# JSON array string captured from this challenge (required).
58+
# Preserve the original order; the sequence is challenge-specific.
59+
task="[7,15,14,0,11,6,6,0,11,15,6,10,1,14,3,12,9,0,15,1,5,1,8,11,12,11,0,12,1,10,1,4,14,6,10,6,10,8,3,0,5,9,7,8,0,3,8,0,9,12,12,11,3,0,8,10]",
60+
)
61+
)
62+
# STEP-04: Print the slider-arrow click count, or report the error.
63+
# Unlike most SDK tasks, this task returns a plain string rather than a dict.
64+
# Click the Kaleidoscope slider arrow this many times to complete the puzzle.
65+
# Example: "8"
66+
print("Slider arrow clicks: " + str(clicks))
67+
68+
69+
if __name__ == "__main__":
70+
try:
71+
asyncio.run(main())
72+
except Exception as exc:
73+
sys.exit(exc)
Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
"""Example: Solve an image-based Yandex SmartCaptcha Kaleidoscope puzzle.
2+
3+
This example reads the bundled Kaleidoscope challenge image, encodes it as
4+
Base64, sends it together with the puzzle-step sequence without a proxy, and
5+
prints how many times to click the slider arrow. It uses
6+
YandexSmartCaptchaKaleidoscopeTask and CaptchaClient.solve().
7+
8+
How it works:
9+
STEP-01 - Configure CaptchaClient and locate the bundled challenge image.
10+
STEP-02 - Encode the image and create a task with the captured puzzle steps.
11+
STEP-03 - Call solve(), which creates the task and polls for its solution.
12+
STEP-04 - Print the slider-arrow click count, or report the error.
13+
14+
Prerequisites:
15+
Set the CAPTCHA_API_KEY environment variable.
16+
The sample image is bundled in examples/assets/.
17+
"""
18+
19+
import os
20+
import sys
21+
from base64 import b64encode
22+
23+
try:
24+
from dotenv import load_dotenv
25+
except ModuleNotFoundError as exc:
26+
if exc.name != "dotenv":
27+
raise
28+
load_dotenv = None
29+
30+
repo_root = os.path.dirname(os.path.dirname(os.path.dirname(os.path.realpath(__file__))))
31+
sys.path.append(repo_root)
32+
if load_dotenv is not None:
33+
load_dotenv(os.path.join(repo_root, ".env"))
34+
35+
from captcha_solver_api import CaptchaClient
36+
from captcha_solver_api.tasks import YandexSmartCaptchaKaleidoscopeTask
37+
38+
39+
def encode_image(filename: str) -> str:
40+
"""Return an image from examples/assets as a Base64 string."""
41+
path = os.path.join(repo_root, "examples", "assets", filename)
42+
with open(path, "rb") as image_file:
43+
return b64encode(image_file.read()).decode("utf-8")
44+
45+
46+
# STEP-01: Configure CaptchaClient and locate the bundled challenge image.
47+
api_key = os.getenv("CAPTCHA_API_KEY", "YOUR_API_KEY")
48+
solver = CaptchaClient(api_key)
49+
50+
try:
51+
# STEP-02: Encode the image and create a task with the captured puzzle steps.
52+
# STEP-03: Call solve(), which creates the task and polls for its solution.
53+
clicks = solver.solve(
54+
YandexSmartCaptchaKaleidoscopeTask(
55+
# Base64-encoded Kaleidoscope image (required).
56+
image=encode_image("yandex-smartcaptcha-kaleidoscope.jpg"),
57+
# JSON array string captured from this challenge (required).
58+
# Preserve the original order; the sequence is challenge-specific.
59+
task="[7,15,14,0,11,6,6,0,11,15,6,10,1,14,3,12,9,0,15,1,5,1,8,11,12,11,0,12,1,10,1,4,14,6,10,6,10,8,3,0,5,9,7,8,0,3,8,0,9,12,12,11,3,0,8,10]",
60+
)
61+
)
62+
# STEP-04: Print the slider-arrow click count, or report the error.
63+
# Unlike most SDK tasks, this task returns a plain string rather than a dict.
64+
# Click the Kaleidoscope slider arrow this many times to complete the puzzle.
65+
# Example: "8"
66+
print("Slider arrow clicks: " + str(clicks))
67+
except Exception as exc:
68+
sys.exit(exc)

0 commit comments

Comments
 (0)