diff --git a/capmonster_python/__init__.py b/capmonster_python/__init__.py index 3c16720..8ae44e9 100644 --- a/capmonster_python/__init__.py +++ b/capmonster_python/__init__.py @@ -6,3 +6,4 @@ from .image_to_text import ImageToTextTask from .geetest import GeeTestTask from .utils import CapmonsterException +from .compleximage import ComplexImageTask diff --git a/capmonster_python/compleximage.py b/capmonster_python/compleximage.py new file mode 100644 index 0000000..0776c86 --- /dev/null +++ b/capmonster_python/compleximage.py @@ -0,0 +1,48 @@ +from .capmonster import UserAgent + +class ComplexImageTask(UserAgent): + def __init__(self, client_key): + super(ComplexImageTask, self).__init__(client_key) + + def create_task(self, _class: str, grid: str = None, + task_definition: str = None, + image_urls: list = None, + images_base64: list = None, + task: str = None, + websiteUrl: str = None): + if _class is not "recaptcha" or _class is not "hcaptcha": + raise ValueError("Currently only recaptcha or hcaptcha is supported as _class value.") + data = { + "clientKey": self._client_key, + "task": { + "type": "ComplexImageTask", + "class": _class, + "metadata": {} + } + } + if image_urls is not None: + data["task"]["imageUrls"] = image_urls + elif images_base64 is not None: + data["task"]["imagesBase64"] = images_base64 + else: + raise ValueError("image_urls or images_base64 must be sent") + if _class is "recaptcha": + if grid is None: + raise ValueError("Grid parameter must sent with recaptcha") + else: + data["task"]["metadata"]["Grid"] = grid + if task is not None: + data["task"]["metadata"]["Task"] = task + elif task_definition is not None: + data["task"]["metadata"]["TaskDefinition"] = task_definition + else: + raise ValueError("task_definition or task parameter must be sent") + elif _class is "hcaptcha": + if task is not None: + data["task"]["metadata"]["Task"] = task + else: + raise ValueError("task parameter must be sent with hcaptcha") + if websiteUrl is not None: + data["task"]["websiteUrl"] = websiteUrl + data, is_user_agent = self._add_user_agent(data) + return self._make_request("createTask", data).get("taskId") \ No newline at end of file diff --git a/setup.py b/setup.py index 73170f7..3d691b3 100644 --- a/setup.py +++ b/setup.py @@ -7,14 +7,14 @@ setup( name="capmonster_python", - version="2.3", + version="2.4", packages=["capmonster_python"], url="https://github.com/alperensert/capmonster_python", long_description=long_description, long_description_content_type="text/markdown", license="MIT", author="Alperen Sert", - author_email="mail@alperenn.com", + author_email="business@alperen.io", description="capmonster.cloud library for Python", requires=["requests"], classifiers=[