1313from .const import RETRIES , ASYNC_RETRIES
1414from .serializer import CaptchaResponseSer
1515
16- __all__ = ("CaptchaInstrument " , "FileInstrument" )
16+ __all__ = ("CaptchaInstrumentBase " , "FileInstrument" )
1717
1818
1919class FileInstrument :
20+ """
21+ This class contains usefull methods for async and async files processing to prepare them for solving
22+
23+ Examples:
24+ >>> from python3_capsolver.core.captcha_instrument import FileInstrument
25+ >>> body = FileInstrument().file_processing(captcha_file="captcha_example.jpeg")
26+ /9j/4AAQSkZJRgABAQAAAQABAAD/2wCEAAoHCBUVxxxxx
27+
28+ >>> from python3_capsolver.core.captcha_instrument import FileInstrument
29+ >>> body = FileInstrument().file_processing(captcha_link="https://some-url/file.jpeg")
30+ /9j/4AAQSkZJRgABAQAAAQABAAD/2wCEAAoHCBUVxxxxx
31+
32+ Returns:
33+ String with decoded file data
34+ """
35+
2036 @staticmethod
2137 def _local_file_captcha (captcha_file : str ):
2238 """
@@ -80,6 +96,33 @@ def file_processing(
8096 file_extension : str = "png" ,
8197 ** kwargs ,
8298 ) -> str :
99+ """
100+ Synchronous method for captcha image processing.
101+ - Method can read local file and return it's as base64 string.
102+ - Method can read file URL and return it's as base64 string.
103+ - Method can decode base64 bytes and return it's as base64 string.
104+
105+ Args:
106+ captcha_link: URL link to file. Instrument will send GET request to it and read content
107+ captcha_file: Local file path. Instrument will read it
108+ captcha_base64: Readed file base64 data. Instrument will decode it in ``utf-8``
109+ save_format: This arg works only with ``captcha_link`` arg
110+ If ``SaveFormatsEnm.CONST`` is set - file will be loaded and saved locally.
111+ img_clearing: This arg works only with ``captcha_link`` arg
112+ If ``False`` - file wil not be removed downloading and saving locally
113+ file_path: This arg works only with ``captcha_link`` and ``SaveFormatsEnm.CONST`` args
114+ In this param u can set locally path for downloaded file saving
115+ file_extension: This arg works only with ``file_path`` args
116+ In this param u MUST set file format for saving
117+
118+ Examples:
119+ >>> from python3_capsolver.core.captcha_instrument import FileInstrument
120+ >>> body = FileInstrument().file_processing(captcha_file="captcha_example.jpeg")
121+ /9j/4AAQSkZJRgABAQAAAQABAAD/2wCEAAoHCBUVxxxxx
122+
123+ Returns:
124+ String with decoded file data
125+ """
83126 # if a local file link is passed
84127 if captcha_file :
85128 return base64 .b64encode (self ._local_file_captcha (captcha_file = captcha_file )).decode ("utf-8" )
@@ -109,6 +152,35 @@ async def aio_file_processing(
109152 file_extension : str = "png" ,
110153 ** kwargs ,
111154 ) -> str :
155+ """
156+ Asynchronous method for captcha image processing.
157+ - Method can read local file and return it's as base64 string.
158+ - Method can read file URL and return it's as base64 string.
159+ - Method can decode base64 bytes and return it's as base64 string.
160+
161+ Args:
162+ captcha_link: URL link to file. Instrument will send GET request to it and read content
163+ captcha_file: Local file path. Instrument will read it
164+ captcha_base64: Readed file base64 data. Instrument will decode it in ``utf-8``
165+ save_format: This arg works only with ``captcha_link`` arg
166+ If ``SaveFormatsEnm.CONST`` is set - file will be loaded and saved locally.
167+ img_clearing: This arg works only with ``captcha_link`` arg
168+ If ``False`` - file wil not be removed downloading and saving locally
169+ file_path: This arg works only with ``captcha_link`` and ``SaveFormatsEnm.CONST`` args
170+ In this param u can set locally path for downloaded file saving
171+ file_extension: This arg works only with ``file_path`` args
172+ In this param u MUST set file format for saving
173+
174+ Examples:
175+ >>> import asyncio
176+ >>> from python3_capsolver.core.captcha_instrument import FileInstrument
177+ >>> body = asyncio.run(FileInstrument()
178+ ... .aio_file_processing(captcha_file="captcha_example.jpeg"))
179+ /9j/4AAQSkZJRgABAQAAAQABAAD/2wCEAAoHCBUVxxxxx
180+
181+ Returns:
182+ String with decoded file data
183+ """
112184 # if a local file link is passed
113185 if captcha_file :
114186 return base64 .b64encode (self ._local_file_captcha (captcha_file = captcha_file )).decode ("utf-8" )
@@ -129,8 +201,9 @@ async def aio_file_processing(
129201 raise ValueError ("No valid captcha variant is set." )
130202
131203
132- class CaptchaInstrument ( FileInstrument ) :
204+ class CaptchaInstrumentBase :
133205 CAPTCHA_UNSOLVABLE = "ERROR_CAPTCHA_UNSOLVABLE"
206+ CAPTCHA_UNSOLVABLE_DESCRIPTION = "Captcha not recognized"
134207 """
135208 Basic Captcha solving class
136209
0 commit comments