Code Monkey home page Code Monkey logo

Comments (1)

khoben avatar khoben commented on June 5, 2024

Temporary hack:

class Base64String:
    """String mimics to bytes decoding"""

    def __init__(self, base64: str) -> None:
        self.base64 = base64

    def decode(self, *args, **kwargs) -> str:
        return self.base64


@dataclass
class ImageBase64StringCaptcha(ImageCaptcha):
    """ImageCaptcha: pass base64 string image directly"""

    image: str

    def __post_init__(self):
        pass

    def get_image_bytes(self) -> bytes:
        return base64.b64decode(self.image[self.image.find(",") + 1 :])

    def get_image_base64(self) -> Base64String:
        return Base64String(self.image)

    def get_image_type(self) -> str:
        return "base64"

    @classmethod
    def get_type(cls) -> CaptchaType:
        """Return CaptchaType"""

        return ImageCaptcha.get_type()

    @classmethod
    def get_solution_class(cls) -> BaseCaptchaSolution:
        """Return appropriate solution class"""

        return ImageCaptcha.get_solution_class()
async def solve_image_base64_captcha(
    service: AsyncCaptchaSolver, image: str, **kwargs
) -> AsyncSolvedCaptcha:
    r"""Solves image CAPTCHA.

    :param service: AsyncCaptchaSolver
    :param image: str object containing base64 image with CAPTCHA
    :param char_type: (optional) Character type.
    :param is_phrase: (optional) Boolean. True if CAPTCHA contains more than one word.
    :param is_case_sensitive: (optional) Boolean.
    :param is_math: (optional) Boolean. True if CAPTCHA requires calculation.
    :param min_len: (optional) Integer. Minimum length of the CAPTCHA's text.
    :param max_len: (optional) Integer. Maximum length of the CAPTCHA's text.
    :param alphabet: (optional) Alphabet used in the CAPTCHA.
    :param language: (optional) Language.
    :param comment: (optional) String. Text instructions for worker.
    :return: :class:`AsyncSolvedCaptcha <AsyncSolvedCaptcha>` object
    :rtype: unicaps.AsyncSolvedCaptcha
    """

    return await service._solve_captcha_async(
        ImageBase64StringCaptcha, image, **kwargs
    )

async def main():
    async with AsyncCaptchaSolver(CaptchaSolvingService.TWOCAPTCHA, API_KEY) as solver:
        solved = await solve_image_base64_captcha(
            solver,
            BASE64_STRING_IMAGE,
            is_phrase=False,
            is_case_sensitive=True
        )
        print(f'CAPTCHA text: {solved.solution.text}')
        await solved.report_good()

if __name__ == '__main__':
    asyncio.run(main())

from unicaps.

Related Issues (13)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.