Skip to content

Commit

Permalink
complex image task added
Browse files Browse the repository at this point in the history
  • Loading branch information
alperensert committed Mar 10, 2023
1 parent 13f4c3b commit a408ad3
Show file tree
Hide file tree
Showing 3 changed files with 51 additions and 2 deletions.
1 change: 1 addition & 0 deletions capmonster_python/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,4 @@
from .image_to_text import ImageToTextTask
from .geetest import GeeTestTask
from .utils import CapmonsterException
from .compleximage import ComplexImageTask
48 changes: 48 additions & 0 deletions capmonster_python/compleximage.py
Original file line number Diff line number Diff line change
@@ -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")
4 changes: 2 additions & 2 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -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=[
Expand Down

0 comments on commit a408ad3

Please sign in to comment.