summaryrefslogtreecommitdiffstats
path: root/pyload/plugins/captcha/AdsCaptcha.py
diff options
context:
space:
mode:
Diffstat (limited to 'pyload/plugins/captcha/AdsCaptcha.py')
-rw-r--r--pyload/plugins/captcha/AdsCaptcha.py52
1 files changed, 29 insertions, 23 deletions
diff --git a/pyload/plugins/captcha/AdsCaptcha.py b/pyload/plugins/captcha/AdsCaptcha.py
index fe8fec29b..3f14ebdc0 100644
--- a/pyload/plugins/captcha/AdsCaptcha.py
+++ b/pyload/plugins/captcha/AdsCaptcha.py
@@ -10,15 +10,15 @@ from pyload.plugins.internal.Captcha import Captcha
class AdsCaptcha(Captcha):
__name__ = "AdsCaptcha"
__type__ = "captcha"
- __version__ = "0.05"
+ __version__ = "0.06"
__description__ = """AdsCaptcha captcha service plugin"""
__license__ = "GPLv3"
__authors__ = [("pyLoad Team", "admin@pyload.org")]
- ID_PATTERN = r'api\.adscaptcha\.com/Get\.aspx\?[^"\']*CaptchaId=(?P<ID>\d+)'
- KEY_PATTERN = r'api\.adscaptcha\.com/Get\.aspx\?[^"\']*PublicKey=(?P<KEY>[\w-]+)'
+ CAPTCHAID_PATTERN = r'api\.adscaptcha\.com/Get\.aspx\?[^"\']*CaptchaId=(\d+)'
+ PUBLICKEY_PATTERN = r'api\.adscaptcha\.com/Get\.aspx\?[^"\']*PublicKey=([\w-]+)'
def detect_key(self, html=None):
@@ -27,45 +27,51 @@ class AdsCaptcha(Captcha):
html = self.plugin.html
else:
errmsg = _("AdsCaptcha html not found")
- self.plugin.error(errmsg)
+ self.plugin.fail(errmsg)
raise TypeError(errmsg)
- m = re.search(self.ID_PATTERN, html)
- n = re.search(self.KEY_PATTERN, html)
+ m = re.search(self.PUBLICKEY_PATTERN, html)
+ n = re.search(self.CAPTCHAID_PATTERN, html)
if m and n:
- self.key = (m.group("ID"), m.group("KEY"))
- self.plugin.logDebug("AdsCaptcha id|key: %s | %s" % self.key)
+ self.key = (m.group(1).strip(), n.group(1).strip()) #: key is the tuple(PublicKey, CaptchaId)
+ self.plugin.logDebug("AdsCaptcha key|id: %s | %s" % self.key)
return self.key
else:
- self.plugin.logDebug("AdsCaptcha id or key not found")
+ self.plugin.logDebug("AdsCaptcha key or id not found")
return None
- def challenge(self, key=None): #: key is a tuple(CaptchaId, PublicKey)
+ def challenge(self, key=None):
if not key:
if self.detect_key():
key = self.key
else:
errmsg = _("AdsCaptcha key not found")
- self.plugin.error(errmsg)
+ self.plugin.fail(errmsg)
raise TypeError(errmsg)
- CaptchaId, PublicKey = key
+ PublicKey, CaptchaId = key
- js = self.plugin.req.load("http://api.adscaptcha.com/Get.aspx", get={'CaptchaId': CaptchaId, 'PublicKey': PublicKey})
+ html = self.plugin.req.load("http://api.adscaptcha.com/Get.aspx", get={'CaptchaId': CaptchaId, 'PublicKey': PublicKey})
try:
- challenge = re.search("challenge: '(.+?)',", js).group(1)
- server = re.search("server: '(.+?)',", js).group(1)
- except Exception:
- self.plugin.error(_("AdsCaptcha challenge pattern not found"))
+ challenge = re.search("challenge: '(.+?)',", html).group(1)
+ server = re.search("server: '(.+?)',", html).group(1)
+ except:
+ errmsg = _("AdsCaptcha challenge pattern not found")
+ self.plugin.error(errmsg)
+ raise ValueError(errmsg)
- result = self.result(server, challenge)
+ self.plugin.logDebug("AdsCaptcha challenge: %s" % challenge)
- self.plugin.logDebug("AdsCaptcha result: %s" % result, "challenge: %s" % challenge)
-
- return challenge, result
+ return challenge, self.result(server, challenge)
def result(self, server, challenge):
- return self.plugin.decryptCaptcha("%sChallenge.aspx" % server, get={'cid': challenge, 'dummy': random()},
- cookies=True, imgtype="jpg")
+ result = self.plugin.decryptCaptcha("%sChallenge.aspx" % server,
+ get={'cid': challenge, 'dummy': random()},
+ cookies=True,
+ imgtype="jpg")
+
+ self.plugin.logDebug("AdsCaptcha result: %s" % result)
+
+ return result