diff options
author | 2015-08-09 00:50:54 +0200 | |
---|---|---|
committer | 2015-08-09 00:50:54 +0200 | |
commit | b0ef3f1673e1930916604bb1264ca3a38414bc8d (patch) | |
tree | c97936e4d2a4cd6eb1072c65c8a08a7d18816b18 /module/plugins/hooks/ImageTyperz.py | |
parent | [XFileSharingPro][XFileSharingProFolder] Added default __pattern__ (diff) | |
parent | Fix https://github.com/pyload/pyload/issues/1707 (diff) | |
download | pyload-b0ef3f1673e1930916604bb1264ca3a38414bc8d.tar.xz |
Merge pull request #1 from pyload/stable
sync with stable
Diffstat (limited to 'module/plugins/hooks/ImageTyperz.py')
-rw-r--r-- | module/plugins/hooks/ImageTyperz.py | 78 |
1 files changed, 37 insertions, 41 deletions
diff --git a/module/plugins/hooks/ImageTyperz.py b/module/plugins/hooks/ImageTyperz.py index f1fcacb71..42ab99027 100644 --- a/module/plugins/hooks/ImageTyperz.py +++ b/module/plugins/hooks/ImageTyperz.py @@ -7,8 +7,8 @@ import re from base64 import b64encode -from module.network.RequestFactory import getURL, getRequest -from module.plugins.Hook import Hook, threaded +from module.network.RequestFactory import getRequest as get_request +from module.plugins.internal.Hook import Hook, threaded class ImageTyperzException(Exception): @@ -17,7 +17,7 @@ class ImageTyperzException(Exception): self.err = err - def getCode(self): + def get_code(self): return self.err @@ -32,11 +32,12 @@ class ImageTyperzException(Exception): class ImageTyperz(Hook): __name__ = "ImageTyperz" __type__ = "hook" - __version__ = "0.06" + __version__ = "0.08" + __status__ = "testing" - __config__ = [("username", "str", "Username", ""), - ("passkey", "password", "Password", ""), - ("force", "bool", "Force IT even if client is connected", False)] + __config__ = [("username" , "str" , "Username" , "" ), + ("password" , "password", "Password" , "" ), + ("check_client", "bool" , "Don't use if client is connected", True)] __description__ = """Send captchas to ImageTyperz.com""" __license__ = "GPLv3" @@ -44,22 +45,16 @@ class ImageTyperz(Hook): ("zoidberg", "zoidberg@mujmail.cz")] - interval = 0 #@TODO: Remove in 0.4.10 - SUBMIT_URL = "http://captchatypers.com/Forms/UploadFileAndGetTextNEW.ashx" RESPOND_URL = "http://captchatypers.com/Forms/SetBadImage.ashx" GETCREDITS_URL = "http://captchatypers.com/Forms/RequestBalance.ashx" - def setup(self): - self.info = {} #@TODO: Remove in 0.4.10 - - - def getCredits(self): - res = getURL(self.GETCREDITS_URL, + def get_credits(self): + res = self.load(self.GETCREDITS_URL, post={'action': "REQUESTBALANCE", - 'username': self.getConfig('username'), - 'password': self.getConfig('passkey')}) + 'username': self.get_config('username'), + 'password': self.get_config('password')}) if res.startswith('ERROR'): raise ImageTyperzException(res) @@ -69,18 +64,18 @@ class ImageTyperz(Hook): except Exception: raise ImageTyperzException("Invalid response") - self.logInfo(_("Account balance: $%s left") % res) + self.log_info(_("Account balance: $%s left") % res) return balance def submit(self, captcha, captchaType="file", match=None): - req = getRequest() - #raise timeout threshold + req = get_request() + #: Raise timeout threshold req.c.setopt(pycurl.LOW_SPEED_TIME, 80) try: #@NOTE: Workaround multipart-post bug in HTTPRequest.py - if re.match("^\w*$", self.getConfig('passkey')): + if re.match("^\w*$", self.get_config('password')): multipart = True data = (pycurl.FORM_FILE, captcha) else: @@ -89,11 +84,12 @@ class ImageTyperz(Hook): data = f.read() data = b64encode(data) - res = req.load(self.SUBMIT_URL, - post={'action': "UPLOADCAPTCHA", - 'username': self.getConfig('username'), - 'password': self.getConfig('passkey'), "file": data}, - multipart=multipart) + res = self.load(self.SUBMIT_URL, + post={'action': "UPLOADCAPTCHA", + 'username': self.get_config('username'), + 'password': self.get_config('password'), 'file': data}, + multipart=multipart, + req=req) finally: req.close() @@ -109,50 +105,50 @@ class ImageTyperz(Hook): return ticket, result - def newCaptchaTask(self, task): + def captcha_task(self, task): if "service" in task.data: return False if not task.isTextual(): return False - if not self.getConfig('username') or not self.getConfig('passkey'): + if not self.get_config('username') or not self.get_config('password'): return False - if self.core.isClientConnected() and not self.getConfig('force'): + if self.pyload.isClientConnected() and self.get_config('check_client'): return False - if self.getCredits() > 0: + if self.get_credits() > 0: task.handler.append(self) task.data['service'] = self.__name__ task.setWaiting(100) - self._processCaptcha(task) + self._process_captcha(task) else: - self.logInfo(_("Your %s account has not enough credits") % self.__name__) + self.log_info(_("Your %s account has not enough credits") % self.__name__) - def captchaInvalid(self, task): - if task.data['service'] == self.__name__ and "ticket" in task.data: - res = getURL(self.RESPOND_URL, + def captcha_invalid(self, task): + if task.data['service'] is self.__name__ and "ticket" in task.data: + res = self.load(self.RESPOND_URL, post={'action': "SETBADIMAGE", - 'username': self.getConfig('username'), - 'password': self.getConfig('passkey'), + 'username': self.get_config('username'), + 'password': self.get_config('password'), 'imageid': task.data['ticket']}) if res == "SUCCESS": - self.logInfo(_("Bad captcha solution received, requested refund")) + self.log_info(_("Bad captcha solution received, requested refund")) else: - self.logError(_("Bad captcha solution received, refund request failed"), res) + self.log_error(_("Bad captcha solution received, refund request failed"), res) @threaded - def _processCaptcha(self, task): + def _process_captcha(self, task): c = task.captchaFile try: ticket, result = self.submit(c) except ImageTyperzException, e: - task.error = e.getCode() + task.error = e.get_code() return task.data['ticket'] = ticket |