python-rucaptcha 6.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.
- python_rucaptcha/__init__.py +0 -0
- python_rucaptcha/__version__.py +1 -0
- python_rucaptcha/amazon_waf.py +114 -0
- python_rucaptcha/audio_captcha.py +161 -0
- python_rucaptcha/bounding_box_captcha.py +310 -0
- python_rucaptcha/capy_puzzle.py +138 -0
- python_rucaptcha/control.py +174 -0
- python_rucaptcha/coordinates_captcha.py +295 -0
- python_rucaptcha/core/__init__.py +0 -0
- python_rucaptcha/core/base.py +244 -0
- python_rucaptcha/core/config.py +21 -0
- python_rucaptcha/core/enums.py +146 -0
- python_rucaptcha/core/result_handler.py +65 -0
- python_rucaptcha/core/serializer.py +74 -0
- python_rucaptcha/cutcaptcha.py +116 -0
- python_rucaptcha/cyber_siara_captcha.py +110 -0
- python_rucaptcha/datadome_captcha.py +121 -0
- python_rucaptcha/draw_around_captcha.py +359 -0
- python_rucaptcha/fun_captcha.py +103 -0
- python_rucaptcha/gee_test.py +216 -0
- python_rucaptcha/grid_captcha.py +271 -0
- python_rucaptcha/hcaptcha.py +111 -0
- python_rucaptcha/image_captcha.py +249 -0
- python_rucaptcha/key_captcha.py +111 -0
- python_rucaptcha/lemin_captcha.py +112 -0
- python_rucaptcha/mt_captcha.py +104 -0
- python_rucaptcha/re_captcha.py +172 -0
- python_rucaptcha/rotate_captcha.py +196 -0
- python_rucaptcha/text_captcha.py +119 -0
- python_rucaptcha/turnstile.py +111 -0
- python_rucaptcha-6.1.0.dist-info/METADATA +138 -0
- python_rucaptcha-6.1.0.dist-info/RECORD +34 -0
- python_rucaptcha-6.1.0.dist-info/WHEEL +5 -0
- python_rucaptcha-6.1.0.dist-info/top_level.txt +1 -0
|
File without changes
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
__version__ = "6.1.0"
|
|
@@ -0,0 +1,114 @@
|
|
|
1
|
+
from typing import Union
|
|
2
|
+
|
|
3
|
+
from .core.base import BaseCaptcha
|
|
4
|
+
from .core.enums import AmazonWAFCaptchaEnm
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+
class AmazonWAF(BaseCaptcha):
|
|
8
|
+
def __init__(
|
|
9
|
+
self,
|
|
10
|
+
websiteURL: str,
|
|
11
|
+
websiteKey: str,
|
|
12
|
+
iv: str,
|
|
13
|
+
context: str,
|
|
14
|
+
method: Union[str, AmazonWAFCaptchaEnm] = AmazonWAFCaptchaEnm.AmazonTaskProxyless,
|
|
15
|
+
*args,
|
|
16
|
+
**kwargs,
|
|
17
|
+
):
|
|
18
|
+
"""
|
|
19
|
+
The class is used to work with Amazon WAF
|
|
20
|
+
|
|
21
|
+
Args:
|
|
22
|
+
rucaptcha_key: User API key
|
|
23
|
+
websiteURL: Full URL of the captcha page
|
|
24
|
+
websiteKey: Key value from the page
|
|
25
|
+
iv: Value iv from the page
|
|
26
|
+
context: Value of context from page
|
|
27
|
+
method: Captcha type
|
|
28
|
+
|
|
29
|
+
Examples:
|
|
30
|
+
>>> AmazonWAF(rucaptcha_key="aa9011f31111181111168611f1151122",
|
|
31
|
+
... websiteURL="https://page-with-waf.com/",
|
|
32
|
+
... websiteKey="some-site-key",
|
|
33
|
+
... iv="some-iv-value",
|
|
34
|
+
... context="some-context-value").captcha_handler()
|
|
35
|
+
{
|
|
36
|
+
"errorId":0,
|
|
37
|
+
"status":"ready",
|
|
38
|
+
"solution":{
|
|
39
|
+
"captcha_voucher":"eyJ0eXAiO...oQjTnJlBvAW4",
|
|
40
|
+
"existing_token":"f8ab5749-f916-...5D8yAA39JtKVbw="
|
|
41
|
+
},
|
|
42
|
+
"cost":"0.00145",
|
|
43
|
+
"ip":"1.2.3.4",
|
|
44
|
+
"createTime":1692863536,
|
|
45
|
+
"endTime":1692863556,
|
|
46
|
+
"solveCount":0,
|
|
47
|
+
"taskId": 73243152973,
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
>>> AmazonWAF(rucaptcha_key="aa9011f31111181111168611f1151122",
|
|
51
|
+
... websiteURL="https://page-with-waf.com/",
|
|
52
|
+
... websiteKey="some-site-key",
|
|
53
|
+
... iv="some-iv-value",
|
|
54
|
+
... context="some-context-value").aio_captcha_handler()
|
|
55
|
+
{
|
|
56
|
+
"errorId":0,
|
|
57
|
+
"status":"ready",
|
|
58
|
+
"solution":{
|
|
59
|
+
"captcha_voucher":"eyJ0eXAiO...oQjTnJlBvAW4",
|
|
60
|
+
"existing_token":"f8ab5749-f916-...5D8yAA39JtKVbw="
|
|
61
|
+
},
|
|
62
|
+
"cost":"0.00145",
|
|
63
|
+
"ip":"1.2.3.4",
|
|
64
|
+
"createTime":1692863536,
|
|
65
|
+
"endTime":1692863556,
|
|
66
|
+
"solveCount":0,
|
|
67
|
+
"taskId": 73243152973,
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
Returns:
|
|
71
|
+
Dict with full server response
|
|
72
|
+
|
|
73
|
+
Notes:
|
|
74
|
+
https://rucaptcha.com/api-docs/amazon-aws-waf-captcha
|
|
75
|
+
"""
|
|
76
|
+
super().__init__(method=method, *args, **kwargs)
|
|
77
|
+
|
|
78
|
+
# check user params
|
|
79
|
+
if method not in AmazonWAFCaptchaEnm.list_values():
|
|
80
|
+
raise ValueError(f"Invalid method parameter set, available - {AmazonWAFCaptchaEnm.list_values()}")
|
|
81
|
+
# insert `gt` param to payload
|
|
82
|
+
self.create_task_payload["task"].update(
|
|
83
|
+
{
|
|
84
|
+
"websiteURL": websiteURL,
|
|
85
|
+
"websiteKey": websiteKey,
|
|
86
|
+
"iv": iv,
|
|
87
|
+
"context": context,
|
|
88
|
+
}
|
|
89
|
+
)
|
|
90
|
+
|
|
91
|
+
def captcha_handler(self, **kwargs) -> dict:
|
|
92
|
+
"""
|
|
93
|
+
Synchronous method for captcha solving
|
|
94
|
+
|
|
95
|
+
Returns:
|
|
96
|
+
Dict with full server response
|
|
97
|
+
|
|
98
|
+
Notes:
|
|
99
|
+
Check class docstirng for more info
|
|
100
|
+
"""
|
|
101
|
+
|
|
102
|
+
return self._processing_response(**kwargs)
|
|
103
|
+
|
|
104
|
+
async def aio_captcha_handler(self) -> dict:
|
|
105
|
+
"""
|
|
106
|
+
Asynchronous method for captcha solving
|
|
107
|
+
|
|
108
|
+
Returns:
|
|
109
|
+
Dict with full server response
|
|
110
|
+
|
|
111
|
+
Notes:
|
|
112
|
+
Check class docstirng for more info
|
|
113
|
+
"""
|
|
114
|
+
return await self._aio_processing_response()
|
|
@@ -0,0 +1,161 @@
|
|
|
1
|
+
import shutil
|
|
2
|
+
from typing import Union, Optional
|
|
3
|
+
|
|
4
|
+
from .core.base import BaseCaptcha
|
|
5
|
+
from .core.enums import SaveFormatsEnm, AudioCaptchaEnm
|
|
6
|
+
from .core.serializer import GetTaskResultResponseSer
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
class AudioCaptcha(BaseCaptcha):
|
|
10
|
+
def __init__(
|
|
11
|
+
self,
|
|
12
|
+
save_format: Union[str, SaveFormatsEnm] = SaveFormatsEnm.TEMP,
|
|
13
|
+
audio_clearing: bool = True,
|
|
14
|
+
audio_path: str = "PythonRuCaptchaAudio",
|
|
15
|
+
lang: str = "en",
|
|
16
|
+
*args,
|
|
17
|
+
**kwargs,
|
|
18
|
+
):
|
|
19
|
+
"""
|
|
20
|
+
The class is used to work with Text Captcha.
|
|
21
|
+
|
|
22
|
+
Args:
|
|
23
|
+
rucaptcha_key: User API key
|
|
24
|
+
save_format: The format in which the file will be saved, or as a temporary file - 'temp',
|
|
25
|
+
or as a regular file to a folder created by the library - 'const'.
|
|
26
|
+
audio_clearing: True - delete file after solution, False - don't delete file after solution
|
|
27
|
+
audio_path: Folder to save captcha audio
|
|
28
|
+
lang: Captcha audio lang: `en`, `fr`, `de`, `el`, `pt`, `ru`
|
|
29
|
+
|
|
30
|
+
Examples:
|
|
31
|
+
>>> AudioCaptcha(rucaptcha_key="aa9011f31111181111168611f1151122",
|
|
32
|
+
... lang='en'
|
|
33
|
+
... ).captcha_handler(captcha_file='examples/mediacaptcha_audio/recaptcha_55914.mp3')
|
|
34
|
+
{
|
|
35
|
+
'captchaSolve': 'five five nine one four',
|
|
36
|
+
'taskId': 73243152973,
|
|
37
|
+
'error': False,
|
|
38
|
+
'errorBody': None
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
>>> with open("src/examples/mediacaptcha_audio/recaptcha_55914.mp3", "rb") as f:
|
|
42
|
+
... file_data = f.read()
|
|
43
|
+
>>> AudioCaptcha(rucaptcha_key="aa9011f31111181111168611f1151122"
|
|
44
|
+
... ).captcha_handler(captcha_base64=file_data)
|
|
45
|
+
{
|
|
46
|
+
'captchaSolve': 'five five nine one four',
|
|
47
|
+
'taskId': 73243152973,
|
|
48
|
+
'error': False,
|
|
49
|
+
'errorBody': None
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
>>> await AudioCaptcha(rucaptcha_key="aa9011f31111181111168611f1151122",
|
|
53
|
+
... lang='en'
|
|
54
|
+
... ).aio_captcha_handler(captcha_file='examples/mediacaptcha_audio/recaptcha_55914.mp3')
|
|
55
|
+
{
|
|
56
|
+
'captchaSolve': 'five five nine one four',
|
|
57
|
+
'taskId': 73243152973,
|
|
58
|
+
'error': False,
|
|
59
|
+
'errorBody': None
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
>>> with open("src/examples/mediacaptcha_audio/recaptcha_55914.mp3", "rb") as f:
|
|
63
|
+
... file_data = f.read()
|
|
64
|
+
>>> await AudioCaptcha(rucaptcha_key="aa9011f31111181111168611f1151122"
|
|
65
|
+
... ).aio_captcha_handler(captcha_base64=file_data)
|
|
66
|
+
{
|
|
67
|
+
'captchaSolve': 'five five nine one four',
|
|
68
|
+
'taskId': 73243152973,
|
|
69
|
+
'error': False,
|
|
70
|
+
'errorBody': None
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
Returns:
|
|
74
|
+
Dict with full server response
|
|
75
|
+
|
|
76
|
+
Notes:
|
|
77
|
+
https://rucaptcha.com/api-docs/audio
|
|
78
|
+
"""
|
|
79
|
+
|
|
80
|
+
super().__init__(method=AudioCaptchaEnm.AudioTask.value, *args, **kwargs)
|
|
81
|
+
self.save_format = save_format
|
|
82
|
+
self.audio_clearing = audio_clearing
|
|
83
|
+
self.audio_path = audio_path
|
|
84
|
+
self.result = GetTaskResultResponseSer()
|
|
85
|
+
|
|
86
|
+
self.create_task_payload["task"].update({"lang": lang})
|
|
87
|
+
|
|
88
|
+
def captcha_handler(
|
|
89
|
+
self,
|
|
90
|
+
captcha_link: Optional[str] = None,
|
|
91
|
+
captcha_file: Optional[str] = None,
|
|
92
|
+
captcha_base64: Optional[bytes] = None,
|
|
93
|
+
**kwargs,
|
|
94
|
+
) -> dict:
|
|
95
|
+
"""
|
|
96
|
+
Synchronous method for captcha solving
|
|
97
|
+
|
|
98
|
+
Args:
|
|
99
|
+
captcha_link: Captcha file URL
|
|
100
|
+
captcha_file: Captcha file path
|
|
101
|
+
captcha_base64: Captcha file BASE64 info
|
|
102
|
+
kwargs: additional params for `requests` library
|
|
103
|
+
|
|
104
|
+
Returns:
|
|
105
|
+
Dict with full server response
|
|
106
|
+
|
|
107
|
+
Notes:
|
|
108
|
+
Check class docstirng for more info
|
|
109
|
+
"""
|
|
110
|
+
|
|
111
|
+
self._body_file_processing(
|
|
112
|
+
save_format=self.save_format,
|
|
113
|
+
file_path=self.audio_path,
|
|
114
|
+
file_extension="mp3",
|
|
115
|
+
captcha_link=captcha_link,
|
|
116
|
+
captcha_file=captcha_file,
|
|
117
|
+
captcha_base64=captcha_base64,
|
|
118
|
+
**kwargs,
|
|
119
|
+
)
|
|
120
|
+
if not self.result.errorId:
|
|
121
|
+
return self._processing_response(**kwargs)
|
|
122
|
+
return self.result.to_dict()
|
|
123
|
+
|
|
124
|
+
async def aio_captcha_handler(
|
|
125
|
+
self,
|
|
126
|
+
captcha_link: Optional[str] = None,
|
|
127
|
+
captcha_file: Optional[str] = None,
|
|
128
|
+
captcha_base64: Optional[bytes] = None,
|
|
129
|
+
**kwargs,
|
|
130
|
+
) -> dict:
|
|
131
|
+
"""
|
|
132
|
+
Asynchronous method for captcha solving
|
|
133
|
+
|
|
134
|
+
Args:
|
|
135
|
+
captcha_link: Captcha file URL
|
|
136
|
+
captcha_file: Captcha file path
|
|
137
|
+
captcha_base64: Captcha file BASE64
|
|
138
|
+
kwargs: additional params for `aiohttp` library
|
|
139
|
+
|
|
140
|
+
Returns:
|
|
141
|
+
Dict with full server response
|
|
142
|
+
|
|
143
|
+
Notes:
|
|
144
|
+
Check class docstirng for more info
|
|
145
|
+
"""
|
|
146
|
+
await self._aio_body_file_processing(
|
|
147
|
+
save_format=self.save_format,
|
|
148
|
+
file_path=self.audio_path,
|
|
149
|
+
file_extension="mp3",
|
|
150
|
+
captcha_link=captcha_link,
|
|
151
|
+
captcha_file=captcha_file,
|
|
152
|
+
captcha_base64=captcha_base64,
|
|
153
|
+
**kwargs,
|
|
154
|
+
)
|
|
155
|
+
if not self.result.errorId:
|
|
156
|
+
return await self._aio_processing_response()
|
|
157
|
+
return self.result.to_dict()
|
|
158
|
+
|
|
159
|
+
def __del__(self):
|
|
160
|
+
if self.save_format == SaveFormatsEnm.CONST.value and self.audio_clearing:
|
|
161
|
+
shutil.rmtree(self.audio_path)
|
|
@@ -0,0 +1,310 @@
|
|
|
1
|
+
import shutil
|
|
2
|
+
import logging
|
|
3
|
+
from typing import Union, Optional
|
|
4
|
+
|
|
5
|
+
from .core.base import BaseCaptcha
|
|
6
|
+
from .core.enums import SaveFormatsEnm, BoundingBoxCaptchaEnm
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
class BoundingBoxCaptcha(BaseCaptcha):
|
|
10
|
+
def __init__(
|
|
11
|
+
self,
|
|
12
|
+
comment: str = "Draw Around Bounding Box",
|
|
13
|
+
save_format: Union[str, SaveFormatsEnm] = SaveFormatsEnm.TEMP,
|
|
14
|
+
img_clearing: bool = True,
|
|
15
|
+
img_path: str = "PythonRuCaptchaBoundingBox",
|
|
16
|
+
*args,
|
|
17
|
+
**kwargs,
|
|
18
|
+
):
|
|
19
|
+
"""
|
|
20
|
+
The class is used to work with Bounding Box.
|
|
21
|
+
|
|
22
|
+
Args:
|
|
23
|
+
rucaptcha_key: User API key
|
|
24
|
+
save_format: The format in which the image will be saved, or as a temporary file - 'temp',
|
|
25
|
+
or as a regular image to a folder created by the library - 'const'.
|
|
26
|
+
img_clearing: True - delete file after solution, False - don't delete file after solution
|
|
27
|
+
img_path: Folder to save captcha images
|
|
28
|
+
kwargs: Additional not required params for this captcha type
|
|
29
|
+
|
|
30
|
+
Examples:
|
|
31
|
+
>>> BoundingBoxCaptcha(rucaptcha_key="aa9011f31111181111168611f1151122",
|
|
32
|
+
... ).captcha_handler(captcha_link="https://rucaptcha.com/dist/web/99581b9d446a509a0a01954438a5e36a.jpg")
|
|
33
|
+
{
|
|
34
|
+
"errorId":0,
|
|
35
|
+
"status":"ready",
|
|
36
|
+
"solution":{
|
|
37
|
+
"bounding_boxes": [
|
|
38
|
+
{
|
|
39
|
+
"xMin": 310,
|
|
40
|
+
"xMax": 385,
|
|
41
|
+
"yMin": 231,
|
|
42
|
+
"yMax": 308
|
|
43
|
+
}
|
|
44
|
+
]
|
|
45
|
+
},
|
|
46
|
+
"cost":0.033,
|
|
47
|
+
"ip":"46.53.241.91",
|
|
48
|
+
"createTime":1696730723,
|
|
49
|
+
"endTime":1696730723,
|
|
50
|
+
"solveCount":1,
|
|
51
|
+
"taskId":74708110322
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
>>> BoundingBoxCaptcha(rucaptcha_key="aa9011f31111181111168611f1151122",
|
|
55
|
+
... ).captcha_handler(captcha_file="src/examples/088636.png")
|
|
56
|
+
{
|
|
57
|
+
"errorId":0,
|
|
58
|
+
"status":"ready",
|
|
59
|
+
"solution":{
|
|
60
|
+
"bounding_boxes": [
|
|
61
|
+
{
|
|
62
|
+
"xMin": 310,
|
|
63
|
+
"xMax": 385,
|
|
64
|
+
"yMin": 231,
|
|
65
|
+
"yMax": 308
|
|
66
|
+
}
|
|
67
|
+
]
|
|
68
|
+
},
|
|
69
|
+
"cost":0.033,
|
|
70
|
+
"ip":"46.53.241.91",
|
|
71
|
+
"createTime":1696730723,
|
|
72
|
+
"endTime":1696730723,
|
|
73
|
+
"solveCount":1,
|
|
74
|
+
"taskId":74708110322
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
>>> with open("src/examples/088636.png", "rb") as f:
|
|
78
|
+
... file_data = f.read()
|
|
79
|
+
>>> BoundingBoxCaptcha(rucaptcha_key="aa9011f31111181111168611f1151122"
|
|
80
|
+
... ).captcha_handler(captcha_base64=file_data)
|
|
81
|
+
{
|
|
82
|
+
"errorId":0,
|
|
83
|
+
"status":"ready",
|
|
84
|
+
"solution":{
|
|
85
|
+
"bounding_boxes": [
|
|
86
|
+
{
|
|
87
|
+
"xMin": 310,
|
|
88
|
+
"xMax": 385,
|
|
89
|
+
"yMin": 231,
|
|
90
|
+
"yMax": 308
|
|
91
|
+
}
|
|
92
|
+
]
|
|
93
|
+
},
|
|
94
|
+
"cost":0.033,
|
|
95
|
+
"ip":"46.53.241.91",
|
|
96
|
+
"createTime":1696730723,
|
|
97
|
+
"endTime":1696730723,
|
|
98
|
+
"solveCount":1,
|
|
99
|
+
"taskId":74708110322
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
>>> await BoundingBoxCaptcha(rucaptcha_key="aa9011f31111181111168611f1151122",
|
|
103
|
+
... ).aio_captcha_handler(captcha_link="https://rucaptcha.com/dist/web/99581b9d446a509a0a01954438a5e36a.jpg")
|
|
104
|
+
{
|
|
105
|
+
"errorId":0,
|
|
106
|
+
"status":"ready",
|
|
107
|
+
"solution":{
|
|
108
|
+
"bounding_boxes": [
|
|
109
|
+
{
|
|
110
|
+
"xMin": 310,
|
|
111
|
+
"xMax": 385,
|
|
112
|
+
"yMin": 231,
|
|
113
|
+
"yMax": 308
|
|
114
|
+
}
|
|
115
|
+
]
|
|
116
|
+
},
|
|
117
|
+
"cost":0.033,
|
|
118
|
+
"ip":"46.53.241.91",
|
|
119
|
+
"createTime":1696730723,
|
|
120
|
+
"endTime":1696730723,
|
|
121
|
+
"solveCount":1,
|
|
122
|
+
"taskId":74708110322
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
>>> await BoundingBoxCaptcha(rucaptcha_key="aa9011f31111181111168611f1151122",
|
|
126
|
+
... ).aio_captcha_handler(captcha_file="src/examples/088636.png")
|
|
127
|
+
{
|
|
128
|
+
"errorId":0,
|
|
129
|
+
"status":"ready",
|
|
130
|
+
"solution":{
|
|
131
|
+
"bounding_boxes": [
|
|
132
|
+
{
|
|
133
|
+
"xMin": 310,
|
|
134
|
+
"xMax": 385,
|
|
135
|
+
"yMin": 231,
|
|
136
|
+
"yMax": 308
|
|
137
|
+
}
|
|
138
|
+
]
|
|
139
|
+
},
|
|
140
|
+
"cost":0.033,
|
|
141
|
+
"ip":"46.53.241.91",
|
|
142
|
+
"createTime":1696730723,
|
|
143
|
+
"endTime":1696730723,
|
|
144
|
+
"solveCount":1,
|
|
145
|
+
"taskId":74708110322
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
Death Captcha
|
|
149
|
+
|
|
150
|
+
>>> BoundingBoxCaptcha(rucaptcha_key="some_username:some_password",
|
|
151
|
+
... service_type="deathbycaptcha"
|
|
152
|
+
... ).captcha_handler(captcha_file="src/examples/088636.jpg")
|
|
153
|
+
{
|
|
154
|
+
"errorId":0,
|
|
155
|
+
"status":"ready",
|
|
156
|
+
"solution":{
|
|
157
|
+
"bounding_boxes": [
|
|
158
|
+
{
|
|
159
|
+
"xMin": 310,
|
|
160
|
+
"xMax": 385,
|
|
161
|
+
"yMin": 231,
|
|
162
|
+
"yMax": 308
|
|
163
|
+
}
|
|
164
|
+
]
|
|
165
|
+
},
|
|
166
|
+
"cost":0.033,
|
|
167
|
+
"ip":"46.53.241.91",
|
|
168
|
+
"createTime":1696730723,
|
|
169
|
+
"endTime":1696730723,
|
|
170
|
+
"solveCount":1,
|
|
171
|
+
"taskId":74708110322
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
>>> await BoundingBoxCaptcha(rucaptcha_key="some_username:some_password",
|
|
175
|
+
... service_type="deathbycaptcha"
|
|
176
|
+
... ).aio_captcha_handler(captcha_link="https://rucaptcha.com/dist/web/99581b9d446a509a0a01954438a5e36a.jpg")
|
|
177
|
+
{
|
|
178
|
+
"errorId":0,
|
|
179
|
+
"status":"ready",
|
|
180
|
+
"solution":{
|
|
181
|
+
"bounding_boxes": [
|
|
182
|
+
{
|
|
183
|
+
"xMin": 310,
|
|
184
|
+
"xMax": 385,
|
|
185
|
+
"yMin": 231,
|
|
186
|
+
"yMax": 308
|
|
187
|
+
}
|
|
188
|
+
]
|
|
189
|
+
},
|
|
190
|
+
"cost":0.033,
|
|
191
|
+
"ip":"46.53.241.91",
|
|
192
|
+
"createTime":1696730723,
|
|
193
|
+
"endTime":1696730723,
|
|
194
|
+
"solveCount":1,
|
|
195
|
+
"taskId":74708110322
|
|
196
|
+
}
|
|
197
|
+
|
|
198
|
+
>>> with open("src/examples/088636.png", "rb") as f:
|
|
199
|
+
... file_data = f.read()
|
|
200
|
+
>>> await BoundingBoxCaptcha(rucaptcha_key="aa9011f31111181111168611f1151122"
|
|
201
|
+
... ).aio_captcha_handler(captcha_base64=file_data)
|
|
202
|
+
{
|
|
203
|
+
"errorId":0,
|
|
204
|
+
"status":"ready",
|
|
205
|
+
"solution":{
|
|
206
|
+
"bounding_boxes": [
|
|
207
|
+
{
|
|
208
|
+
"xMin": 310,
|
|
209
|
+
"xMax": 385,
|
|
210
|
+
"yMin": 231,
|
|
211
|
+
"yMax": 308
|
|
212
|
+
}
|
|
213
|
+
]
|
|
214
|
+
},
|
|
215
|
+
"cost":0.033,
|
|
216
|
+
"ip":"46.53.241.91",
|
|
217
|
+
"createTime":1696730723,
|
|
218
|
+
"endTime":1696730723,
|
|
219
|
+
"solveCount":1,
|
|
220
|
+
"taskId":74708110322
|
|
221
|
+
}
|
|
222
|
+
|
|
223
|
+
Returns:
|
|
224
|
+
Dict with full server response
|
|
225
|
+
|
|
226
|
+
Notes:
|
|
227
|
+
https://2captcha.com/api-docs/bounding-box
|
|
228
|
+
|
|
229
|
+
https://rucaptcha.com/api-docs/bounding-box
|
|
230
|
+
"""
|
|
231
|
+
super().__init__(method=BoundingBoxCaptchaEnm.BoundingBoxTask.value, *args, **kwargs)
|
|
232
|
+
|
|
233
|
+
self.save_format = save_format
|
|
234
|
+
self.img_clearing = img_clearing
|
|
235
|
+
self.img_path = img_path
|
|
236
|
+
self.create_task_payload["task"].update({"comment": comment})
|
|
237
|
+
|
|
238
|
+
def captcha_handler(
|
|
239
|
+
self,
|
|
240
|
+
captcha_link: Optional[str] = None,
|
|
241
|
+
captcha_file: Optional[str] = None,
|
|
242
|
+
captcha_base64: Optional[bytes] = None,
|
|
243
|
+
**kwargs,
|
|
244
|
+
) -> dict:
|
|
245
|
+
"""
|
|
246
|
+
Sync solving method
|
|
247
|
+
|
|
248
|
+
Args:
|
|
249
|
+
captcha_link: Captcha image URL
|
|
250
|
+
captcha_file: Captcha image file path
|
|
251
|
+
captcha_base64: Captcha image BASE64 info
|
|
252
|
+
kwargs: additional params for `requests` library
|
|
253
|
+
|
|
254
|
+
Returns:
|
|
255
|
+
Dict with full server response
|
|
256
|
+
|
|
257
|
+
Notes:
|
|
258
|
+
Check class docstirng for more info
|
|
259
|
+
"""
|
|
260
|
+
self._body_file_processing(
|
|
261
|
+
save_format=self.save_format,
|
|
262
|
+
file_path=self.img_path,
|
|
263
|
+
captcha_link=captcha_link,
|
|
264
|
+
captcha_file=captcha_file,
|
|
265
|
+
captcha_base64=captcha_base64,
|
|
266
|
+
**kwargs,
|
|
267
|
+
)
|
|
268
|
+
logging.warning(f"{self.result = }")
|
|
269
|
+
logging.warning(f"{self.create_task_payload = }")
|
|
270
|
+
if not self.result.errorId:
|
|
271
|
+
return self._processing_response(**kwargs)
|
|
272
|
+
return self.result.to_dict()
|
|
273
|
+
|
|
274
|
+
async def aio_captcha_handler(
|
|
275
|
+
self,
|
|
276
|
+
captcha_link: Optional[str] = None,
|
|
277
|
+
captcha_file: Optional[str] = None,
|
|
278
|
+
captcha_base64: Optional[bytes] = None,
|
|
279
|
+
**kwargs,
|
|
280
|
+
) -> dict:
|
|
281
|
+
"""
|
|
282
|
+
Async solving method
|
|
283
|
+
|
|
284
|
+
Args:
|
|
285
|
+
captcha_link: Captcha image URL
|
|
286
|
+
captcha_file: Captcha image file path
|
|
287
|
+
captcha_base64: Captcha image BASE64 info
|
|
288
|
+
kwargs: additional params for `aiohttp` library
|
|
289
|
+
|
|
290
|
+
Returns:
|
|
291
|
+
Dict with full server response
|
|
292
|
+
|
|
293
|
+
Notes:
|
|
294
|
+
Check class docstirng for more info
|
|
295
|
+
"""
|
|
296
|
+
await self._aio_body_file_processing(
|
|
297
|
+
save_format=self.save_format,
|
|
298
|
+
file_path=self.img_path,
|
|
299
|
+
captcha_link=captcha_link,
|
|
300
|
+
captcha_file=captcha_file,
|
|
301
|
+
captcha_base64=captcha_base64,
|
|
302
|
+
**kwargs,
|
|
303
|
+
)
|
|
304
|
+
if not self.result.errorId:
|
|
305
|
+
return await self._aio_processing_response()
|
|
306
|
+
return self.result.to_dict()
|
|
307
|
+
|
|
308
|
+
def __del__(self):
|
|
309
|
+
if self.save_format == SaveFormatsEnm.CONST.value and self.img_clearing:
|
|
310
|
+
shutil.rmtree(self.img_path)
|