Skip to content

Commit f9f3bcd

Browse files
add Friendly Captcha
1 parent 12c9088 commit f9f3bcd

File tree

4 files changed

+133
-9
lines changed

4 files changed

+133
-9
lines changed

package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,8 @@
3737
"DataDome CAPTCHA",
3838
"CyberSiARA",
3939
"MTCaptcha",
40-
"Bounding Box Method"
40+
"Bounding Box Method",
41+
"Friendly Captcha"
4142
],
4243
"scripts": {
4344
"go": "tsc && node ./dist/index.js",

src/structs/2captcha.ts

Lines changed: 109 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -209,6 +209,14 @@ export interface paramsMTCaptcha {
209209
proxytype?: string,
210210
}
211211

212+
export interface friendlyCaptcha {
213+
pageurl: string,
214+
sitekey: string,
215+
pingback?: string,
216+
proxy?: string,
217+
proxytype?: string,
218+
}
219+
212220
export interface paramsBoundingBox {
213221
image: string,
214222
textinstructions?: string,
@@ -872,7 +880,7 @@ export class Solver {
872880
* [Read more about Cloudflare Turnstile captcha](https://2captcha.com/2captcha-api#turnstile).
873881
*
874882
* @param {{ pageurl, sitekey, action, data, pingback, proxy, proxytype}} params The `сloudflareTurnstile` method takes arguments as an object. Thus, the `pageurl`, `sitekey` fields in the passed object are mandatory. [Open example](https://github.com/dzmitry-duboyski/2captcha-ts/blob/master/tests/turnstile.js)
875-
* @param {string} params.pageurl Full `URL of the page where you see the captcha.
883+
* @param {string} params.pageurl Full `URL` of the page where you see the captcha.
876884
* @param {string} params.sitekey Is a value of `sitekey` parameter in the page source.
877885
* @param {string} params.action Value of optional `action` parameter you found on page.
878886
* @param {string} params.data Value of optional `data` parameter you found on page.
@@ -991,7 +999,7 @@ export class Solver {
991999
* ### Solves Capy Puzzle captcha
9921000
*
9931001
* @param {{ pageurl, captchakey, api_server, version, pingback, proxy, proxytype}} params Parameters Capy Puzzle Captcha as an object.
994-
* @param {string} params.pageurl Full `URL of the page where you see the captcha.
1002+
* @param {string} params.pageurl Full `URL`of the page where you see the captcha.
9951003
* @param {string} params.captchakey Value of `captchakey` parameter you found on page.
9961004
* @param {string} params.api_server The domain part of script URL you found on page. Default value: `https://jp.api.capy.me/`.
9971005
* @param {string} params.version The version of captcha task: `puzzle` (assemble a puzzle) or `avatar` (drag an object)..
@@ -1041,7 +1049,7 @@ export class Solver {
10411049
* ### Solves DataDome captcha
10421050
*
10431051
* @param {{ pageurl, captcha_url, userAgent, pingback, proxy, proxytype}} params Parameters DataDome Captcha as an object.
1044-
* @param {string} params.pageurl Full `URL of the page where you see the captcha.
1052+
* @param {string} params.pageurl Full `URL` of the page where you see the captcha.
10451053
* @param {string} params.captcha_url The value of the `src` parameter for the `iframe` element containing the captcha on the page.
10461054
* @param {string} params.userAgent ser-Agent of your MODERN browser
10471055
* @param {string} params.pingback URL for pingback (callback) response that will be sent when captcha is solved. URL should be registered on the server. [More info here](https://2captcha.com/2captcha-api#pingback).
@@ -1093,7 +1101,7 @@ export class Solver {
10931101
* ### Solves CyberSiARA captcha
10941102
*
10951103
* @param {{ pageurl, master_url_id, userAgent, pingback, proxy, proxytype}} params Parameters CyberSiARA Captcha as an object.
1096-
* @param {string} params.pageurl Full `URL of the page where you see the captcha.
1104+
* @param {string} params.pageurl Full `URL` of the page where you see the captcha.
10971105
* @param {string} params.master_url_id The value of `MasterUrlId` parameter obtained from the request to the endpoint `API/CyberSiara/GetCyberSiara`.
10981106
* @param {string} params.userAgent ser-Agent of your MODERN browser
10991107
* @param {string} params.pingback URL for pingback (callback) response that will be sent when captcha is solved. URL should be registered on the server. [More info here](https://2captcha.com/2captcha-api#pingback).
@@ -1143,7 +1151,7 @@ public async cyberSiARA(params: paramsCyberSiARA): Promise<CaptchaAnswer> {
11431151
* ### Solves MTCaptcha
11441152
*
11451153
* @param {{ pageurl, sitekey, userAgent, pingback, proxy, proxytype}} params Parameters MTCaptcha as an object.
1146-
* @param {string} params.pageurl Full `URL of the page where you see the captcha.
1154+
* @param {string} params.pageurl Full `URL` of the page where you see the captcha.
11471155
* @param {string} params.sitekey TThe value of `sitekey` parameter found on the page.
11481156
* @param {string} params.pingback URL for pingback (callback) response that will be sent when captcha is solved. URL should be registered on the server. [More info here](https://2captcha.com/2captcha-api#pingback).
11491157
* @param {string} params.proxy Format: `login:password@123.123.123.123:3128` You can find more info about proxies [here](https://2captcha.com/2captcha-api#proxies).
@@ -1187,6 +1195,102 @@ public async mtCaptcha(params: paramsMTCaptcha): Promise<CaptchaAnswer> {
11871195
}
11881196
}
11891197

1198+
/**
1199+
* ### Solves Cutcaptcha
1200+
*
1201+
* @param {{ pageurl, sitekey, userAgent, pingback, proxy, proxytype}} params Parameters MTCaptcha as an object.
1202+
* @param {string} params.pageurl Full `URL` of the page where you see the captcha.
1203+
* @param {string} params.sitekey TThe value of `sitekey` parameter found on the page.
1204+
* @param {string} params.pingback URL for pingback (callback) response that will be sent when captcha is solved. URL should be registered on the server. [More info here](https://2captcha.com/2captcha-api#pingback).
1205+
* @param {string} params.proxy Format: `login:password@123.123.123.123:3128` You can find more info about proxies [here](https://2captcha.com/2captcha-api#proxies).
1206+
* @param {string} params.proxytype Type of your proxy: `HTTP`, `HTTPS`, `SOCKS4`, `SOCKS5`.
1207+
*
1208+
* @example
1209+
* solver.cutCaptcha({
1210+
* pageurl: "https://service.mtcaptcha.com/mtcv1/demo/index.html",
1211+
* sitekey: "MTPublic-DemoKey9M"
1212+
* })
1213+
* .then((res) => {
1214+
* console.log(res);
1215+
* })
1216+
* .catch((err) => {
1217+
* console.log(err);
1218+
* })
1219+
*/
1220+
public async cutCaptcha(params: paramsMTCaptcha): Promise<CaptchaAnswer> {
1221+
checkCaptchaParams(params, "mt_captcha")
1222+
1223+
const payload = {
1224+
...params,
1225+
method: "mt_captcha",
1226+
...this.defaultPayload,
1227+
}
1228+
1229+
const response = await fetch(this.in + utils.objectToURI(payload))
1230+
const result = await response.text()
1231+
1232+
let data;
1233+
try {
1234+
data = JSON.parse(result)
1235+
} catch {
1236+
throw new APIError(result)
1237+
}
1238+
1239+
if (data.status == 1) {
1240+
return this.pollResponse(data.request)
1241+
} else {
1242+
throw new APIError(data.request)
1243+
}
1244+
}
1245+
1246+
/**
1247+
* ### Solves Friendly Captcha
1248+
*
1249+
* @param {{ pageurl, sitekey, pingback, proxy, proxytype}} params Parameters Friendly Captcha as an object.
1250+
* @param {string} params.pageurl Full `URL` of the page where you see the captcha.
1251+
* @param {string} params.sitekey The value of `data-apikey` or `data-sitekey` parameter found on the page.
1252+
* @param {string} params.pingback URL for pingback (callback) response that will be sent when captcha is solved. URL should be registered on the server. [More info here](https://2captcha.com/2captcha-api#pingback).
1253+
* @param {string} params.proxy Format: `login:password@123.123.123.123:3128` You can find more info about proxies [here](https://2captcha.com/2captcha-api#proxies).
1254+
* @param {string} params.proxytype Type of your proxy: `HTTP`, `HTTPS`, `SOCKS4`, `SOCKS5`.
1255+
*
1256+
* @example
1257+
* solver.friendlyCaptcha({
1258+
* pageurl: "https://geizhals.de/?liftban=1&from=/455973138?fsean=5901747021356",
1259+
* sitekey: "FCMST5VUMCBOCGQ9"
1260+
* })
1261+
* .then((res) => {
1262+
* console.log(res);
1263+
* })
1264+
* .catch((err) => {
1265+
* console.log(err);
1266+
* })
1267+
*/
1268+
public async friendlyCaptcha(params: friendlyCaptcha): Promise<CaptchaAnswer> {
1269+
checkCaptchaParams(params, "friendly_captcha")
1270+
1271+
const payload = {
1272+
...params,
1273+
method: "friendly_captcha",
1274+
...this.defaultPayload,
1275+
}
1276+
1277+
const response = await fetch(this.in + utils.objectToURI(payload))
1278+
const result = await response.text()
1279+
1280+
let data;
1281+
try {
1282+
data = JSON.parse(result)
1283+
} catch {
1284+
throw new APIError(result)
1285+
}
1286+
1287+
if (data.status == 1) {
1288+
return this.pollResponse(data.request)
1289+
} else {
1290+
throw new APIError(data.request)
1291+
}
1292+
}
1293+
11901294
/**
11911295
* ### Bounding Box Method
11921296
*

src/utils/checkCaptchaParams.ts

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
// Captcha methods for which parameter checking is available
22
const supportedMethods = ["userrecaptcha", "hcaptcha", "geetest", "geetest_v4","yandex","funcaptcha","lemin","amazon_waf",
3-
"turnstile", "base64", "capy","datadome", "cybersiara", "mt_captcha", "bounding_box"]
3+
"turnstile", "base64", "capy","datadome", "cybersiara", "mt_captcha", "bounding_box", 'friendly_captcha']
44

55
// Names of required fields that must be contained in the parameters captcha
66
const recaptchaRequiredFields = ['pageurl','googlekey']
@@ -17,8 +17,9 @@ const base64RequiredFields = ['body']
1717
const capyPuzzleRequiredFields = ['captchakey']
1818
const dataDomeRequiredFields = ['pageurl', 'captcha_url', 'userAgent', 'proxy', 'proxytype']
1919
const сyberSiARARequiredFields = ['pageurl', 'master_url_id', 'userAgent']
20-
const mtСaptchaRequiredFields = ['pageurl', 'sitekey']
21-
const boundingBoxRequiredFields = ['image'] // and textinstructions or imginstructions
20+
const mtСaptchaRequiredFields = ['pageurl', 'sitekey']
21+
const boundingBoxRequiredFields = ['image'] // and textinstructions or imginstructions
22+
const friendlyCaptchaFields = ['pageurl','sitekey']
2223

2324
/**
2425
* Getting required arguments for a captcha.
@@ -75,6 +76,9 @@ const getRequiredFildsArr = (method: string):Array<string> => {
7576
case "bounding_box":
7677
requiredFieldsArr = boundingBoxRequiredFields
7778
break;
79+
case "friendly_captcha":
80+
requiredFieldsArr = friendlyCaptchaFields
81+
break;
7882
}
7983
return requiredFieldsArr
8084
}

tests/friendlyCaptcha.js

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
const Captcha = require("../dist/index.js");
2+
require('dotenv').config();
3+
const APIKEY = process.env.APIKEY
4+
const solver = new Captcha.Solver(APIKEY);
5+
6+
solver.friendlyCaptcha({
7+
pageurl: "https://geizhals.de/?liftban=1&from=/455973138?fsean=5901747021356",
8+
sitekey: "FCMST5VUMCBOCGQ9"
9+
})
10+
.then((res) => {
11+
console.log(res);
12+
})
13+
.catch((err) => {
14+
console.log(err);
15+
})

0 commit comments

Comments
 (0)