summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGravatar Stefano <l.stickell@yahoo.it> 2014-04-10 14:56:25 +0200
committerGravatar Stefano <l.stickell@yahoo.it> 2014-04-21 17:13:46 +0200
commit8e94b33790156ed3749c383b8c64b10c1bfcd6c4 (patch)
treed852a5b0c732a62492d42ce5df36f37e5ef0d1b1
parentNew hoster: UpstoreNet (diff)
downloadpyload-8e94b33790156ed3749c383b8c64b10c1bfcd6c4.tar.xz
Improved ReCaptcha class:
Ability to detect public key and use it for challenge requests. + cosmetics (cherry picked from commit 806fca3ffbe17b9b23b962c484e95c0955d48fd9) Conflicts: pyload/plugins/internal/CaptchaService.py
-rw-r--r--pyload/plugins/internal/CaptchaService.py35
1 files changed, 29 insertions, 6 deletions
diff --git a/pyload/plugins/internal/CaptchaService.py b/pyload/plugins/internal/CaptchaService.py
index d4d0c9979..bb5a1370c 100644
--- a/pyload/plugins/internal/CaptchaService.py
+++ b/pyload/plugins/internal/CaptchaService.py
@@ -21,18 +21,38 @@ import re
class CaptchaService():
- __version__ = "0.02"
+ __version__ = "0.03"
def __init__(self, plugin):
self.plugin = plugin
class ReCaptcha():
+ RECAPTCHA_KEY_PATTERN = r"https?://(?:www\.)?google\.com/recaptcha/api/challenge\?k=(?P<key>\w+)"
+ RECAPTCHA_KEY_AJAX_PATTERN = r"Recaptcha\.create\s*\(\s*[\"'](?P<key>\w+)[\"']\s*,"
+
+ recaptcha_key = None
+
def __init__(self, plugin):
self.plugin = plugin
- def challenge(self, id):
- js = self.plugin.req.load("http://www.google.com/recaptcha/api/challenge", get={"k": id}, cookies=True)
+ def detect_key(self, html):
+ m = re.search(self.RECAPTCHA_KEY_PATTERN, html)
+ if not m:
+ m = re.search(self.RECAPTCHA_KEY_AJAX_PATTERN, html)
+ if m:
+ self.recaptcha_key = m.group('key')
+ return self.recaptcha_key
+ else:
+ return None
+
+ def challenge(self, key=None):
+ if not key and self.recaptcha_key:
+ key = self.recaptcha_key
+ elif not (key or self.recaptcha_key):
+ raise TypeError("ReCaptcha key not found")
+
+ js = self.plugin.req.load("http://www.google.com/recaptcha/api/challenge", get={"k": key}, cookies=True)
try:
challenge = re.search("challenge : '(.*?)',", js).group(1)
@@ -44,7 +64,8 @@ class ReCaptcha():
return challenge, result
def result(self, server, challenge):
- return self.plugin.decryptCaptcha("%simage" % server, get={"c": challenge}, cookies=True, forceUser=True, imgtype="jpg")
+ return self.plugin.decryptCaptcha("%simage" % server, get={"c": challenge},
+ cookies=True, forceUser=True, imgtype="jpg")
class AdsCaptcha(CaptchaService):
@@ -61,7 +82,8 @@ class AdsCaptcha(CaptchaService):
return challenge, result
def result(self, server, challenge):
- return self.plugin.decryptCaptcha("%sChallenge.aspx" % server, get={"cid": challenge, "dummy": random()}, cookies=True, imgtype="jpg")
+ return self.plugin.decryptCaptcha("%sChallenge.aspx" % server, get={"cid": challenge, "dummy": random()},
+ cookies=True, imgtype="jpg")
class SolveMedia(CaptchaService):
@@ -69,7 +91,8 @@ class SolveMedia(CaptchaService):
def challenge(self, src):
html = self.plugin.req.load("http://api.solvemedia.com/papi/challenge.noscript?k=%s" % src, cookies=True)
try:
- challenge = re.search(r'<input type=hidden name="adcopy_challenge" id="adcopy_challenge" value="([^"]+)">', html).group(1)
+ challenge = re.search(r'<input type=hidden name="adcopy_challenge" id="adcopy_challenge" value="([^"]+)">',
+ html).group(1)
except:
self.plugin.fail("solvmedia error")
result = self.result(challenge)