示例#1
0
文件: run.py 项目: ztacesa/uncaptcha2
def runCap():
    try:
        print("Removing old files...")
        os.system(
            'rm ./audio.wav 2>/dev/null'
        )  # These files may be left over from previous runs, and should be removed just in case.
        os.system('rm ' + DOWNLOAD_LOCATION + 'audio.mp3 2>/dev/null')
        # First, download the file
        downloadResult = downloadCaptcha()
        if downloadResult == 2:
            pyautogui.moveTo(CLOSE_LOCATION)
            pyautogui.click()
            return 2
        elif downloadResult == -1:
            pyautogui.moveTo(CLOSE_LOCATION)
            pyautogui.click()
            return 3

        # Convert the file to a format our APIs will understand
        print("Converting Captcha...")
        os.system("echo 'y' | ffmpeg -i " + DOWNLOAD_LOCATION +
                  "audio.mp3 ./audio.wav 2>/dev/null")
        with sr.AudioFile('./audio.wav') as source:
            audio = r.record(source)

        print("Submitting To Speech to Text:")
        determined = google(
            audio)  # Instead of google, you can use ibm or bing here
        print(determined)

        print("Inputting Answer")
        # Input the captcha
        pyautogui.moveTo(FINAL_COORDS)
        pyautogui.click()
        time.sleep(.5)
        pyautogui.typewrite(determined, interval=.05)
        time.sleep(.5)
        pyautogui.moveTo(VERIFY_COORDS)
        pyautogui.click()

        print("Verifying Answer")
        time.sleep(2)
        # Check that the captcha is completed
        result = checkCaptcha()
        return result
    except Exception as e:
        pyautogui.moveTo(CLOSE_LOCATION)
        pyautogui.click()
        return 3
示例#2
0
def runCap():
    try:
        log("Removing old audio files...")
        # These files may be left over from previous runs, and should be removed just in case.
        os.system('rm ./audio.wav 2>/dev/null')
        os.system('rm ./audioCurl.mp3 2>/dev/null')

        if USE_CHROME_DEBUG_BROWSER:
            log("Opening Chrome in Debug Mode")
            launchBrowserInDebugMode()
        else:
            log("Starting Chrome")
            command = CHROME_LAUNCH_COMMAND
            if USE_INCOGNITO:
                command += ' --incognito'
            os.system(command + ' &')

        # First, download the file
        downloadResult = downloadCaptcha()
        if downloadResult != 0:
            return downloadResult

        if OPEN_CAPTCHA_ONLY:
            return 3

        # Convert the file to a format our APIs will understand
        log("Converting Captcha to .wav format...")
        os.system("echo 'y' | ffmpeg -i audioCurl.mp3 ./audio.wav 2>/dev/null")

        # play the sound
        os.system("aplay audio.wav 2>/dev/null &")

        with sr.AudioFile('./audio.wav') as source:
            audio = r.record(source)

        log("Submitting To Speech to Text API...")
        determined = google(
            audio)  # Instead of google, you can use ibm or bing here

        log('Google speech to text API: "{}"'.format(determined),
            bcolors.OKBLUE)

        log("Inputting Answer into Captcha")
        # Input the captcha
        humanMove(CAPTCHA_INPUT_COORDS, steps=2)
        pyautogui.typewrite(determined, interval=.025)

        # click the check box
        humanMove(CAPTCHA_CHECK_BOX_COORDS, steps=2)

        # if Google gives us half correct solution: "Multiple correct solutions required - please solve more."
        log("Verifying Answer")
        time.sleep(1)
        # Check that the captcha is completed
        result = checkCaptcha()
        if result:
            log('Captcha was correct!', bcolors.OKGREEN)
        return result
    except Exception as e:
        log('Error: {}'.format(str(e)))
        return 3