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,249 @@
1
+ import shutil
2
+ from typing import Union, Optional
3
+
4
+ from .core.base import BaseCaptcha
5
+ from .core.enums import SaveFormatsEnm, ImageCaptchaEnm
6
+
7
+
8
+ class ImageCaptcha(BaseCaptcha):
9
+ def __init__(
10
+ self,
11
+ save_format: Union[str, SaveFormatsEnm] = SaveFormatsEnm.TEMP,
12
+ img_clearing: bool = True,
13
+ img_path: str = "PythonRuCaptchaImages",
14
+ *args,
15
+ **kwargs,
16
+ ):
17
+ """
18
+ The class is used to work with Image Captcha.
19
+
20
+ Args:
21
+ rucaptcha_key: User API key
22
+ save_format: The format in which the image will be saved, or as a temporary file - 'temp',
23
+ or as a regular image to a folder created by the library - 'const'.
24
+ img_clearing: True - delete file after solution, False - don't delete file after solution
25
+ img_path: Folder to save captcha images
26
+ kwargs: Additional not required params for this captcha type
27
+
28
+ Examples:
29
+ >>> ImageCaptcha(rucaptcha_key="aa9011f31111181111168611f1151122",
30
+ ... ).captcha_handler(captcha_link="https://rucaptcha.com/dist/web/99581b9d446a509a0a01954438a5e36a.jpg")
31
+ {
32
+ "errorId":0,
33
+ "status":"ready",
34
+ "solution":{
35
+ "text":"w9h5k"
36
+ },
37
+ "cost":0.033,
38
+ "ip":"46.53.241.91",
39
+ "createTime":1696730723,
40
+ "endTime":1696730723,
41
+ "solveCount":1,
42
+ "taskId":74708110322
43
+ }
44
+
45
+ >>> ImageCaptcha(rucaptcha_key="aa9011f31111181111168611f1151122",
46
+ ... ).captcha_handler(captcha_file="src/examples/088636.png")
47
+ {
48
+ "errorId":0,
49
+ "status":"ready",
50
+ "solution":{
51
+ "text":"w9h5k"
52
+ },
53
+ "cost":0.033,
54
+ "ip":"46.53.241.91",
55
+ "createTime":1696730723,
56
+ "endTime":1696730723,
57
+ "solveCount":1,
58
+ "taskId":74708110322
59
+ }
60
+
61
+ >>> with open("src/examples/088636.png", "rb") as f:
62
+ ... file_data = f.read()
63
+ >>> ImageCaptcha(rucaptcha_key="aa9011f31111181111168611f1151122"
64
+ ... ).captcha_handler(captcha_base64=file_data)
65
+ {
66
+ "errorId":0,
67
+ "status":"ready",
68
+ "solution":{
69
+ "text":"w9h5k"
70
+ },
71
+ "cost":0.033,
72
+ "ip":"46.53.241.91",
73
+ "createTime":1696730723,
74
+ "endTime":1696730723,
75
+ "solveCount":1,
76
+ "taskId":74708110322
77
+ }
78
+
79
+ >>> await ImageCaptcha(rucaptcha_key="aa9011f31111181111168611f1151122",
80
+ ... ).aio_captcha_handler(captcha_link="https://rucaptcha.com/dist/web/99581b9d446a509a0a01954438a5e36a.jpg")
81
+ {
82
+ "errorId":0,
83
+ "status":"ready",
84
+ "solution":{
85
+ "text":"w9h5k"
86
+ },
87
+ "cost":0.033,
88
+ "ip":"46.53.241.91",
89
+ "createTime":1696730723,
90
+ "endTime":1696730723,
91
+ "solveCount":1,
92
+ "taskId":74708110322
93
+ }
94
+
95
+ >>> await ImageCaptcha(rucaptcha_key="aa9011f31111181111168611f1151122",
96
+ ... ).aio_captcha_handler(captcha_file="src/examples/088636.png")
97
+ {
98
+ "errorId":0,
99
+ "status":"ready",
100
+ "solution":{
101
+ "text":"w9h5k"
102
+ },
103
+ "cost":0.033,
104
+ "ip":"46.53.241.91",
105
+ "createTime":1696730723,
106
+ "endTime":1696730723,
107
+ "solveCount":1,
108
+ "taskId":74708110322
109
+ }
110
+
111
+ Death Captcha
112
+
113
+ >>> ImageCaptcha(rucaptcha_key="some_username:some_password",
114
+ ... service_type="deathbycaptcha"
115
+ ... ).captcha_handler(captcha_file="src/examples/088636.jpg")
116
+ {
117
+ "errorId":0,
118
+ "status":"ready",
119
+ "solution":{
120
+ "text":"w9h5k"
121
+ },
122
+ "cost":0.033,
123
+ "ip":"46.53.241.91",
124
+ "createTime":1696730723,
125
+ "endTime":1696730723,
126
+ "solveCount":1,
127
+ "taskId":74708110322
128
+ }
129
+
130
+ >>> await ImageCaptcha(rucaptcha_key="some_username:some_password",
131
+ ... service_type="deathbycaptcha"
132
+ ... ).aio_captcha_handler(captcha_link="https://rucaptcha.com/dist/web/99581b9d446a509a0a01954438a5e36a.jpg")
133
+ {
134
+ "errorId":0,
135
+ "status":"ready",
136
+ "solution":{
137
+ "text":"w9h5k"
138
+ },
139
+ "cost":0.033,
140
+ "ip":"46.53.241.91",
141
+ "createTime":1696730723,
142
+ "endTime":1696730723,
143
+ "solveCount":1,
144
+ "taskId":74708110322
145
+ }
146
+
147
+ >>> with open("src/examples/088636.png", "rb") as f:
148
+ ... file_data = f.read()
149
+ >>> await ImageCaptcha(rucaptcha_key="aa9011f31111181111168611f1151122"
150
+ ... ).aio_captcha_handler(captcha_base64=file_data)
151
+ {
152
+ "errorId":0,
153
+ "status":"ready",
154
+ "solution":{
155
+ "text":"w9h5k"
156
+ },
157
+ "cost":0.033,
158
+ "ip":"46.53.241.91",
159
+ "createTime":1696730723,
160
+ "endTime":1696730723,
161
+ "solveCount":1,
162
+ "taskId":74708110322
163
+ }
164
+
165
+ Returns:
166
+ Dict with full server response
167
+
168
+ Notes:
169
+ https://2captcha.com/api-docs/normal-captcha
170
+
171
+ https://rucaptcha.com/api-docs/normal-captcha
172
+ """
173
+ super().__init__(method=ImageCaptchaEnm.ImageToTextTask.value, *args, **kwargs)
174
+
175
+ self.save_format = save_format
176
+ self.img_clearing = img_clearing
177
+ self.img_path = img_path
178
+
179
+ def captcha_handler(
180
+ self,
181
+ captcha_link: Optional[str] = None,
182
+ captcha_file: Optional[str] = None,
183
+ captcha_base64: Optional[bytes] = None,
184
+ **kwargs,
185
+ ) -> dict:
186
+ """
187
+ Sync solving method
188
+
189
+ Args:
190
+ captcha_link: Captcha image URL
191
+ captcha_file: Captcha image file path
192
+ captcha_base64: Captcha image BASE64 info
193
+ kwargs: additional params for `requests` library
194
+
195
+ Returns:
196
+ Dict with full server response
197
+
198
+ Notes:
199
+ Check class docstirng for more info
200
+ """
201
+ self._body_file_processing(
202
+ save_format=self.save_format,
203
+ file_path=self.img_path,
204
+ captcha_link=captcha_link,
205
+ captcha_file=captcha_file,
206
+ captcha_base64=captcha_base64,
207
+ **kwargs,
208
+ )
209
+ if not self.result.errorId:
210
+ return self._processing_response(**kwargs)
211
+ return self.result.to_dict()
212
+
213
+ async def aio_captcha_handler(
214
+ self,
215
+ captcha_link: Optional[str] = None,
216
+ captcha_file: Optional[str] = None,
217
+ captcha_base64: Optional[bytes] = None,
218
+ **kwargs,
219
+ ) -> dict:
220
+ """
221
+ Async solving method
222
+
223
+ Args:
224
+ captcha_link: Captcha image URL
225
+ captcha_file: Captcha image file path
226
+ captcha_base64: Captcha image BASE64 info
227
+ kwargs: additional params for `aiohttp` library
228
+
229
+ Returns:
230
+ Dict with full server response
231
+
232
+ Notes:
233
+ Check class docstirng for more info
234
+ """
235
+ await self._aio_body_file_processing(
236
+ save_format=self.save_format,
237
+ file_path=self.img_path,
238
+ captcha_link=captcha_link,
239
+ captcha_file=captcha_file,
240
+ captcha_base64=captcha_base64,
241
+ **kwargs,
242
+ )
243
+ if not self.result.errorId:
244
+ return await self._aio_processing_response()
245
+ return self.result.to_dict()
246
+
247
+ def __del__(self):
248
+ if self.save_format == SaveFormatsEnm.CONST.value and self.img_clearing:
249
+ shutil.rmtree(self.img_path)
@@ -0,0 +1,111 @@
1
+ from typing import Union
2
+
3
+ from .core.base import BaseCaptcha
4
+ from .core.enums import KeyCaptchaEnm
5
+
6
+
7
+ class KeyCaptcha(BaseCaptcha):
8
+ def __init__(
9
+ self,
10
+ websiteURL: str,
11
+ s_s_c_user_id: str,
12
+ s_s_c_session_id: str,
13
+ s_s_c_web_server_sign: str,
14
+ s_s_c_web_server_sign2: str,
15
+ method: Union[str, KeyCaptchaEnm] = KeyCaptchaEnm.KeyCaptchaTaskProxyless,
16
+ *args,
17
+ **kwargs,
18
+ ):
19
+ """
20
+ The class is used to work with KeyCaptcha.
21
+
22
+ Args:
23
+ rucaptcha_key: User API key
24
+ websiteURL: Full URL of the captcha page
25
+ s_s_c_user_id: Value of `s_s_c_user_id` parameter found on the page
26
+ s_s_c_session_id: Value of `s_s_c_session_id` parameter found on the page
27
+ s_s_c_web_server_sign: Value of `s_s_c_web_server_sign` parameter found on the page
28
+ s_s_c_web_server_sign2: Value of `s_s_c_web_server_sign2` parameter found on the page
29
+ method: Captcha type
30
+ kwargs: Not required params for task creation request
31
+
32
+ Examples:
33
+ >>> KeyCaptcha(rucaptcha_key="aa9011f31111181111168611f1151122",
34
+ ... pageurl="https://rucaptcha.com/demo/keycaptcha",
35
+ ... s_s_c_user_id="184015",
36
+ ... s_s_c_session_id="0917788cad24ad3a69813c4fcd556061",
37
+ ... s_s_c_web_server_sign="02f7f9669f1269595c4c69bcd4a3c52e",
38
+ ... s_s_c_web_server_sign2="d888700f6f324ec0f32b44c32c50bde1",
39
+ ... method=KeyCaptchaEnm.KeyCaptchaTaskProxyless.value
40
+ ... ).captcha_handler()
41
+ {
42
+ "captchaSolve": "d58....61|1",
43
+ "taskId": 73052314114,
44
+ "error": False,
45
+ "errorBody": None
46
+ }
47
+
48
+ >>> await KeyCaptcha(rucaptcha_key="aa9011f31111181111168611f1151122",
49
+ ... pageurl="https://rucaptcha.com/demo/keycaptcha",
50
+ ... s_s_c_user_id="184015",
51
+ ... s_s_c_session_id="0917788cad24ad3a69813c4fcd556061",
52
+ ... s_s_c_web_server_sign="02f7f9669f1269595c4c69bcd4a3c52e",
53
+ ... s_s_c_web_server_sign2="d888700f6f324ec0f32b44c32c50bde1",
54
+ ... method=KeyCaptchaEnm.KeyCaptchaTaskProxyless.value
55
+ ... ).aio_captcha_handler()
56
+ {
57
+ "captchaSolve": "P1_eyJ.....cp_J",
58
+ "taskId": 73052314114,
59
+ "error": False,
60
+ "errorBody": None
61
+ }
62
+
63
+ Returns:
64
+ Dict with full server response
65
+
66
+ Notes:
67
+ https://rucaptcha.com/api-docs/keycaptcha
68
+ """
69
+ super().__init__(method=method, *args, **kwargs)
70
+
71
+ self.create_task_payload["task"].update(
72
+ {
73
+ "websiteURL": websiteURL,
74
+ "s_s_c_user_id": s_s_c_user_id,
75
+ "s_s_c_session_id": s_s_c_session_id,
76
+ "s_s_c_web_server_sign": s_s_c_web_server_sign,
77
+ "s_s_c_web_server_sign2": s_s_c_web_server_sign2,
78
+ }
79
+ )
80
+
81
+ # check user params
82
+ if method not in KeyCaptchaEnm.list_values():
83
+ raise ValueError(f"Invalid method parameter set, available - {KeyCaptchaEnm.list_values()}")
84
+
85
+ def captcha_handler(self, **kwargs) -> dict:
86
+ """
87
+ Sync solving method
88
+
89
+ Args:
90
+ kwargs: Parameters for the `requests` library
91
+
92
+ Returns:
93
+ Dict with full server response
94
+
95
+ Notes:
96
+ Check class docstirng for more info
97
+ """
98
+
99
+ return self._processing_response(**kwargs)
100
+
101
+ async def aio_captcha_handler(self) -> dict:
102
+ """
103
+ Async solving method
104
+
105
+ Returns:
106
+ Dict with full server response
107
+
108
+ Notes:
109
+ Check class docstirng for more info
110
+ """
111
+ return await self._aio_processing_response()
@@ -0,0 +1,112 @@
1
+ from typing import Union
2
+
3
+ from .core.base import BaseCaptcha
4
+ from .core.enums import LeminCaptchaEnm
5
+
6
+
7
+ class LeminCaptcha(BaseCaptcha):
8
+ def __init__(
9
+ self,
10
+ websiteURL: str,
11
+ captchaId: str,
12
+ div_id: str,
13
+ method: Union[str, LeminCaptchaEnm] = LeminCaptchaEnm.LeminTaskProxyless,
14
+ *args,
15
+ **kwargs,
16
+ ):
17
+ """
18
+ The class is used to work with Lemin Cropped Captcha.
19
+
20
+ Args:
21
+ rucaptcha_key: User API key
22
+ websiteURL: Full URL of the captcha page
23
+ captchaId: The value of the `captcha_id` parameter found on the site
24
+ div_id: The `id` of the parent `div`, which contains the captcha
25
+ method: Captcha type
26
+ kwargs: Not required params for task creation request
27
+
28
+ Examples:
29
+ >>> LeminCaptcha(rucaptcha_key="aa9011f31111181111168611f1151122",
30
+ ... websiteURL="https://dashboard.leminnow.com/auth/signup",
31
+ ... captchaId="CROPPED_099216d_8ba061383fa24ef498115023aa7189d4",
32
+ ... div_id="lemin-cropped-captcha",
33
+ ... method=LeminCaptchaEnm.LeminTaskProxyless.value,
34
+ ... api_server="api.leminnow.com"
35
+ ... ).captcha_handler()
36
+ {
37
+ "errorId":0,
38
+ "status":"ready",
39
+ "solution":{
40
+ "answer":"0xaxakx0xaxaax0xkxx3ox0x3ox3ox_...gAAAAABk8bgzEFOg9i3Jm",
41
+ "challenge_id":"e0348984-92ec-23af-1488-446e3a58946c"
42
+ },
43
+ "cost":"0.00299",
44
+ "ip":"1.2.3.4",
45
+ "createTime":1692863536,
46
+ "endTime":1692863556,
47
+ "solveCount":1,
48
+ "taskId": 73243152973,
49
+ }
50
+
51
+ >>> await LeminCaptcha(rucaptcha_key="aa9011f31111181111168611f1151122",
52
+ ... websiteURL="https://dashboard.leminnow.com/auth/signup",
53
+ ... captcha_id="CROPPED_099216d_8ba061383fa24ef498115023aa7189d4",
54
+ ... div_id="lemin-cropped-captcha",
55
+ ... method=LeminCaptchaEnm.LeminTaskProxyless.value,
56
+ ... api_server="api.leminnow.com"
57
+ ... ).aio_captcha_handler()
58
+ {
59
+ "errorId":0,
60
+ "status":"ready",
61
+ "solution":{
62
+ "answer":"0xaxakx0xaxaax0xkxx3ox0x3ox3ox_...gAAAAABk8bgzEFOg9i3Jm",
63
+ "challenge_id":"e0348984-92ec-23af-1488-446e3a58946c"
64
+ },
65
+ "cost":"0.00299",
66
+ "ip":"1.2.3.4",
67
+ "createTime":1692863536,
68
+ "endTime":1692863556,
69
+ "solveCount":1,
70
+ "taskId": 73243152973,
71
+ }
72
+
73
+ Returns:
74
+ Dict with full server response
75
+
76
+ Notes:
77
+ https://rucaptcha.com/api-docs/lemin
78
+ """
79
+ super().__init__(method=method, *args, **kwargs)
80
+
81
+ self.create_task_payload["task"].update({"websiteURL": websiteURL, "captchaId": captchaId, "div_id": div_id})
82
+
83
+ # check user params
84
+ if method not in LeminCaptchaEnm.list_values():
85
+ raise ValueError(f"Invalid method parameter set, available - {LeminCaptchaEnm.list_values()}")
86
+
87
+ def captcha_handler(self, **kwargs) -> dict:
88
+ """
89
+ Sync solving method
90
+
91
+ Args:
92
+ kwargs: Parameters for the `requests` library
93
+
94
+ Returns:
95
+ Dict with full server response
96
+
97
+ Notes:
98
+ Check class docstirng for more info
99
+ """
100
+ return self._processing_response(**kwargs)
101
+
102
+ async def aio_captcha_handler(self) -> dict:
103
+ """
104
+ Async solving method
105
+
106
+ Returns:
107
+ Dict with full server response
108
+
109
+ Notes:
110
+ Check class docstirng for more info
111
+ """
112
+ return await self._aio_processing_response()
@@ -0,0 +1,104 @@
1
+ from typing import Union
2
+
3
+ from .core.base import BaseCaptcha
4
+ from .core.enums import MTCaptchaEnm
5
+
6
+
7
+ class MTCaptcha(BaseCaptcha):
8
+ def __init__(
9
+ self,
10
+ websiteURL: str,
11
+ websiteKey: str,
12
+ method: Union[str, MTCaptchaEnm] = MTCaptchaEnm.MtCaptchaTaskProxyless.value,
13
+ *args,
14
+ **kwargs,
15
+ ):
16
+ """
17
+ The class is used to work with HCaptcha.
18
+
19
+ Args:
20
+ rucaptcha_key: User API key
21
+ websiteURL: Full URL of the captcha page
22
+ websiteKey: The MTCaptcha `sitekey` value found in the page code.
23
+ method: Captcha type
24
+ kwargs: Not required params for task creation request
25
+
26
+ Examples:
27
+ >>> MTCaptcha(rucaptcha_key="aa9011f31111181111168611f1151122",
28
+ ... websiteURL="https://service.mtcaptcha.com/mtcv1/demo/index.html",
29
+ ... websiteKey="MTPublic-DemoKey9M",
30
+ ... method=MTCaptchaEnm.MtCaptchaTaskProxyless,
31
+ ... ).captcha_handler()
32
+ {
33
+ "errorId":0,
34
+ "status":"ready",
35
+ "solution":{
36
+ "token": "datadome=4ZXwCBlyHx9ktZhSnycMF...; Path=/; Secure; SameSite=Lax"
37
+ },
38
+ "cost":"0.00299",
39
+ "ip":"1.2.3.4",
40
+ "createTime":1692863536,
41
+ "endTime":1692863556,
42
+ "solveCount":1,
43
+ "taskId": 73243152973,
44
+ }
45
+
46
+ >>> await MTCaptcha(rucaptcha_key="aa9011f31111181111168611f1151122",
47
+ ... websiteURL="https://service.mtcaptcha.com/mtcv1/demo/index.html",
48
+ ... websiteKey="MTPublic-DemoKey9M",
49
+ ... method=MTCaptchaEnm.MtCaptchaTaskProxyless,
50
+ ... ).aio_captcha_handler()
51
+ {
52
+ "errorId":0,
53
+ "status":"ready",
54
+ "solution":{
55
+ "token": "datadome=4ZXwCBlyHx9ktZhSnycMF...; Path=/; Secure; SameSite=Lax"
56
+ },
57
+ "cost":"0.00299",
58
+ "ip":"1.2.3.4",
59
+ "createTime":1692863536,
60
+ "endTime":1692863556,
61
+ "solveCount":1,
62
+ "taskId": 73243152973,
63
+ }
64
+
65
+ Returns:
66
+ Dict with full server response
67
+
68
+ Notes:
69
+ https://2captcha.com/api-docs/mtcaptcha
70
+ """
71
+ super().__init__(method=method, *args, **kwargs)
72
+
73
+ self.create_task_payload["task"].update({"websiteURL": websiteURL, "websiteKey": websiteKey})
74
+ # check user params
75
+ if method not in MTCaptchaEnm.list_values():
76
+ raise ValueError(f"Invalid method parameter set, available - {MTCaptchaEnm.list_values()}")
77
+
78
+ def captcha_handler(self, **kwargs) -> dict:
79
+ """
80
+ Sync solving method
81
+
82
+ Args:
83
+ kwargs: Parameters for the `requests` library
84
+
85
+ Returns:
86
+ Dict with full server response
87
+
88
+ Notes:
89
+ Check class docstirng for more info
90
+ """
91
+
92
+ return self._processing_response(**kwargs)
93
+
94
+ async def aio_captcha_handler(self) -> dict:
95
+ """
96
+ Async solving method
97
+
98
+ Returns:
99
+ Dict with full server response
100
+
101
+ Notes:
102
+ Check class docstirng for more info
103
+ """
104
+ return await self._aio_processing_response()