diff --git a/docs/conf.py b/docs/conf.py index ba14013..2e10f84 100644 --- a/docs/conf.py +++ b/docs/conf.py @@ -5,6 +5,7 @@ from python3_capsolver import ( core, + akamai, gee_test, hcaptcha, recaptcha, diff --git a/docs/index.rst b/docs/index.rst index 170c03e..80eab72 100644 --- a/docs/index.rst +++ b/docs/index.rst @@ -32,6 +32,7 @@ The library is intended for software developers and is used to work with the `Ca modules/cloudflare/example.rst modules/aws-waf/example.rst modules/cyber-si-ara/example.rst + modules/akamai/example.rst .. toctree:: :maxdepth: 2 diff --git a/docs/modules/akamai/example.rst b/docs/modules/akamai/example.rst new file mode 100644 index 0000000..62c4769 --- /dev/null +++ b/docs/modules/akamai/example.rst @@ -0,0 +1,12 @@ +Akamai +====== + +To import this module: + +.. code-block:: python + + from python3_capsolver.akamai import Akamai + + +.. autoclass:: python3_capsolver.akamai.Akamai + :members: \ No newline at end of file diff --git a/docs/modules/serializer/info.rst b/docs/modules/serializer/info.rst index ea044b2..acefab7 100644 --- a/docs/modules/serializer/info.rst +++ b/docs/modules/serializer/info.rst @@ -16,3 +16,13 @@ To import this module: .. autopydantic_model:: python3_capsolver.core.serializer.WebsiteDataOptionsSer :members: :undoc-members: + + +.. autopydantic_model:: python3_capsolver.core.serializer.CyberSiAraSer + :members: + :undoc-members: + + +.. autopydantic_model:: python3_capsolver.core.serializer.AntiAkamaiBMPTaskSer + :members: + :undoc-members: diff --git a/src/python3_capsolver/akamai.py b/src/python3_capsolver/akamai.py new file mode 100644 index 0000000..fdb6df9 --- /dev/null +++ b/src/python3_capsolver/akamai.py @@ -0,0 +1,143 @@ +from typing import Union + +from python3_capsolver.core.base import BaseCaptcha +from python3_capsolver.core.enum import AntiAkamaiTaskEnm, EndpointPostfixEnm +from python3_capsolver.core.serializer import PostRequestSer, CaptchaResponseSer, AntiAkamaiBMPTaskSer + + +class Akamai(BaseCaptcha): + """ + The class is used to work with Capsolver AntiAkamai methods. + + Args: + api_key: Capsolver API key + captcha_type: Captcha type name, like ``AntiAkamaiBMPTask`` and etc. + packageName: Package name of AkamaiBMP mobile APP + version: AKAMAI BMP Version number, default is: 3.2.6 , max support 3.3.1 + + Examples: + >>> Akamai(api_key="CAI-BA9XXXXXXXXXXXXX2702E010", + ... captcha_type="AntiAkamaiBMPTask", + ... packageName="de.zalando.iphone", + ... country="US", + ... deviceId="90F9EAF5-D6E5-4E30-BC8B-B7780AD02600", + ... deviceName="iPhone14,2/16.0.2", + ... count=10, + ... ).captcha_handler() + CaptchaResponseSer(errorId=0, + errorCode=None, + errorDescription=None, + taskId='73bdcd28-6c77-4414-8....', + status=, + solution={'deviceId': '90F9EAF...'} + ) + + >>> Akamai(api_key="CAI-BA9XXXXXXXXXXXXX2702E010", + ... captcha_type=AntiAkamaiTaskEnm.AntiAkamaiBMPTask, + ... ).captcha_handler() + CaptchaResponseSer(errorId=0, + errorCode=None, + errorDescription=None, + taskId='73bdcd28-6c77-4414-8....', + status=, + solution={'deviceId': '6DKFOD0...'} + ) + + >>> Akamai(api_key="CAI-BA9XXXXXXXXXXXXX2702E010", + ... captcha_type=AntiAkamaiTaskEnm.AntiAkamaiBMPTask, + ... **{ + ... "version": "3.2.6", + ... "deviceId": "90F9EAF5-D6E5-4E30-BC8B-B7780AD02600", + ... "deviceName": "iPhone14,2/16.0.2", + ... "count": 10, + ... }, + ... ).captcha_handler() + CaptchaResponseSer(errorId=0, + errorCode=None, + errorDescription=None, + taskId="87f149f4-1c....", + status=, + solution={'deviceId': '90F9EAF...'} + ) + + >>> await Akamai(api_key="CAI-BA9650D2B9C2786B21120D512702E010", + ... captcha_type="AntiAkamaiBMPTask", + ... packageName="de.zalando.iphone", + ... country="US", + ... deviceId="90F9EAF5-D6E5-4E30-BC8B-B7780AD02600", + ... deviceName="iPhone14,2/16.0.2", + ... count=10, + ... ).aio_captcha_handler() + CaptchaResponseSer(errorId=0, + errorCode=None, + errorDescription=None, + taskId='73bdcd28-6c77-4414-8....', + status=, + solution={'deviceId': '90F9EAF...'} + ) + + Returns: + CaptchaResponseSer model with full server response + + Notes: + https://docs.capsolver.com/guide/antibots/akamaibmp.html + https://docs.capsolver.com/guide/antibots/akamaiweb.html + """ + + serializer = PostRequestSer + + def __init__( + self, + captcha_type: Union[AntiAkamaiTaskEnm, str], + packageName: str = "de.zalando.iphone", + version: str = "3.2.6", + country: str = "US", + *args, + **kwargs, + ): + super().__init__(*args, **kwargs) + + if captcha_type == AntiAkamaiTaskEnm.AntiAkamaiBMPTask: + self.task_params = AntiAkamaiBMPTaskSer(**locals()).dict() + else: + raise ValueError( + f"""Invalid `captcha_type` parameter set for `{self.__class__.__name__}`, + available - {AntiAkamaiTaskEnm.list_values()}""" + ) + + for key in kwargs: + self.task_params.update({key: kwargs[key]}) + + def captcha_handler(self) -> CaptchaResponseSer: + """ + Sync solving method + + Returns: + CaptchaResponseSer model with full service response + + Notes: + Check class docstring for more info + """ + self._prepare_create_task_payload(serializer=self.serializer, create_params=self.task_params) + return CaptchaResponseSer( + **self._create_task( + url_postfix=EndpointPostfixEnm.AKAMAI_BMP_INVOKE.value, + ) + ) + + async def aio_captcha_handler(self) -> CaptchaResponseSer: + """ + Async method for captcha solving + + Returns: + CaptchaResponseSer model with full service response + + Notes: + Check class docstring for more info + """ + self._prepare_create_task_payload(serializer=self.serializer, create_params=self.task_params) + return CaptchaResponseSer( + **await self._aio_create_task( + url_postfix=EndpointPostfixEnm.AKAMAI_BMP_INVOKE.value, + ) + ) diff --git a/src/python3_capsolver/core/enum.py b/src/python3_capsolver/core/enum.py index 86fbd12..6288204 100644 --- a/src/python3_capsolver/core/enum.py +++ b/src/python3_capsolver/core/enum.py @@ -39,6 +39,8 @@ class EndpointPostfixEnm(str, MyEnum): GET_BALANCE = "getBalance" CREATE_TASK = "createTask" GET_TASK_RESULT = "getTaskResult" + AKAMAI_BMP_INVOKE = "/akamaibmp/invoke" + AKAMAI_WEB_INVOKE = "/akamaiweb/invoke" class ImageToTextTaskTypeEnm(str, MyEnum): @@ -110,6 +112,11 @@ class AntiCyberSiAraTaskTypeEnm(str, MyEnum): AntiCyberSiAraTaskProxyLess = "AntiCyberSiAraTaskProxyLess" +class AntiAkamaiTaskEnm(str, MyEnum): + AntiAkamaiBMPTask = "AntiAkamaiBMPTask" + AntiAkamaiWebTask = "AntiAkamaiWebTask" + + class ResponseStatusEnm(str, MyEnum): """ Enum store results `status` field variants diff --git a/src/python3_capsolver/core/serializer.py b/src/python3_capsolver/core/serializer.py index 5c6d96a..b7cfc44 100644 --- a/src/python3_capsolver/core/serializer.py +++ b/src/python3_capsolver/core/serializer.py @@ -132,3 +132,9 @@ class CyberSiAraSer(WebsiteDataOptionsSer): ..., description="You can get MasterUrlId param form `api/CyberSiara/GetCyberSiara` endpoint request" ) UserAgent: str = Field(..., description="Browser userAgent, you need submit your userAgent") + + +class AntiAkamaiBMPTaskSer(BaseModel): + packageName: str = Field("de.zalando.iphone", description="Package name of AkamaiBMP mobile APP") + version: str = Field("3.2.6", description="AKAMAI BMP Version number") + country: str = Field("US", description="AKAMAI BMP country")