diff options
author | Walter Purcaro <vuolter@users.noreply.github.com> | 2015-12-16 11:04:11 +0100 |
---|---|---|
committer | Walter Purcaro <vuolter@users.noreply.github.com> | 2015-12-27 22:34:53 +0100 |
commit | c7eca073a22ee06282b50229df05ff2095e2ba2e (patch) | |
tree | 3d924a011607c15778f7921f64c73403fb770017 /module/plugins | |
parent | [Addon] Map events (diff) | |
download | pyload-c7eca073a22ee06282b50229df05ff2095e2ba2e.tar.xz |
[Captcha] Update
Diffstat (limited to 'module/plugins')
-rw-r--r-- | module/plugins/internal/Captcha.py | 29 |
1 files changed, 12 insertions, 17 deletions
diff --git a/module/plugins/internal/Captcha.py b/module/plugins/internal/Captcha.py index d30271dd4..da5440978 100644 --- a/module/plugins/internal/Captcha.py +++ b/module/plugins/internal/Captcha.py @@ -6,13 +6,13 @@ import os import time from module.plugins.internal.Plugin import Plugin -from module.plugins.internal.utils import encode +from module.plugins.internal.misc import encode class Captcha(Plugin): __name__ = "Captcha" __type__ = "captcha" - __version__ = "0.47" + __version__ = "0.48" __status__ = "stable" __description__ = """Base anti-captcha plugin""" @@ -20,10 +20,10 @@ class Captcha(Plugin): __authors__ = [("Walter Purcaro", "vuolter@gmail.com")] - def __init__(self, plugin): #@TODO: Pass pyfile instead plugin, so store plugin's html in its associated pyfile as data - self._init(plugin.pyload) + def __init__(self, pyfile): + self._init(pyfile.m.core) - self.plugin = plugin + self.pyfile = pyfile self.task = None #: captchaManager task self.init() @@ -31,20 +31,19 @@ class Captcha(Plugin): def _log(self, level, plugintype, pluginname, messages): messages = (self.__name__,) + messages - return self.plugin._log(level, plugintype, self.plugin.__name__, messages) + return self.pyfile.plugin._log(level, plugintype, self.pyfile.plugin.__name__, messages) def recognize(self, image): """ Extend to build your custom anti-captcha ocr """ - self.log_debug("This function does nothing") pass def decrypt(self, url, get={}, post={}, ref=False, cookies=True, decode=False, req=None, input_type='jpg', output_type='textual', ocr=True, timeout=120): - img = self.load(url, get=get, post=post, ref=ref, cookies=cookies, decode=decode, req=req or self.plugin.req) + img = self.load(url, get=get, post=post, ref=ref, cookies=cookies, decode=decode, req=req or self.pyfile.plugin.req) return self.decrypt_image(img, input_type, output_type, ocr, timeout) @@ -67,13 +66,13 @@ class Captcha(Plugin): result = "" time_ref = ("%.2f" % time.time())[-6:].replace(".", "") - with open(os.path.join("tmp", "captcha_image_%s_%s.%s" % (self.plugin.__name__, time_ref, input_type)), "wb") as tmp_img: + with open(os.path.join("tmp", "captcha_image_%s_%s.%s" % (self.pyfile.plugin.__name__, time_ref, input_type)), "wb") as tmp_img: tmp_img.write(encode(data)) if ocr: if isinstance(ocr, basestring): OCR = self.pyload.pluginManager.loadClass("captcha", ocr) #: Rename `captcha` to `ocr` in 0.4.10 - result = OCR(self.plugin).recognize(tmp_img.name) + result = OCR(self.pyfile).recognize(tmp_img.name) else: result = self.recognize(tmp_img.name) @@ -87,7 +86,7 @@ class Captcha(Plugin): self.task.setWaiting(max(timeout, 50)) #@TODO: Move to `CaptchaManager` in 0.4.10 while self.task.isWaiting(): - self.plugin.check_status() + self.pyfile.plugin.check_status() time.sleep(1) finally: @@ -97,16 +96,12 @@ class Captcha(Plugin): self.fail(self.task.error) elif not self.task.result: - self.plugin.retry_captcha(msg=_("No captcha result obtained in appropriate time")) + self.pyfile.plugin.retry_captcha(msg=_("No captcha result obtained in appropriate time")) result = self.task.result if not self.pyload.debug: - try: - os.remove(tmp_img.name) - - except OSError, e: - self.log_warning(_("Error removing `%s`") % tmp_img.name, e) + self.remove(tmp_img.name, trash=False) # self.log_info(_("Captcha result: ") + result) #@TODO: Remove from here? |