diff options
Diffstat (limited to 'module/plugins/hooks/ExpertDecoders.py')
-rw-r--r-- | module/plugins/hooks/ExpertDecoders.py | 44 |
1 files changed, 22 insertions, 22 deletions
diff --git a/module/plugins/hooks/ExpertDecoders.py b/module/plugins/hooks/ExpertDecoders.py index 54de8eb53..ccd48f664 100644 --- a/module/plugins/hooks/ExpertDecoders.py +++ b/module/plugins/hooks/ExpertDecoders.py @@ -2,36 +2,33 @@ from __future__ import with_statement +import pycurl +import uuid + from base64 import b64encode -from pycurl import LOW_SPEED_TIME -from thread import start_new_thread -from uuid import uuid4 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 ExpertDecoders(Hook): __name__ = "ExpertDecoders" __type__ = "hook" - __version__ = "0.03" + __version__ = "0.04" __config__ = [("force", "bool", "Force CT even if client is connected", False), ("passkey", "password", "Access key", "")] __description__ = """Send captchas to expertdecoders.com""" __license__ = "GPLv3" - __authors__ = [("RaNaN", "RaNaN@pyload.org"), + __authors__ = [("RaNaN" , "RaNaN@pyload.org" ), ("zoidberg", "zoidberg@mujmail.cz")] - API_URL = "http://www.fasttypers.org/imagepost.ashx" - + interval = 0 #@TODO: Remove in 0.4.10 - #@TODO: Remove in 0.4.10 - def initPeriodical(self): - pass + API_URL = "http://www.fasttypers.org/imagepost.ashx" def setup(self): @@ -39,7 +36,7 @@ class ExpertDecoders(Hook): def getCredits(self): - res = getURL(self.API_URL, post={"key": self.getConfig("passkey"), "action": "balance"}) + res = getURL(self.API_URL, post={"key": self.getConfig('passkey'), "action": "balance"}) if res.isdigit(): self.logInfo(_("%s credits left") % res) @@ -50,21 +47,24 @@ class ExpertDecoders(Hook): return 0 - def processCaptcha(self, task): - task.data['ticket'] = ticket = uuid4() + @threaded + def _processCaptcha(self, task): + task.data['ticket'] = ticket = uuid.uuid4() result = None with open(task.captchaFile, 'rb') as f: data = f.read() - data = b64encode(data) req = getRequest() #raise timeout threshold - req.c.setopt(LOW_SPEED_TIME, 80) + req.c.setopt(pycurl.LOW_SPEED_TIME, 80) try: - result = req.load(self.API_URL, post={"action": "upload", "key": self.getConfig("passkey"), - "file": data, "gen_task_id": ticket}) + result = req.load(self.API_URL, + post={'action' : "upload", + 'key' : self.getConfig('passkey'), + 'file' : b64encode(data), + 'gen_task_id': ticket}) finally: req.close() @@ -76,16 +76,16 @@ class ExpertDecoders(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.setWaiting(100) - start_new_thread(self.processCaptcha, (task,)) + self._processCaptcha(task) else: self.logInfo(_("Your ExpertDecoders Account has not enough credits")) @@ -96,7 +96,7 @@ class ExpertDecoders(Hook): try: res = getURL(self.API_URL, - post={'action': "refund", 'key': self.getConfig("passkey"), 'gen_task_id': task.data['ticket']}) + post={'action': "refund", 'key': self.getConfig('passkey'), 'gen_task_id': task.data['ticket']}) self.logInfo(_("Request refund"), res) except BadHeader, e: |