You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

60 lines
1.9 KiB
JavaScript

// IMPORTANT NOTE: get a captcha key and refill your account on 2captcha.com, then place the key on line 6
const fs = require('fs');
const path = require('path');
const Captcha = require("2captcha")
const solver = new Captcha.Solver("YOUR_2CAPTCHA_KEY_HERE")
const sharp = require('sharp');
const directories = [];
const completedImages = [];
const allFiles = fs.readdirSync('raw');
function process(path) {
return new Promise(async (resolve) => {
const imageBuf = await sharp(`raw/${path}/resultraw.png`)
.resize({
width: 550,
height: 256
})
.toBuffer();
const base64string = `data:image/png;base64,${imageBuf.toString('base64')}`
solver.imageCaptcha(base64string)
.then((res) => {
resolve(res.data);
})
})
}
async function main() {
for (let i = 0; i < allFiles.length; i++) {
if (!allFiles[i].split('data')[0]) {
const file = allFiles[i];
const filepath = path.join(__dirname, 'raw', file, 'resultraw.png')
const fileExists = fs.existsSync(filepath);
if (fileExists) {
directories.push(file);
} else {
console.log('Skipped directory ' + file + ' for reason: invalid format');
console.log('Cleaning dataset of this invalid entry!');
fs.rmSync(path.join(__dirname, 'raw', file), { recursive: true, force: true })
}
}
};
for(let i = 0; i < directories.length; i++) {
const solved = await process(directories[i]);
console.log('Solved captcha ' + i + ' with result ' + solved)
completedImages.push({
uuid: directories[i],
solution: solved
});
if(fs.existsSync('data.json')) {
fs.unlinkSync('data.json')
}
fs.writeFileSync('data.json', JSON.stringify(completedImages))
}
};
main()