Skip to content

Commit

Permalink
Testing Audio Solver 2/2
Browse files Browse the repository at this point in the history
Tested Audio Solver
Add Set Language
Tested all Examples
  • Loading branch information
MacKey-255 committed Jun 24, 2020
1 parent 71f2b3e commit 635e9b3
Show file tree
Hide file tree
Showing 12 changed files with 39 additions and 43 deletions.
14 changes: 6 additions & 8 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -88,17 +88,16 @@ If you want to use it in your own script
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"}
args = ["--timeout 5"]
options = {"ignoreHTTPSErrors": True, "args": args}
options = {"ignoreHTTPSErrors": True, "args": args} # References: https://miyakogi.github.io/pyppeteer/reference.html
client = Solver(
# With Proxy
pageurl, sitekey, options=options, proxy=proxy, proxy_auth=auth_details
# pageurl, lang='en-US', options=options, proxy=proxy, proxy_auth=auth_details
# Without Proxy
# pageurl, sitekey, options=options
pageurl, lang='en-US', options=options
)
solution = client.loop.run_until_complete(client.start())
Expand All @@ -112,12 +111,11 @@ If you want to use events
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"}
args = ["--timeout 5"]
options = {"ignoreHTTPSErrors": True, "args": args}
options = {"ignoreHTTPSErrors": True, "args": args} # References: https://miyakogi.github.io/pyppeteer/reference.html
class MySolver(Solver):
Expand Down Expand Up @@ -145,9 +143,9 @@ If you want to use events
client = MySolver(
# With Proxy
pageurl, sitekey, options=options, proxy=proxy, proxy_auth=auth_details
# pageurl, lang='en-US', options=options, proxy=proxy, proxy_auth=auth_details
# Without Proxy
# pageurl, sitekey, options=options
pageurl, lang='en-US', options=options
)
client.loop.run_until_complete(client.start())
4 changes: 2 additions & 2 deletions TODO.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ TODO
=======
1. Define parameters that are interchangeable and list them along with explanations to the README.
1. Output version number when script starts
1. Add logging for displaying error messages during runtime, and option to output to file
1. Add logging for displaying error messages during runtime, and option to output to file
1. Ensure script can run auto-piloted, without user interaction and safely integrating with Jetson TX2
1. Build an API for customizing the eye, including but not limited to color, shape, focus. This should have a separate option for developers with flexible yet breakable settings control.
1. Build an API for customizing the eye, including but not limited to color, shape, focus. This should have a separate option for developers with flexible yet breakable settings control.
1. Brainstorm.
23 changes: 10 additions & 13 deletions examples/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -130,10 +130,10 @@ async def cleanup(self):
gathered.cancel()
await gathered
self._loop.call_soon_threadsafe(self._loop.stop)
self.executor.shutdown()
self._executor.shutdown()


async def work(pageurl, sitekey, loop):
async def work(pageurl, loop):
proxy = proxies.get()
proxy_auth = None
if proxy_username and proxy_password:
Expand All @@ -142,7 +142,6 @@ async def work(pageurl, sitekey, loop):
options = {"ignoreHTTPSErrors": True, "args": ["--timeout 5"]}
client = Solver(
pageurl,
sitekey,
loop=loop,
options=options,
proxy=proxy,
Expand All @@ -160,23 +159,21 @@ async def work(pageurl, sitekey, loop):
async def get_solution(request):
params = request.rel_url.query
pageurl = params.get("pageurl")
sitekey = params.get("sitekey")
secret_key = params.get("secret_key")
response = {"error": "error"}
if not pageurl or not sitekey or not secret_key:
if not pageurl or not secret_key:
response = {"error": "invalid request"}
else:
if secret_key != SECRET_KEY:
response = {"error": "unauthorized attempt logged"}
else:
if pageurl and sitekey:
coro = partial(work, pageurl, sitekey)
async with TaskRerun(coro, duration=SOLVE_DURATION) as t:
result = await t.start()
if result:
response = {"solution": result}
else:
response = {"error": "worker timed-out"}
coro = partial(work, pageurl)
async with TaskRerun(coro, duration=SOLVE_DURATION) as t:
result = await t.start()
if result:
response = {"solution": result}
else:
response = {"error": "worker timed-out"}
return web.json_response(response)


Expand Down
8 changes: 4 additions & 4 deletions examples/basic.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,16 @@

from goodbyecaptcha.solver import Solver

if len(sys.argv) == 4:
pageurl, sitekey, proxy = sys.argv[1:]
if len(sys.argv) == 3:
pageurl, proxy = sys.argv[1:]
else:
print('Invalid number of arguments (pageurl, sitekey, proxy)')
print('Invalid number of arguments (pageurl, proxy)')
sys.exit(0)

options = {"ignoreHTTPSErrors": True, "args": ["--timeout 5"]}
if proxy.lower() == "none":
proxy = None
client = Solver(pageurl, sitekey, options=options, proxy=proxy)
client = Solver(pageurl, options=options, proxy=proxy)
try:
result = client.loop.run_until_complete(client.start())
except asyncio.CancelledError:
Expand Down
2 changes: 0 additions & 2 deletions examples/console.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
sort_position = False

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

proxy_source = None # Can be URL or file location
proxy_username, proxy_password = (None, None)
Expand Down Expand Up @@ -94,7 +93,6 @@ async def work(self):
"password": proxy_password}
client = Solver(
pageurl,
sitekey,
options=options,
loop=self.loop,
proxy=proxy,
Expand Down
4 changes: 2 additions & 2 deletions examples/demo.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@
options = {"ignoreHTTPSErrors": True, "args": args} # References: https://miyakogi.github.io/pyppeteer/reference.html
client = Solver(
# With Proxy
# pageurl, sitekey, options=options, proxy=proxy, proxy_auth=auth_details
# pageurl, lang='en-US', options=options, proxy=proxy, proxy_auth=auth_details
# Without Proxy
pageurl, options=options
pageurl, lang='en-US', options=options
)

solution = client.loop.run_until_complete(client.start())
Expand Down
7 changes: 3 additions & 4 deletions examples/events.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
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"}
args = ["--timeout 5"]
options = {"ignoreHTTPSErrors": True, "args": args}
options = {"ignoreHTTPSErrors": True, "args": args} # References: https://miyakogi.github.io/pyppeteer/reference.html


class MySolver(Solver):
Expand Down Expand Up @@ -34,9 +33,9 @@ async def on_finish(self):

client = MySolver(
# With Proxy
pageurl, sitekey, options=options, proxy=proxy, proxy_auth=auth_details
# pageurl, lang='en-US', options=options, proxy=proxy, proxy_auth=auth_details
# Without Proxy
# pageurl, sitekey, options=options
pageurl, lang='en-US', options=options
)

client.loop.run_until_complete(client.start())
2 changes: 1 addition & 1 deletion goodbyecaptcha/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import os.path
import sys

version_info = (2, 4, 0)
version_info = (2, 4, 1)
__version__ = "{}.{}.{}".format(*version_info)

authors = (("MacKey-255", "mackeyfuturo@gmail.com"), ("Michael Mooney", "mikeyy@mikeyy.com"))
Expand Down
4 changes: 2 additions & 2 deletions goodbyecaptcha/audio.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,12 @@


class SolveAudio(Base):
def __init__(self, page, image_frame, loop=None, proxy=None, proxy_auth=None, options=None, **kwargs):
def __init__(self, page, image_frame, loop=None, proxy=None, proxy_auth=None, lang='en-US', options=None, **kwargs):
self.page = page
self.image_frame = image_frame
self.service = self.speech_service.lower()

super(SolveAudio, self).__init__(loop=loop, proxy=proxy, proxy_auth=proxy_auth, options=options, **kwargs)
super(SolveAudio, self).__init__(loop=loop, proxy=proxy, proxy_auth=proxy_auth, language=lang, options=options, **kwargs)

async def solve_by_audio(self):
"""Go through procedures to solve audio"""
Expand Down
5 changes: 4 additions & 1 deletion goodbyecaptcha/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,11 +68,12 @@ class Base:
jquery_data = os.path.join(package_dir, settings["data"]["jquery_js"])
pictures = os.path.join(package_dir, settings['data']['pictures'])

def __init__(self, loop=None, proxy=None, proxy_auth=None, options=None, **kwargs):
def __init__(self, loop=None, proxy=None, proxy_auth=None, options=None, language='en-US', **kwargs):
self.options = merge_dict({} if options is None else options, kwargs)
self.loop = loop or get_event_loop()
self.proxy = proxy
self.proxy_auth = proxy_auth
self.language = language

patch_pyppeteer() # Patch Pyppeter (Fix InvalidStateError and Download Chrome)

Expand Down Expand Up @@ -186,6 +187,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 self.page.setExtraHTTPHeaders({'Accept-Language': self.language}) # Forced set Language
await fuckcaptcha.bypass_detections(self.page) # bypass reCAPTCHA detection in pyppeteer
retry = 3 # Go to Page and Retry 3 times
while True:
Expand Down Expand Up @@ -248,6 +250,7 @@ async def get_new_browser(self):
'--enable-automation',
'--password-store=basic',
'--use-mock-keychain',
'--lang="{0}"'.format(self.language),
'--user-agent="{0}"'.format(agent)]
if self.proxy:
if self.proxy == 'auto':
Expand Down
4 changes: 2 additions & 2 deletions goodbyecaptcha/image.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,11 @@ class SolveImage(Base):
download = None
cur_image_path = None

def __init__(self, page, image_frame, loop=None, proxy=None, proxy_auth=None, options=None, **kwargs):
def __init__(self, page, image_frame, loop=None, proxy=None, proxy_auth=None, options=None, lang='en-US', **kwargs):
self.page = page
self.image_frame = image_frame

super(SolveImage, self).__init__(loop=loop, proxy=proxy, proxy_auth=proxy_auth, options=options, **kwargs)
super(SolveImage, self).__init__(loop=loop, proxy=proxy, proxy_auth=proxy_auth, options=options, language=lang, **kwargs)

async def get_start_data(self):
"""Detect pieces and get title image"""
Expand Down
5 changes: 3 additions & 2 deletions goodbyecaptcha/solver.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,14 @@


class Solver(Base):
def __init__(self, pageurl, loop=None, proxy=None, proxy_auth=None, options=None, **kwargs):
def __init__(self, pageurl, loop=None, proxy=None, proxy_auth=None, options=None, lang='en-US', **kwargs):
self.url = pageurl
self.loop = loop or util.get_event_loop()
self.proxy = proxy
self.proxy_auth = proxy_auth
self.options = merge_dict({} if options is None else options, kwargs)

super(Solver, self).__init__(loop=loop, proxy=proxy, proxy_auth=proxy_auth, options=options)
super(Solver, self).__init__(loop=loop, proxy=proxy, proxy_auth=proxy_auth, language=lang, options=options)

async def start(self):
"""Begin solving"""
Expand Down Expand Up @@ -68,6 +68,7 @@ async def start(self):
if self.browser:
await self.browser.close()
self.browser = None
await self.cleanup()
# Return result
if isinstance(result, dict):
status = result['status'].capitalize()
Expand Down

0 comments on commit 635e9b3

Please sign in to comment.