diff --git a/docs/conf.py b/docs/conf.py index 5e86745..dd85b26 100644 --- a/docs/conf.py +++ b/docs/conf.py @@ -22,6 +22,8 @@ recaptcha_v2, recaptcha_v3, image_to_text, + prosopo_captcha, + friendly_captcha, image_to_coordinates, ) from python3_anticaptcha.__version__ import __version__ diff --git a/docs/modules/friend/example.rst b/docs/modules/friend/example.rst new file mode 100644 index 0000000..be940aa --- /dev/null +++ b/docs/modules/friend/example.rst @@ -0,0 +1,12 @@ +FriendlyCaptcha +=============== + +To import this module: + +.. code-block:: python + + from python3_anticaptcha.friendly_captcha import FriendlyCaptcha + + +.. autoclass:: python3_anticaptcha.friendly_captcha.FriendlyCaptcha + :members: diff --git a/docs/modules/prosopo/example.rst b/docs/modules/prosopo/example.rst new file mode 100644 index 0000000..8acd406 --- /dev/null +++ b/docs/modules/prosopo/example.rst @@ -0,0 +1,12 @@ +Prosopo +======= + +To import this module: + +.. code-block:: python + + from python3_anticaptcha.prosopo_captcha import Prosopo + + +.. autoclass:: python3_anticaptcha.prosopo_captcha.Prosopo + :members: diff --git a/docs/requirements.txt b/docs/requirements.txt index ecc43cc..e44b97a 100644 --- a/docs/requirements.txt +++ b/docs/requirements.txt @@ -1,3 +1,3 @@ -sphinx==8.2.1 +sphinx==8.3.0 pallets_sphinx_themes==2.3.0 myst-parser==4.0.1 diff --git a/requirements.style.txt b/requirements.style.txt index d5dea09..5444207 100644 --- a/requirements.style.txt +++ b/requirements.style.txt @@ -1,4 +1,4 @@ # codestyle -isort==5.* +isort==6.* black==25.* autoflake==2.* diff --git a/src/python3_anticaptcha/__version__.py b/src/python3_anticaptcha/__version__.py index e835b9d..df4be5e 100644 --- a/src/python3_anticaptcha/__version__.py +++ b/src/python3_anticaptcha/__version__.py @@ -1 +1 @@ -__version__ = "2.1.3" +__version__ = "2.1.4" diff --git a/src/python3_anticaptcha/core/enum.py b/src/python3_anticaptcha/core/enum.py index d1267d4..ae9c30e 100644 --- a/src/python3_anticaptcha/core/enum.py +++ b/src/python3_anticaptcha/core/enum.py @@ -55,6 +55,12 @@ class CaptchaTypeEnm(str, MyEnum): # Turnstile TurnstileTask = "TurnstileTask" TurnstileTaskProxyless = "TurnstileTaskProxyless" + # FriendlyCaptcha + FriendlyCaptchaTask = "FriendlyCaptchaTask" + FriendlyCaptchaTaskProxyless = "FriendlyCaptchaTaskProxyless" + # FriendlyCaptcha + ProsopoTask = "ProsopoTask" + ProsopoTaskProxyless = "ProsopoTaskProxyless" # Custom AntiGateTask = "AntiGateTask" diff --git a/src/python3_anticaptcha/friendly_captcha.py b/src/python3_anticaptcha/friendly_captcha.py new file mode 100644 index 0000000..9dcec2d --- /dev/null +++ b/src/python3_anticaptcha/friendly_captcha.py @@ -0,0 +1,146 @@ +from typing import Union, Optional + +from .core.base import CaptchaParams +from .core.enum import ProxyTypeEnm, CaptchaTypeEnm + +__all__ = ("FriendlyCaptcha",) + + +class FriendlyCaptcha(CaptchaParams): + def __init__( + self, + api_key: str, + websiteURL: str, + websiteKey: str, + captcha_type: Union[CaptchaTypeEnm, str] = CaptchaTypeEnm.FriendlyCaptchaTaskProxyless, + proxyType: Optional[Union[ProxyTypeEnm, str]] = None, + proxyAddress: Optional[str] = None, + proxyPort: Optional[int] = None, + proxyLogin: Optional[str] = None, + proxyPassword: Optional[str] = None, + userAgent: Optional[str] = None, + sleep_time: Optional[int] = 10, + ): + """ + The class is used to work with FriendlyCaptcha. + + Args: + api_key: Capsolver API key + captcha_type: Captcha type + websiteURL: Address of the webpage + websiteKey: Friendly Captcha sitekey + proxyType: Type of the proxy + proxyAddress: Proxy IP address IPv4/IPv6. Not allowed to use: + host names instead of IPs, + transparent proxies (where client IP is visible), + proxies from local networks (192.., 10.., 127...) + proxyPort: Proxy port. + proxyLogin: Proxy login. + proxyPassword: Proxy password. + userAgent: Browser UserAgent. + sleep_time: The waiting time between requests to get the result of the Captcha + + Examples: + >>> FriendlyCaptcha(api_key="99d7d111a0111dc11184111c8bb111da", + ... captcha_type="FriendlyCaptchaTaskProxyless", + ... websiteURL="https://demo.arkoselabs.com", + ... websiteKey="FCMDESUD3M34857N" + ... ).captcha_handler() + { + "errorId": 0, + "errorCode": None, + "errorDescription": None, + "status":"ready", + "solution":{ + "token":"0.Qz0.....f1", + "userAgent":"Mozilla/5.0 (Wind.....", + }, + "cost": 0.002, + "ip": "46.53.249.230", + "createTime": 1679004358, + "endTime": 1679004368, + "solveCount": 0, + "taskId": 396687629 + } + + >>> await FriendlyCaptcha(api_key="99d7d111a0111dc11184111c8bb111da", + ... captcha_type="FriendlyCaptchaTaskProxyless", + ... websiteURL="https://demo.arkoselabs.com", + ... websitePublicKey="DF9C4D87-CB7B-4062-9FEB-BADB6ADA61E6" + ... ).aio_captcha_handler() + { + "errorId": 0, + "errorCode": None, + "errorDescription": None, + "status":"ready", + "solution":{ + "token":"0.Qz0.....f1", + "userAgent":"Mozilla/5.0 (Wind.....", + }, + "cost": 0.002, + "ip": "46.53.249.230", + "createTime": 1679004358, + "endTime": 1679004368, + "solveCount": 0, + "taskId": 396687629 + } + + >>> FriendlyCaptcha(api_key="99d7d111a0111dc11184111c8bb111da", + ... captcha_type="FriendlyCaptchaTask", + ... websiteURL="https://demo.arkoselabs.com", + ... websitePublicKey="DF9C4D87-CB7B-4062-9FEB-BADB6ADA61E6", + ... proxyType="http", + ... proxyAddress="0.0.0.0", + ... proxyPort=9988, + ... proxyLogin="proxy_login", + ... proxyPassword="proxy_password", + ... userAgent="some_real_user_agent", + ... ).captcha_handler() + { + "errorId": 0, + "errorCode": None, + "errorDescription": None, + "status":"ready", + "solution":{ + "token":"0.Qz0.....f1", + "userAgent":"Mozilla/5.0 (Wind.....", + }, + "cost": 0.002, + "ip": "46.53.249.230", + "createTime": 1679004358, + "endTime": 1679004368, + "solveCount": 0, + "taskId": 396687629 + } + + Notes + https://anti-captcha.com/apidoc/task-types/FriendlyCaptchaTask + + https://anti-captcha.com/apidoc/task-types/FriendlyCaptchaTaskProxyless + """ + super().__init__(api_key=api_key, sleep_time=sleep_time) + + # validation of the received parameters + if captcha_type == CaptchaTypeEnm.FriendlyCaptchaTask: + self.task_params = dict( + type=captcha_type, + websiteURL=websiteURL, + websiteKey=websiteKey, + proxyType=proxyType, + proxyAddress=proxyAddress, + proxyPort=proxyPort, + proxyLogin=proxyLogin, + proxyPassword=proxyPassword, + userAgent=userAgent, + ) + elif captcha_type == CaptchaTypeEnm.FriendlyCaptchaTaskProxyless: + self.task_params = dict( + type=captcha_type, + websiteURL=websiteURL, + websiteKey=websiteKey, + ) + else: + raise ValueError( + f"Invalid `captcha_type` parameter set for `{self.__class__.__name__}`, \ + available - {CaptchaTypeEnm.FriendlyCaptchaTaskProxyless.value,CaptchaTypeEnm.FriendlyCaptchaTask.value}" + ) diff --git a/src/python3_anticaptcha/prosopo_captcha.py b/src/python3_anticaptcha/prosopo_captcha.py new file mode 100644 index 0000000..e638b84 --- /dev/null +++ b/src/python3_anticaptcha/prosopo_captcha.py @@ -0,0 +1,146 @@ +from typing import Union, Optional + +from .core.base import CaptchaParams +from .core.enum import ProxyTypeEnm, CaptchaTypeEnm + +__all__ = ("Prosopo",) + + +class Prosopo(CaptchaParams): + def __init__( + self, + api_key: str, + websiteURL: str, + websiteKey: str, + captcha_type: Union[CaptchaTypeEnm, str] = CaptchaTypeEnm.ProsopoTaskProxyless, + proxyType: Optional[Union[ProxyTypeEnm, str]] = None, + proxyAddress: Optional[str] = None, + proxyPort: Optional[int] = None, + proxyLogin: Optional[str] = None, + proxyPassword: Optional[str] = None, + userAgent: Optional[str] = None, + sleep_time: Optional[int] = 10, + ): + """ + The class is used to work with Prosopo captcha. + + Args: + api_key: Capsolver API key + captcha_type: Captcha type + websiteURL: Address of the webpage + websiteKey: Prosopo sitekey + proxyType: Type of the proxy + proxyAddress: Proxy IP address IPv4/IPv6. Not allowed to use: + host names instead of IPs, + transparent proxies (where client IP is visible), + proxies from local networks (192.., 10.., 127...) + proxyPort: Proxy port. + proxyLogin: Proxy login. + proxyPassword: Proxy password. + userAgent: Browser UserAgent. + sleep_time: The waiting time between requests to get the result of the Captcha + + Examples: + >>> Prosopo(api_key="99d7d111a0111dc11184111c8bb111da", + ... captcha_type="ProsopoTaskProxyless", + ... websiteURL="https://demo.arkoselabs.com", + ... websiteKey="FCMDESUD3M34857N" + ... ).captcha_handler() + { + "errorId": 0, + "errorCode": None, + "errorDescription": None, + "status":"ready", + "solution":{ + "token":"0.Qz0.....f1", + "userAgent":"Mozilla/5.0 (Wind.....", + }, + "cost": 0.002, + "ip": "46.53.249.230", + "createTime": 1679004358, + "endTime": 1679004368, + "solveCount": 0, + "taskId": 396687629 + } + + >>> await Prosopo(api_key="99d7d111a0111dc11184111c8bb111da", + ... captcha_type="ProsopoTaskProxyless", + ... websiteURL="https://demo.arkoselabs.com", + ... websitePublicKey="DF9C4D87-CB7B-4062-9FEB-BADB6ADA61E6" + ... ).aio_captcha_handler() + { + "errorId": 0, + "errorCode": None, + "errorDescription": None, + "status":"ready", + "solution":{ + "token":"0.Qz0.....f1", + "userAgent":"Mozilla/5.0 (Wind.....", + }, + "cost": 0.002, + "ip": "46.53.249.230", + "createTime": 1679004358, + "endTime": 1679004368, + "solveCount": 0, + "taskId": 396687629 + } + + >>> Prosopo(api_key="99d7d111a0111dc11184111c8bb111da", + ... captcha_type="ProsopoTask", + ... websiteURL="https://demo.arkoselabs.com", + ... websitePublicKey="DF9C4D87-CB7B-4062-9FEB-BADB6ADA61E6", + ... proxyType="http", + ... proxyAddress="0.0.0.0", + ... proxyPort=9988, + ... proxyLogin="proxy_login", + ... proxyPassword="proxy_password", + ... userAgent="some_real_user_agent", + ... ).captcha_handler() + { + "errorId": 0, + "errorCode": None, + "errorDescription": None, + "status":"ready", + "solution":{ + "token":"0.Qz0.....f1", + "userAgent":"Mozilla/5.0 (Wind.....", + }, + "cost": 0.002, + "ip": "46.53.249.230", + "createTime": 1679004358, + "endTime": 1679004368, + "solveCount": 0, + "taskId": 396687629 + } + + Notes + https://anti-captcha.com/apidoc/task-types/ProsopoTask + + https://anti-captcha.com/apidoc/task-types/ProsopoTaskProxyless + """ + super().__init__(api_key=api_key, sleep_time=sleep_time) + + # validation of the received parameters + if captcha_type == CaptchaTypeEnm.ProsopoTask: + self.task_params = dict( + type=captcha_type, + websiteURL=websiteURL, + websiteKey=websiteKey, + proxyType=proxyType, + proxyAddress=proxyAddress, + proxyPort=proxyPort, + proxyLogin=proxyLogin, + proxyPassword=proxyPassword, + userAgent=userAgent, + ) + elif captcha_type == CaptchaTypeEnm.ProsopoTaskProxyless: + self.task_params = dict( + type=captcha_type, + websiteURL=websiteURL, + websiteKey=websiteKey, + ) + else: + raise ValueError( + f"Invalid `captcha_type` parameter set for `{self.__class__.__name__}`, \ + available - {CaptchaTypeEnm.ProsopoTaskProxyless.value,CaptchaTypeEnm.ProsopoTask.value}" + )