ExAntiGate v0.4.1 ExAntiGate View Source
This is documentation for ExAntiGate - unofficial anti-captcha.com (antigate.com) API client for Elixir. The antigate service solves captchas by human workers.
Disclaimer
This project has been intended for fair use only. It's not allowed to use it for any destructive, anti-social and/or illegal activity.
Description
Unofficial anti-captcha.com (antigate.com) API client for Elixir. The antigate service solves captchas by human workers.
Supports:
- ImageToTextTask : solve usual image captcha
- NoCaptchaTask : Google Recaptcha puzzle solving
- NoCaptchaTaskProxyless : Google Recaptcha puzzle solving without proxies
- RecaptchaV3TaskProxyless : Google Recaptcha v.3
- FunCaptchaTask - rotating captcha funcaptcha.com
- FunCaptchaTaskProxyless - funcaptcha without proxy
- SquareNetTextTask : select objects on image with an overlay grid
Installation
Add it to your dependencies:
# mix.exs
def deps do
[{:ex_anti_gate, "~> 0.4"}]
end
end fetch it with mix deps.get
.
Configuration
The Antigate client has to be configured. At least api_key
MUST be set, otherwise the client
is shutting down with a notice. It's possible to set it in config file or via environment variable
EX_ANTI_GATE_API_KEY
. Note: in case of both (system and config) options exist at the same time
the environment variable value will be used.
Since 0.4 version now settings split into common and task specific parts.
Default common options look like this:
config :ex_anti_gate,
autostart: true, # Start ExAntiGate process on application start
http_client: HTTPoison, # http client - change for testing proposes only
# ############################# task options #####################################
api_key: nil,
api_host: "https://api.anti-captcha.com",
language_pool: "en", # "en" (default) - english queue,
# "rn" - Russian, Ukrainian, Belorussian, Kazakh language group
result_request_interval: 10_000, # result request first attemt interval, in milliseconds
result_retry_interval: 2_000, # delay between captcha status checks, in milliseconds
no_slot_retry_interval: 5_000, # delay between retries to catch a free slot to proceed captcha, in milliseconds
no_slot_max_retries: 0, # number of retries to catch a free slot,
# 0 - until (max_timeout - result_request_inteval) milliseconds gone
max_timeout: 120_000, # captcha recognition maximum timeout;
# the result value must be read during this period
push: false # do not reply to the sender by default (wait for a result request)
Default tasks options exists for ImageToTextTask only but you can set any options you need the same way:
config :ex_anti_gate, ExAntiGate.Tasks.ImageToTextTask,
phrase: false, # does captcha have one or more spaces
case: false, # captcha is case sensetive
numeric: 0, # 0 - any symbols
# 1 - captcha has digits only
# 2 - captcha has any symbols EXCEPT digits
math: false, # captcha is a math equation and it's necessary to solve it and enter result
min_length: 0, # 0 - has no limits
# > 0 - an integer sets minimum captcha length
max_length: 0, # 0 - has no limits
# > 0 - an integer sets maximum captcha length
How to use
It is possible to use it in standard and push mode.
In standard mode you send a task request with ExAntiGate.solve_captcha/2
function and then can
request current result with ExAntiGate.get_task_result/1
or a full task stack with ExAntiGate.get_task/1
.
get_task_result/1
is preferable.
In push mode you should wait for two kind of tuples:
{:ex_anti_gate_result, {:ready, task_uuid :: String.t(), response :: any}}
in case of successfull task or{:ex_anti_gate_result, {:error, task_uuid :: String.t(), error_id :: integer, error_code :: String.t(), error_description :: String.t()}}
- in case of any errors.
For example:
defmodule MyCaptchaDispatcher do
use GenServer
# ...
# Server API
def handle_info({:ex_anti_gate_result, {:ready, task_uuid, %{"solution" => %{"text" => text}} = _response}}, state) do
# deal with captcha text
end
def handle_info({:ex_anti_gate_result, {:error, task_uuid, error_id, error_code, error_description}}, state) do
# deal with error
end
end
Please beware that in push mode task data disappear right after message is sent without any kind of delivery check and
in standard mode task data disappear after max_timeout
amount of time.
Please check available task options in the Antigate tasks documentation. Parameters send as Keyword (so all keys are atoms), please, mind parameters case.
Errors
You can find most errors description in the Antigate documentation. A number of errors came from this client implementation and have negative codes:
error_id
: -1, error_code
: "ERROR_UNKNOWN_ERROR", error_description
: will be taken from the error source
error_id
: -2, error_code
: "ERROR_API_TIMEOUT", error_description
: "Maximum timeout reached, task interrupted."
error_id
: -3, error_code
: "ERROR_NO_SLOT_MAX_RETRIES", error_description
: "Maximum attempts to catch free slot reached, task interrupted."
Link to this section Summary
Functions
Returns a specification to start this module under a supervisor.
Returns task's current full structure by uuid
Returns task current status with result as one of the following
Invoked when the server is started. start_link/3
or start/3
will
block until it returns.
Creates a new task for a captcha. Expects captcha task type and task options as in Antigate documentation
Starts the antigate client process
Starts the antigate client linked process
Link to this section Functions
Returns a specification to start this module under a supervisor.
See Supervisor
.
Returns task's current full structure by uuid
Returns task current status with result as one of the following:
{:waiting, :none}
- waiting for result{:ready, result :: any}
- captcha solved; the second param has result (text captcha result is%{text :: String.t()}
){:error, {error_id :: integer, error_code :: String.t(), error_description :: String.t()}}
- an error with description
Invoked when the server is started. start_link/3
or start/3
will
block until it returns.
init_arg
is the argument term (second argument) passed to start_link/3
.
Returning {:ok, state}
will cause start_link/3
to return
{:ok, pid}
and the process to enter its loop.
Returning {:ok, state, timeout}
is similar to {:ok, state}
,
except that it also sets a timeout. See the "Timeouts" section
in the module documentation for more information.
Returning {:ok, state, :hibernate}
is similar to {:ok, state}
except the process is hibernated before entering the loop. See
c:handle_call/3
for more information on hibernation.
Returning {:ok, state, {:continue, continue}}
is similar to
{:ok, state}
except that immediately after entering the loop
the c:handle_continue/2
callback will be invoked with the value
continue
as first argument.
Returning :ignore
will cause start_link/3
to return :ignore
and
the process will exit normally without entering the loop or calling
c:terminate/2
. If used when part of a supervision tree the parent
supervisor will not fail to start nor immediately try to restart the
GenServer
. The remainder of the supervision tree will be started
and so the GenServer
should not be required by other processes.
It can be started later with Supervisor.restart_child/2
as the child
specification is saved in the parent supervisor. The main use cases for
this are:
- The
GenServer
is disabled by configuration but might be enabled later. - An error occurred and it will be handled by a different mechanism than the
Supervisor
. Likely this approach involves callingSupervisor.restart_child/2
after a delay to attempt a restart.
Returning {:stop, reason}
will cause start_link/3
to return
{:error, reason}
and the process to exit with reason reason
without
entering the loop or calling c:terminate/2
.
Callback implementation for GenServer.init/1
.
Creates a new task for a captcha. Expects captcha task type and task options as in Antigate documentation
Returns a UUID string as a task id
Starts the antigate client process
Starts the antigate client linked process