Skip to content

Commit

Permalink
Testing Audio Solver 1/2
Browse files Browse the repository at this point in the history
Add Incognito Page
Remove Site-Key (Not use for now)
Adjust logging in Base Project
Add FakeBrowser (Bypass Bot detections)
Testing Audio method 1/2 ( Try Later :V )
Add Try Catch to Try Again Message
  • Loading branch information
MacKey-255 committed Jun 15, 2020
1 parent 685b081 commit 71f2b3e
Show file tree
Hide file tree
Showing 5 changed files with 66 additions and 36 deletions.
3 changes: 1 addition & 2 deletions examples/demo.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
from goodbyecaptcha.solver import Solver

pageurl = "https://www.google.com/recaptcha/api2/demo"
sitekey = "6Le-wvkSAAAAAPBMRTvw0Q4Muexq9bi0DJwx_mJ-"

proxy = "127.0.0.1:1000"
auth_details = {"username": "user", "password": "pass"}
Expand All @@ -11,7 +10,7 @@
# With Proxy
# pageurl, sitekey, options=options, proxy=proxy, proxy_auth=auth_details
# Without Proxy
pageurl, sitekey, options=options
pageurl, options=options
)

solution = client.loop.run_until_complete(client.start())
Expand Down
25 changes: 21 additions & 4 deletions goodbyecaptcha/audio.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,22 +30,28 @@ async def solve_by_audio(self):
self.log('Wait for Audio Buttom ...')
await self.loop.create_task(self.wait_for_audio_button())
self.log('Click random images ...')
for _ in range(int(random.uniform(3, 6))):
for _ in range(int(random.uniform(2, 5))):
await asyncio.sleep(random.uniform(0.2, 0.5)) # Wait 2-5 ms
await self.click_tile() # Click random images
await asyncio.sleep(random.uniform(1, 2)) # Wait 1-2 seg
await asyncio.sleep(random.uniform(1.5, 3.5)) # Wait 1-3 seg
await self.click_verify() # Click Verify button
self.log('Clicking Audio Buttom ...')
await asyncio.sleep(random.uniform(1, 3)) # Wait 1-3 sec
result = await self.click_audio_button() # Click audio button
if isinstance(result, dict):
if result["status"] == "detected": # Verify if detected
return result
# Start process
await self.get_frames()
answer = None
for _ in range(2):
# Start url for ...
start_url = self.page.url
for _ in range(8):
try:
answer = await self.loop.create_task(self.get_audio_response())
temp = self.service
self.service = self.speech_secondary_service.lower() # Secondary Recognition
self.speech_secondary_service = temp
except TryAgain:
self.log('Try again Error!')
except DownloadError:
Expand All @@ -60,10 +66,15 @@ async def solve_by_audio(self):
continue
await self.type_audio_response(answer)
await self.click_verify()
await asyncio.sleep(2.0) # Wait 2seg
if start_url != self.page.url:
return {'status': 'success'}
try:
result = await self.check_detection(self.animation_timeout)
except TryAgain:
continue
except SafePassage:
continue
except Exception:
raise ResolveMoreLater('You must solve more captchas.')
else:
Expand Down Expand Up @@ -143,8 +154,14 @@ async def get_audio_response(self):

async def type_audio_response(self, answer):
"""Enter answer text on input"""
self.log("Waiting audio response")
response_input = None
for i in range(4):
response_input = await self.image_frame.J("#audio-response")
if response_input:
break
await asyncio.sleep(2.0) # Wait 2seg
self.log("Typing audio response")
response_input = await self.image_frame.J("#audio-response")
length = random.uniform(70, 130)
try:
await self.loop.create_task(response_input.type(text=answer, delay=length))
Expand Down
24 changes: 16 additions & 8 deletions goodbyecaptcha/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@
import traceback
from shutil import copyfile

import fuckcaptcha as fucking
import fuckcaptcha
from fake_useragent import UserAgent
from pyppeteer.errors import TimeoutError, PageError, PyppeteerError, NetworkError
from pyppeteer.launcher import Launcher
from pyppeteer.util import merge_dict
Expand All @@ -20,7 +21,8 @@
from goodbyecaptcha.exceptions import SafePassage, TryAgain
from goodbyecaptcha.util import patch_pyppeteer, get_event_loop, load_file, get_random_proxy

logging.basicConfig(format="%(asctime)s %(message)s")
if len(logging.root.handlers) == 0:
logging.basicConfig(format="%(asctime)s %(message)s")

try:
import yaml
Expand All @@ -44,6 +46,7 @@ class Base:
"""Base control Pyppeteer"""

browser = None
context = None
launcher = None
page = None
page_index = 0
Expand Down Expand Up @@ -168,7 +171,7 @@ async def open_page(self, url, cookies=None, new_page=True):
"""Create new page"""
if new_page:
self.page_index += 1 # Add Actual Index
self.page = await self.browser.newPage()
self.page = await self.context.newPage()
if self.proxy_auth and self.proxy:
await self.page.authenticate(self.proxy_auth)
self.log(f"Open page with proxy {self.proxy}")
Expand All @@ -183,7 +186,7 @@ async def goto(self, url):
"""Navigate to address"""
jquery_js = await load_file(self.jquery_data)
await self.page.evaluateOnNewDocument("() => {\n%s}" % jquery_js) # Inject JQuery
await fucking.bypass_detections(self.page) # bypass reCAPTCHA detection in pyppeteer
await fuckcaptcha.bypass_detections(self.page) # bypass reCAPTCHA detection in pyppeteer
retry = 3 # Go to Page and Retry 3 times
while True:
try:
Expand Down Expand Up @@ -216,6 +219,7 @@ async def goto(self, url):

async def get_new_browser(self):
"""Get a new browser, set proxy and arguments"""
agent = UserAgent().random
args = [
'--cryptauth-http-host ""',
'--disable-accelerated-2d-canvas',
Expand All @@ -240,11 +244,11 @@ async def get_new_browser(self):
'--metrics-recording-only',
'--no-first-run',
'--safebrowsing-disable-auto-update',
'--no-sandbox',
# Automation arguments
'--enable-automation',
'--password-store=basic',
'--use-mock-keychain']
'--use-mock-keychain',
'--user-agent="{0}"'.format(agent)]
if self.proxy:
if self.proxy == 'auto':
self.proxy = get_random_proxy()
Expand All @@ -256,9 +260,13 @@ async def get_new_browser(self):
"args": args,
# Silence Pyppeteer logs
"logLevel": "CRITICAL"})
self.launcher = Launcher(self.options)
self.launcher = Launcher(self.options, handleSIGINT=False, handleSIGTERM=False, handleSIGHUP=False)
browser = await self.launcher.launch()
self.page = (await browser.pages())[0] # Set first page
# Set user-agent to all pages
pages = await browser.pages()
for page in pages:
await page.setUserAgent(agent)
self.page = pages[0] # Set first page
return browser

async def page_switch(self, index=0):
Expand Down
39 changes: 23 additions & 16 deletions goodbyecaptcha/solver.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,8 @@


class Solver(Base):
def __init__(self, pageurl, sitekey, loop=None, proxy=None, proxy_auth=None, options=None, **kwargs):
def __init__(self, pageurl, loop=None, proxy=None, proxy_auth=None, options=None, **kwargs):
self.url = pageurl
self.sitekey = sitekey
self.loop = loop or util.get_event_loop()
self.proxy = proxy
self.proxy_auth = proxy_auth
Expand All @@ -35,6 +34,7 @@ async def start(self):
result = None
try:
self.browser = await self.get_new_browser()
self.context = await self.browser.createIncognitoBrowserContext()
await self.open_page(self.url, new_page=False) # Use first page
result = await self.solve()
except NetworkError as ex:
Expand All @@ -61,6 +61,14 @@ async def start(self):
traceback.print_exc(file=sys.stdout)
print(f"Error unexpected: {ex}")
finally:
# Close all Context and Browser
if self.context:
await self.context.close()
self.context = None
if self.browser:
await self.browser.close()
self.browser = None
# Return result
if isinstance(result, dict):
status = result['status'].capitalize()
print(f"Result: {status}")
Expand All @@ -74,7 +82,7 @@ async def solve(self):
try:
await self.get_frames()
except Exception:
raise IframeError("Problem locating reCAPTCHA frames")
return await self.get_code({'status': 'success'})
self.log('Wait for CheckBox ...')
await self.loop.create_task(self.wait_for_checkbox())
self.log('Click CheckBox ...')
Expand All @@ -85,14 +93,7 @@ async def solve(self):
except SafePassage:
return await self._solve() # Start to solver
else:
if result["status"] == "success":
"""Send Data to Buttom"""
code = await self.g_recaptcha_response()
if code:
result["code"] = code
return result
else:
return result
return self.get_code(result)

async def _solve(self):
"""Select method solver"""
Expand All @@ -108,14 +109,20 @@ async def _solve(self):
proxy_auth=self.proxy_auth, options=self.options)
solve = self.audio.solve_by_audio

result = await self.loop.create_task(solve())
if result["status"] == "success":
try:
result = await self.loop.create_task(solve())
return await self.get_code(result)
except PyppeteerError as ex:
raise TryAgain(ex)

async def get_code(self, result_status):
if result_status["status"] == "success":
code = await self.g_recaptcha_response()
if code:
result["code"] = code
return result
result_status["code"] = code
return result_status
else:
return result
return result_status

async def wait_for_checkbox(self):
"""Wait for checkbox to appear."""
Expand Down
11 changes: 5 additions & 6 deletions goodbyecaptcha/speech.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
""" Speech module. Text-to-speech classes - Sphinx, Google, WitAI, Amazon, and Azure. """
import asyncio
import json
import logging
import os
import re
import struct
Expand Down Expand Up @@ -71,13 +72,12 @@ async def get_text(self, mp3_filename):
# recognize speech using Google Speech Recognition
audio_output = None
try:
print('recognize speech using Google Speech Recognition')
audio_output = recognizer.recognize_google(audio)
print("Google Speech Recognition: " + audio_output)
except sr.UnknownValueError:
print("Google Speech Recognition could not understand audio")
logging.warning("Google Speech Recognition could not understand audio")
except sr.RequestError as e:
print("Could not request results from Google Speech Recognition service; {0}".format(e))
logging.warning("Could not request results from Google Speech Recognition service; {0}".format(e))
return audio_output


Expand All @@ -94,14 +94,13 @@ async def get_text(self, mp3_filename):
# recognize speech using WIT.AI Recognition
audio_output = None
try:
print('recognize speech using Wit.AI Recognition')
# Llamamos al metodo de reconocimiento por wit y le pasamos el audio, y la key
audio_output = recognizer.recognize_wit(audio, key=self.API_KEY)
print("Wit.AI Recognition: " + audio_output)
except sr.UnknownValueError: # Definimos excepciones que se puedan presentar
print("Wit.ai could not understand audio")
logging.warning("Wit.ai could not understand audio")
except sr.RequestError as e:
print("Could not request results from Wit.ia; {0}".format(e))
logging.warning("Could not request results from Wit.ia; {0}".format(e))

return audio_output

Expand Down

0 comments on commit 71f2b3e

Please sign in to comment.