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.
@@ -0,0 +1,110 @@
1
+ from typing import Union
2
+
3
+ from .core.base import BaseCaptcha
4
+ from .core.enums import CyberSiARAEnm
5
+
6
+
7
+ class CyberSiARACaptcha(BaseCaptcha):
8
+ def __init__(
9
+ self,
10
+ websiteURL: str,
11
+ SlideMasterUrlId: str,
12
+ userAgent: str,
13
+ method: Union[str, CyberSiARAEnm] = CyberSiARAEnm.AntiCyberSiAraTaskProxyless.value,
14
+ *args,
15
+ **kwargs,
16
+ ):
17
+ """
18
+ The class is used to work with HCaptcha.
19
+
20
+ Args:
21
+ rucaptcha_key: User API key
22
+ websiteURL: Full URL of the captcha page
23
+ SlideMasterUrlId: The value of the `MasterUrlId` parameter obtained from the request to the endpoint `API/CyberSiara/GetCyberSiara`.
24
+ userAgent: User-Agent of your browser will be used to load the captcha. Use only modern browser's User-Agents
25
+ method: Captcha type
26
+ kwargs: Not required params for task creation request
27
+
28
+ Examples:
29
+ >>> CyberSiARACaptcha(rucaptcha_key="aa9011f31111181111168611f1151122",
30
+ ... websiteURL="3ceb8624-1970-4e6b-91d5-70317b70b651",
31
+ ... SlideMasterUrlId="https://rucaptcha.com/demo/hcaptcha",
32
+ ... userAgent="Mozilla/5.0 (Windows .....",
33
+ ... method=CyberSiARAEnm.AntiCyberSiAraTaskProxyless,
34
+ ... ).captcha_handler()
35
+ {
36
+ "errorId":0,
37
+ "status":"ready",
38
+ "solution":{
39
+ "token": "datadome=4ZXwCBlyHx9ktZhSnycMF...; Path=/; Secure; SameSite=Lax"
40
+ },
41
+ "cost":"0.00299",
42
+ "ip":"1.2.3.4",
43
+ "createTime":1692863536,
44
+ "endTime":1692863556,
45
+ "solveCount":1,
46
+ "taskId": 73243152973,
47
+ }
48
+
49
+ >>> await CyberSiARACaptcha(rucaptcha_key="aa9011f31111181111168611f1151122",
50
+ ... websiteURL="3ceb8624-1970-4e6b-91d5-70317b70b651",
51
+ ... SlideMasterUrlId="https://rucaptcha.com/demo/hcaptcha",
52
+ ... userAgent="Mozilla/5.0 (Windows .....",
53
+ ... method=CyberSiARAEnm.AntiCyberSiAraTaskProxyless,
54
+ ... ).aio_captcha_handler()
55
+ {
56
+ "errorId":0,
57
+ "status":"ready",
58
+ "solution":{
59
+ "token": "datadome=4ZXwCBlyHx9ktZhSnycMF...; Path=/; Secure; SameSite=Lax"
60
+ },
61
+ "cost":"0.00299",
62
+ "ip":"1.2.3.4",
63
+ "createTime":1692863536,
64
+ "endTime":1692863556,
65
+ "solveCount":1,
66
+ "taskId": 73243152973,
67
+ }
68
+
69
+ Returns:
70
+ Dict with full server response
71
+
72
+ Notes:
73
+ https://rucaptcha.com/api-docs/anti-cyber-siara#cybersiara
74
+ """
75
+ super().__init__(method=method, *args, **kwargs)
76
+
77
+ self.create_task_payload["task"].update(
78
+ {"websiteURL": websiteURL, "SlideMasterUrlId": SlideMasterUrlId, "userAgent": userAgent}
79
+ )
80
+ # check user params
81
+ if method not in CyberSiARAEnm.list_values():
82
+ raise ValueError(f"Invalid method parameter set, available - {CyberSiARAEnm.list_values()}")
83
+
84
+ def captcha_handler(self, **kwargs) -> dict:
85
+ """
86
+ Sync solving method
87
+
88
+ Args:
89
+ kwargs: Parameters for the `requests` library
90
+
91
+ Returns:
92
+ Dict with full server response
93
+
94
+ Notes:
95
+ Check class docstirng for more info
96
+ """
97
+
98
+ return self._processing_response(**kwargs)
99
+
100
+ async def aio_captcha_handler(self) -> dict:
101
+ """
102
+ Async solving method
103
+
104
+ Returns:
105
+ Dict with full server response
106
+
107
+ Notes:
108
+ Check class docstirng for more info
109
+ """
110
+ return await self._aio_processing_response()
@@ -0,0 +1,121 @@
1
+ from .core.base import BaseCaptcha
2
+ from .core.enums import DataDomeSliderEnm
3
+
4
+
5
+ class DataDomeCaptcha(BaseCaptcha):
6
+ def __init__(
7
+ self,
8
+ websiteURL: str,
9
+ captchaUrl: str,
10
+ userAgent: str,
11
+ proxyType: str,
12
+ proxyAddress: str,
13
+ proxyPort: str,
14
+ *args,
15
+ **kwargs,
16
+ ):
17
+ """
18
+ The class is used to work with HCaptcha.
19
+
20
+ Args:
21
+ rucaptcha_key: User API key
22
+ websiteURL: Full URL of the captcha page
23
+ captchaUrl: The value of the `src` parameter for the `iframe` element containing the captcha on the page.
24
+ userAgent: User-Agent of your browser will be used to load the captcha. Use only modern browser's User-Agents
25
+ proxyType: Proxy type - `http`, `socks4`, `socks5`
26
+ proxyAddress: Proxy IP address or hostname
27
+ proxyPort: Proxy port
28
+ method: Captcha type
29
+ kwargs: Not required params for task creation request
30
+
31
+ Examples:
32
+ >>> DataDomeCaptcha(rucaptcha_key="aa9011f31111181111168611f1151122",
33
+ ... websiteURL="3ceb8624-1970-4e6b-91d5-70317b70b651",
34
+ ... captchaUrl="https://rucaptcha.com/demo/hcaptcha",
35
+ ... userAgent="https://rucaptcha.com/demo/hcaptcha",
36
+ ... proxyType="socks5",
37
+ ... proxyAddress="1.2.3.4",
38
+ ... proxyPort="445",
39
+ ... ).captcha_handler()
40
+ {
41
+ "errorId":0,
42
+ "status":"ready",
43
+ "solution":{
44
+ "cookie": "datadome=4ZXwCBlyHx9ktZhSnycMF...; Path=/; Secure; SameSite=Lax"
45
+ },
46
+ "cost":"0.00299",
47
+ "ip":"1.2.3.4",
48
+ "createTime":1692863536,
49
+ "endTime":1692863556,
50
+ "solveCount":1,
51
+ "taskId": 73243152973,
52
+ }
53
+
54
+ >>> await DataDomeCaptcha(rucaptcha_key="aa9011f31111181111168611f1151122",
55
+ ... websiteURL="3ceb8624-1970-4e6b-91d5-70317b70b651",
56
+ ... captchaUrl="https://rucaptcha.com/demo/hcaptcha",
57
+ ... userAgent="https://rucaptcha.com/demo/hcaptcha",
58
+ ... proxyType="socks5",
59
+ ... proxyAddress="1.2.3.4",
60
+ ... proxyPort="445",
61
+ ... ).aio_captcha_handler()
62
+ {
63
+ "errorId":0,
64
+ "status":"ready",
65
+ "solution":{
66
+ "cookie": "datadome=4ZXwCBlyHx9ktZhSnycMF...; Path=/; Secure; SameSite=Lax"
67
+ },
68
+ "cost":"0.00299",
69
+ "ip":"1.2.3.4",
70
+ "createTime":1692863536,
71
+ "endTime":1692863556,
72
+ "solveCount":1,
73
+ "taskId": 73243152973,
74
+ }
75
+
76
+ Returns:
77
+ Dict with full server response
78
+
79
+ Notes:
80
+ https://rucaptcha.com/api-docs/datadome-slider-captcha
81
+ """
82
+ super().__init__(method=DataDomeSliderEnm.DataDomeSliderTask, *args, **kwargs)
83
+
84
+ self.create_task_payload["task"].update(
85
+ {
86
+ "websiteURL": websiteURL,
87
+ "captchaUrl": captchaUrl,
88
+ "userAgent": userAgent,
89
+ "proxyType": proxyType,
90
+ "proxyAddress": proxyAddress,
91
+ "proxyPort": proxyPort,
92
+ }
93
+ )
94
+
95
+ def captcha_handler(self, **kwargs) -> dict:
96
+ """
97
+ Sync solving method
98
+
99
+ Args:
100
+ kwargs: Parameters for the `requests` library
101
+
102
+ Returns:
103
+ Dict with full server response
104
+
105
+ Notes:
106
+ Check class docstirng for more info
107
+ """
108
+
109
+ return self._processing_response(**kwargs)
110
+
111
+ async def aio_captcha_handler(self) -> dict:
112
+ """
113
+ Async solving method
114
+
115
+ Returns:
116
+ Dict with full server response
117
+
118
+ Notes:
119
+ Check class docstirng for more info
120
+ """
121
+ return await self._aio_processing_response()
@@ -0,0 +1,359 @@
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, DrawAroundCaptchaEnm
7
+
8
+
9
+ class DrawAroundCaptcha(BaseCaptcha):
10
+ def __init__(
11
+ self,
12
+ comment: str = "Draw Around Object",
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
+ >>> DrawAroundCaptcha(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
+ "canvas":[
38
+ [{
39
+ "x":146,
40
+ "y":90
41
+ }],
42
+ [{
43
+ "x":158,
44
+ "y":69
45
+ },
46
+ {
47
+ "x":159,
48
+ "y":69
49
+ }]
50
+ ],
51
+ },
52
+ "cost":0.033,
53
+ "ip":"46.53.241.91",
54
+ "createTime":1696730723,
55
+ "endTime":1696730723,
56
+ "solveCount":1,
57
+ "taskId":74708110322
58
+ }
59
+
60
+ >>> DrawAroundCaptcha(rucaptcha_key="aa9011f31111181111168611f1151122",
61
+ ... ).captcha_handler(captcha_file="src/examples/088636.png")
62
+ {
63
+ "errorId":0,
64
+ "status":"ready",
65
+ "solution":{
66
+ "canvas":[
67
+ [{
68
+ "x":146,
69
+ "y":90
70
+ }],
71
+ [{
72
+ "x":158,
73
+ "y":69
74
+ },
75
+ {
76
+ "x":159,
77
+ "y":69
78
+ }]
79
+ ],
80
+ },
81
+ "cost":0.033,
82
+ "ip":"46.53.241.91",
83
+ "createTime":1696730723,
84
+ "endTime":1696730723,
85
+ "solveCount":1,
86
+ "taskId":74708110322
87
+ }
88
+
89
+ >>> with open("src/examples/088636.png", "rb") as f:
90
+ ... file_data = f.read()
91
+ >>> DrawAroundCaptcha(rucaptcha_key="aa9011f31111181111168611f1151122"
92
+ ... ).captcha_handler(captcha_base64=file_data)
93
+ {
94
+ "errorId":0,
95
+ "status":"ready",
96
+ "solution":{
97
+ "canvas":[
98
+ [{
99
+ "x":146,
100
+ "y":90
101
+ }],
102
+ [{
103
+ "x":158,
104
+ "y":69
105
+ },
106
+ {
107
+ "x":159,
108
+ "y":69
109
+ }]
110
+ ],
111
+ },
112
+ "cost":0.033,
113
+ "ip":"46.53.241.91",
114
+ "createTime":1696730723,
115
+ "endTime":1696730723,
116
+ "solveCount":1,
117
+ "taskId":74708110322
118
+ }
119
+
120
+ >>> await DrawAroundCaptcha(rucaptcha_key="aa9011f31111181111168611f1151122",
121
+ ... ).aio_captcha_handler(captcha_link="https://rucaptcha.com/dist/web/99581b9d446a509a0a01954438a5e36a.jpg")
122
+ {
123
+ "errorId":0,
124
+ "status":"ready",
125
+ "solution":{
126
+ "canvas":[
127
+ [{
128
+ "x":146,
129
+ "y":90
130
+ }],
131
+ [{
132
+ "x":158,
133
+ "y":69
134
+ },
135
+ {
136
+ "x":159,
137
+ "y":69
138
+ }]
139
+ ],
140
+ },
141
+ "cost":0.033,
142
+ "ip":"46.53.241.91",
143
+ "createTime":1696730723,
144
+ "endTime":1696730723,
145
+ "solveCount":1,
146
+ "taskId":74708110322
147
+ }
148
+
149
+ >>> await DrawAroundCaptcha(rucaptcha_key="aa9011f31111181111168611f1151122",
150
+ ... ).aio_captcha_handler(captcha_file="src/examples/088636.png")
151
+ {
152
+ "errorId":0,
153
+ "status":"ready",
154
+ "solution":{
155
+ "canvas":[
156
+ [{
157
+ "x":146,
158
+ "y":90
159
+ }],
160
+ [{
161
+ "x":158,
162
+ "y":69
163
+ },
164
+ {
165
+ "x":159,
166
+ "y":69
167
+ }]
168
+ ],
169
+ },
170
+ "cost":0.033,
171
+ "ip":"46.53.241.91",
172
+ "createTime":1696730723,
173
+ "endTime":1696730723,
174
+ "solveCount":1,
175
+ "taskId":74708110322
176
+ }
177
+
178
+ Death Captcha
179
+
180
+ >>> DrawAroundCaptcha(rucaptcha_key="some_username:some_password",
181
+ ... service_type="deathbycaptcha"
182
+ ... ).captcha_handler(captcha_file="src/examples/088636.jpg")
183
+ {
184
+ "errorId":0,
185
+ "status":"ready",
186
+ "solution":{
187
+ "canvas":[
188
+ [{
189
+ "x":146,
190
+ "y":90
191
+ }],
192
+ [{
193
+ "x":158,
194
+ "y":69
195
+ },
196
+ {
197
+ "x":159,
198
+ "y":69
199
+ }]
200
+ ],
201
+ },
202
+ "cost":0.033,
203
+ "ip":"46.53.241.91",
204
+ "createTime":1696730723,
205
+ "endTime":1696730723,
206
+ "solveCount":1,
207
+ "taskId":74708110322
208
+ }
209
+
210
+ >>> await DrawAroundCaptcha(rucaptcha_key="some_username:some_password",
211
+ ... service_type="deathbycaptcha"
212
+ ... ).aio_captcha_handler(captcha_link="https://rucaptcha.com/dist/web/99581b9d446a509a0a01954438a5e36a.jpg")
213
+ {
214
+ "errorId":0,
215
+ "status":"ready",
216
+ "solution":{
217
+ "canvas":[
218
+ [{
219
+ "x":146,
220
+ "y":90
221
+ }],
222
+ [{
223
+ "x":158,
224
+ "y":69
225
+ },
226
+ {
227
+ "x":159,
228
+ "y":69
229
+ }]
230
+ ],
231
+ },
232
+ "cost":0.033,
233
+ "ip":"46.53.241.91",
234
+ "createTime":1696730723,
235
+ "endTime":1696730723,
236
+ "solveCount":1,
237
+ "taskId":74708110322
238
+ }
239
+
240
+ >>> with open("src/examples/088636.png", "rb") as f:
241
+ ... file_data = f.read()
242
+ >>> await DrawAroundCaptcha(rucaptcha_key="aa9011f31111181111168611f1151122"
243
+ ... ).aio_captcha_handler(captcha_base64=file_data)
244
+ {
245
+ "errorId":0,
246
+ "status":"ready",
247
+ "solution":{
248
+ "canvas":[
249
+ [{
250
+ "x":146,
251
+ "y":90
252
+ }],
253
+ [{
254
+ "x":158,
255
+ "y":69
256
+ },
257
+ {
258
+ "x":159,
259
+ "y":69
260
+ }]
261
+ ],
262
+ },
263
+ "cost":0.033,
264
+ "ip":"46.53.241.91",
265
+ "createTime":1696730723,
266
+ "endTime":1696730723,
267
+ "solveCount":1,
268
+ "taskId":74708110322
269
+ }
270
+
271
+ Returns:
272
+ Dict with full server response
273
+
274
+ Notes:
275
+ https://2captcha.com/api-docs/draw-around
276
+
277
+ https://rucaptcha.com/api-docs/draw-around
278
+ """
279
+ super().__init__(method=DrawAroundCaptchaEnm.DrawAroundTask.value, *args, **kwargs)
280
+
281
+ self.save_format = save_format
282
+ self.img_clearing = img_clearing
283
+ self.img_path = img_path
284
+
285
+ self.create_task_payload["task"].update({"comment": comment})
286
+
287
+ def captcha_handler(
288
+ self,
289
+ captcha_link: Optional[str] = None,
290
+ captcha_file: Optional[str] = None,
291
+ captcha_base64: Optional[bytes] = None,
292
+ **kwargs,
293
+ ) -> dict:
294
+ """
295
+ Sync solving method
296
+
297
+ Args:
298
+ captcha_link: Captcha image URL
299
+ captcha_file: Captcha image file path
300
+ captcha_base64: Captcha image BASE64 info
301
+ kwargs: additional params for `requests` library
302
+
303
+ Returns:
304
+ Dict with full server response
305
+
306
+ Notes:
307
+ Check class docstirng for more info
308
+ """
309
+ self._body_file_processing(
310
+ save_format=self.save_format,
311
+ file_path=self.img_path,
312
+ captcha_link=captcha_link,
313
+ captcha_file=captcha_file,
314
+ captcha_base64=captcha_base64,
315
+ **kwargs,
316
+ )
317
+ logging.warning(f"{self.result = }")
318
+ logging.warning(f"{self.create_task_payload = }")
319
+ if not self.result.errorId:
320
+ return self._processing_response(**kwargs)
321
+ return self.result.to_dict()
322
+
323
+ async def aio_captcha_handler(
324
+ self,
325
+ captcha_link: Optional[str] = None,
326
+ captcha_file: Optional[str] = None,
327
+ captcha_base64: Optional[bytes] = None,
328
+ **kwargs,
329
+ ) -> dict:
330
+ """
331
+ Async solving method
332
+
333
+ Args:
334
+ captcha_link: Captcha image URL
335
+ captcha_file: Captcha image file path
336
+ captcha_base64: Captcha image BASE64 info
337
+ kwargs: additional params for `aiohttp` library
338
+
339
+ Returns:
340
+ Dict with full server response
341
+
342
+ Notes:
343
+ Check class docstirng for more info
344
+ """
345
+ await self._aio_body_file_processing(
346
+ save_format=self.save_format,
347
+ file_path=self.img_path,
348
+ captcha_link=captcha_link,
349
+ captcha_file=captcha_file,
350
+ captcha_base64=captcha_base64,
351
+ **kwargs,
352
+ )
353
+ if not self.result.errorId:
354
+ return await self._aio_processing_response()
355
+ return self.result.to_dict()
356
+
357
+ def __del__(self):
358
+ if self.save_format == SaveFormatsEnm.CONST.value and self.img_clearing:
359
+ shutil.rmtree(self.img_path)
@@ -0,0 +1,103 @@
1
+ from typing import Union
2
+
3
+ from .core.base import BaseCaptcha
4
+ from .core.enums import FunCaptchaEnm
5
+
6
+
7
+ class FunCaptcha(BaseCaptcha):
8
+ def __init__(
9
+ self,
10
+ websiteURL: str,
11
+ websitePublicKey: str,
12
+ method: Union[str, FunCaptchaEnm] = FunCaptchaEnm.FunCaptchaTaskProxyless,
13
+ *args,
14
+ **kwargs,
15
+ ):
16
+ """
17
+ The class is used to work with Arkose Labs FunCaptcha.
18
+
19
+ Args:
20
+ rucaptcha_key: User API key
21
+ websiteURL: Full URL of the captcha page
22
+ websitePublicKey: The value of the `pk` or `data-pkey` parameter you found in the page code
23
+ method: Captcha type
24
+
25
+ Examples:
26
+ >>> FunCaptcha(rucaptcha_key="aa9011f31111181111168611f1151122",
27
+ ... websiteURL="https://api.funcaptcha.com/tile-game-lite-mode/fc/api/nojs/?pkey=69A21A01-CC7B-B9C6-0F9A-E7FA06677FFC&lang=en",
28
+ ... websitePublicKey="69A21A01-CC7B-B9C6-0F9A-E7FA06677FFC",
29
+ ... method=FunCaptchaEnm.FunCaptchaTaskProxyless.value
30
+ ... ).captcha_handler()
31
+ {
32
+ "errorId":0,
33
+ "status":"ready",
34
+ "solution":{
35
+ "token":"142000f.....er"
36
+ },
37
+ "cost":"0.002",
38
+ "ip":"1.2.3.4",
39
+ "createTime":1692863536,
40
+ "endTime":1692863556,
41
+ "solveCount":0,
42
+ "taskId": 73243152973,
43
+ }
44
+
45
+ >>> await FunCaptcha(rucaptcha_key="aa9011f31111181111168611f1151122",
46
+ ... websiteURL="https://api.funcaptcha.com/tile-game-lite-mode/fc/api/nojs/?pkey=69A21A01-CC7B-B9C6-0F9A-E7FA06677FFC&lang=en",
47
+ ... websitePublicKey="69A21A01-CC7B-B9C6-0F9A-E7FA06677FFC",
48
+ ... method=FunCaptchaEnm.FunCaptchaTaskProxyless.value
49
+ ... ).aio_captcha_handler()
50
+ {
51
+ "errorId":0,
52
+ "status":"ready",
53
+ "solution":{
54
+ "token":"142000f.....er"
55
+ },
56
+ "cost":"0.002",
57
+ "ip":"1.2.3.4",
58
+ "createTime":1692863536,
59
+ "endTime":1692863556,
60
+ "solveCount":0,
61
+ "taskId": 73243152973,
62
+ }
63
+
64
+ Returns:
65
+ Dict with full server response
66
+
67
+ Notes:
68
+ https://rucaptcha.com/api-docs/arkoselabs-funcaptcha
69
+ """
70
+ super().__init__(method=method, *args, **kwargs)
71
+
72
+ self.create_task_payload["task"].update({"websiteURL": websiteURL, "websitePublicKey": websitePublicKey})
73
+
74
+ # check user params
75
+ if method not in FunCaptchaEnm.list_values():
76
+ raise ValueError(f"Invalid method parameter set, available - {FunCaptchaEnm.list_values()}")
77
+
78
+ def captcha_handler(self, **kwargs) -> dict:
79
+ """
80
+ Sync solving method
81
+
82
+ Args:
83
+ kwargs: additional params for `requests` library
84
+
85
+ Returns:
86
+ Dict with full server response
87
+
88
+ Notes:
89
+ Check class docstirng for more info
90
+ """
91
+ return self._processing_response(**kwargs)
92
+
93
+ async def aio_captcha_handler(self) -> dict:
94
+ """
95
+ Async solving method
96
+
97
+ Returns:
98
+ Dict with full server response
99
+
100
+ Notes:
101
+ Check class docstirng for more info
102
+ """
103
+ return await self._aio_processing_response()