diff options
Diffstat (limited to 'module/plugins/hooks/BypassCaptcha.py')
-rw-r--r-- | module/plugins/hooks/BypassCaptcha.py | 41 |
1 files changed, 19 insertions, 22 deletions
diff --git a/module/plugins/hooks/BypassCaptcha.py b/module/plugins/hooks/BypassCaptcha.py index a32de7f42..9e01edfa2 100644 --- a/module/plugins/hooks/BypassCaptcha.py +++ b/module/plugins/hooks/BypassCaptcha.py @@ -1,11 +1,10 @@ # -*- coding: utf-8 -*- -from pycurl import FORM_FILE, LOW_SPEED_TIME -from thread import start_new_thread +import pycurl from module.network.HTTPRequest import BadHeader from module.network.RequestFactory import getURL, getRequest -from module.plugins.Hook import Hook +from module.plugins.Hook import Hook, threaded class BypassCaptchaException(Exception): @@ -29,18 +28,20 @@ class BypassCaptchaException(Exception): class BypassCaptcha(Hook): __name__ = "BypassCaptcha" __type__ = "hook" - __version__ = "0.05" + __version__ = "0.06" __config__ = [("force", "bool", "Force BC even if client is connected", False), ("passkey", "password", "Passkey", "")] __description__ = """Send captchas to BypassCaptcha.com""" __license__ = "GPLv3" - __authors__ = [("RaNaN", "RaNaN@pyload.org"), + __authors__ = [("RaNaN" , "RaNaN@pyload.org" ), ("Godofdream", "soilfcition@gmail.com"), - ("zoidberg", "zoidberg@mujmail.cz")] + ("zoidberg" , "zoidberg@mujmail.cz" )] + interval = 0 #@TODO: Remove in 0.4.10 + PYLOAD_KEY = "4f771155b640970d5607f919a615bdefc67e7d32" SUBMIT_URL = "http://bypasscaptcha.com/upload.php" @@ -48,19 +49,14 @@ class BypassCaptcha(Hook): GETCREDITS_URL = "http://bypasscaptcha.com/ex_left.php" - #@TODO: Remove in 0.4.10 - def initPeriodical(self): - pass - - def setup(self): self.info = {} #@TODO: Remove in 0.4.10 def getCredits(self): - res = getURL(self.GETCREDITS_URL, post={"key": self.getConfig("passkey")}) + res = getURL(self.GETCREDITS_URL, post={"key": self.getConfig('passkey')}) - data = dict([x.split(' ', 1) for x in res.splitlines()]) + data = dict(x.split(' ', 1) for x in res.splitlines()) return int(data['Left']) @@ -68,19 +64,19 @@ class BypassCaptcha(Hook): req = getRequest() #raise timeout threshold - req.c.setopt(LOW_SPEED_TIME, 80) + req.c.setopt(pycurl.LOW_SPEED_TIME, 80) try: res = req.load(self.SUBMIT_URL, post={'vendor_key': self.PYLOAD_KEY, - 'key': self.getConfig("passkey"), + 'key': self.getConfig('passkey'), 'gen_task_id': "1", - 'file': (FORM_FILE, captcha)}, + 'file': (pycurl.FORM_FILE, captcha)}, multipart=True) finally: req.close() - data = dict([x.split(' ', 1) for x in res.splitlines()]) + data = dict(x.split(' ', 1) for x in res.splitlines()) if not data or "Value" not in data: raise BypassCaptchaException(res) @@ -93,7 +89,7 @@ class BypassCaptcha(Hook): def respond(self, ticket, success): try: - res = getURL(self.RESPOND_URL, post={"task_id": ticket, "key": self.getConfig("passkey"), + res = getURL(self.RESPOND_URL, post={"task_id": ticket, "key": self.getConfig('passkey'), "cv": 1 if success else 0}) except BadHeader, e: self.logError(_("Could not send response"), e) @@ -106,17 +102,17 @@ class BypassCaptcha(Hook): if not task.isTextual(): return False - if not self.getConfig("passkey"): + if not self.getConfig('passkey'): return False - if self.core.isClientConnected() and not self.getConfig("force"): + if self.core.isClientConnected() and not self.getConfig('force'): return False if self.getCredits() > 0: task.handler.append(self) task.data['service'] = self.__name__ task.setWaiting(100) - start_new_thread(self.processCaptcha, (task,)) + self._processCaptcha(task) else: self.logInfo(_("Your %s account has not enough credits") % self.__name__) @@ -132,7 +128,8 @@ class BypassCaptcha(Hook): self.respond(task.data['ticket'], False) - def processCaptcha(self, task): + @threaded + def _processCaptcha(self, task): c = task.captchaFile try: ticket, result = self.submit(c) |