From 0e1ef9bc01579328e17e79416fa3c1c7b77adcc8 Mon Sep 17 00:00:00 2001 From: Walter Purcaro Date: Mon, 8 Jun 2015 06:08:01 +0200 Subject: Update everything --- module/plugins/internal/Captcha.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'module/plugins/internal/Captcha.py') diff --git a/module/plugins/internal/Captcha.py b/module/plugins/internal/Captcha.py index b4af46493..e5a44d750 100644 --- a/module/plugins/internal/Captcha.py +++ b/module/plugins/internal/Captcha.py @@ -1,13 +1,13 @@ # -*- coding: utf-8 -*- -from module.plugins.Plugin import Base +from module.plugins.internal.Plugin import Base #@TODO: Extend (new) Plugin class; remove all `html` args class Captcha(Base): __name__ = "Captcha" __type__ = "captcha" - __version__ = "0.29" + __version__ = "0.30" __description__ = """Base captcha service plugin""" __license__ = "GPLv3" -- cgit v1.2.3 From 5a139055ae658d3a05cbb658cbd66aeae0d01db5 Mon Sep 17 00:00:00 2001 From: Walter Purcaro Date: Mon, 15 Jun 2015 21:06:10 +0200 Subject: Spare code cosmetics --- module/plugins/internal/Captcha.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'module/plugins/internal/Captcha.py') diff --git a/module/plugins/internal/Captcha.py b/module/plugins/internal/Captcha.py index e5a44d750..8d040515c 100644 --- a/module/plugins/internal/Captcha.py +++ b/module/plugins/internal/Captcha.py @@ -1,10 +1,10 @@ # -*- coding: utf-8 -*- -from module.plugins.internal.Plugin import Base +from module.plugins.internal.Plugin import Plugin #@TODO: Extend (new) Plugin class; remove all `html` args -class Captcha(Base): +class Captcha(Plugin): __name__ = "Captcha" __type__ = "captcha" __version__ = "0.30" -- cgit v1.2.3 From c1764e2fea0bb05164c83a876e8cd58b97f58f25 Mon Sep 17 00:00:00 2001 From: Walter Purcaro Date: Tue, 16 Jun 2015 17:31:38 +0200 Subject: Update all --- module/plugins/internal/Captcha.py | 6 ------ 1 file changed, 6 deletions(-) (limited to 'module/plugins/internal/Captcha.py') diff --git a/module/plugins/internal/Captcha.py b/module/plugins/internal/Captcha.py index 8d040515c..8dbc33da2 100644 --- a/module/plugins/internal/Captcha.py +++ b/module/plugins/internal/Captcha.py @@ -22,12 +22,6 @@ class Captcha(Plugin): super(Captcha, self).__init__(plugin.core) - #@TODO: Recheck in 0.4.10 - def fail(self, reason): - self.plugin.fail(reason) - raise AttributeError(reason) - - #@TODO: Recheck in 0.4.10 def retrieve_key(self, html): if self.detect_key(html): -- cgit v1.2.3 From d99d6eddb6af637580bb6fc72013f913077525d6 Mon Sep 17 00:00:00 2001 From: Walter Purcaro Date: Wed, 17 Jun 2015 11:23:08 +0200 Subject: Spare fixes --- module/plugins/internal/Captcha.py | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) (limited to 'module/plugins/internal/Captcha.py') diff --git a/module/plugins/internal/Captcha.py b/module/plugins/internal/Captcha.py index 8dbc33da2..4629c9522 100644 --- a/module/plugins/internal/Captcha.py +++ b/module/plugins/internal/Captcha.py @@ -3,7 +3,6 @@ from module.plugins.internal.Plugin import Plugin -#@TODO: Extend (new) Plugin class; remove all `html` args class Captcha(Plugin): __name__ = "Captcha" __type__ = "captcha" @@ -11,16 +10,15 @@ class Captcha(Plugin): __description__ = """Base captcha service plugin""" __license__ = "GPLv3" - __authors__ = [("pyLoad Team", "admin@pyload.org")] - - - key = None #: last key detected + __authors__ = [("Walter Purcaro", "vuolter@gmail.com")] def __init__(self, plugin): - self.plugin = plugin super(Captcha, self).__init__(plugin.core) + self.plugin = plugin + self.key = None #: last key detected + #@TODO: Recheck in 0.4.10 def retrieve_key(self, html): -- cgit v1.2.3 From b1759bc440cd6013837697eb8de540914f693ffd Mon Sep 17 00:00:00 2001 From: Walter Purcaro Date: Tue, 7 Jul 2015 01:23:55 +0200 Subject: No camelCase style anymore --- module/plugins/internal/Captcha.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'module/plugins/internal/Captcha.py') diff --git a/module/plugins/internal/Captcha.py b/module/plugins/internal/Captcha.py index 4629c9522..50ebea89c 100644 --- a/module/plugins/internal/Captcha.py +++ b/module/plugins/internal/Captcha.py @@ -6,7 +6,7 @@ from module.plugins.internal.Plugin import Plugin class Captcha(Plugin): __name__ = "Captcha" __type__ = "captcha" - __version__ = "0.30" + __version__ = "0.31" __description__ = """Base captcha service plugin""" __license__ = "GPLv3" -- cgit v1.2.3 From dad722ac7255640e7e0541c4094a4d2e4de79cd3 Mon Sep 17 00:00:00 2001 From: Walter Purcaro Date: Sun, 19 Jul 2015 00:05:58 +0200 Subject: Code cosmetics (2) --- module/plugins/internal/Captcha.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'module/plugins/internal/Captcha.py') diff --git a/module/plugins/internal/Captcha.py b/module/plugins/internal/Captcha.py index 50ebea89c..68d5d3bb8 100644 --- a/module/plugins/internal/Captcha.py +++ b/module/plugins/internal/Captcha.py @@ -17,7 +17,7 @@ class Captcha(Plugin): super(Captcha, self).__init__(plugin.core) self.plugin = plugin - self.key = None #: last key detected + self.key = None #: Last key detected #@TODO: Recheck in 0.4.10 -- cgit v1.2.3 From 502517f37c7540b0bddb092e69386d9d6f08800c Mon Sep 17 00:00:00 2001 From: Walter Purcaro Date: Sun, 19 Jul 2015 09:42:34 +0200 Subject: Fix addons --- module/plugins/internal/Captcha.py | 9 +++++++++ 1 file changed, 9 insertions(+) (limited to 'module/plugins/internal/Captcha.py') diff --git a/module/plugins/internal/Captcha.py b/module/plugins/internal/Captcha.py index 68d5d3bb8..1309b0d6b 100644 --- a/module/plugins/internal/Captcha.py +++ b/module/plugins/internal/Captcha.py @@ -19,6 +19,15 @@ class Captcha(Plugin): self.plugin = plugin self.key = None #: Last key detected + self.init() + + + def init(self): + """ + Initialize additional data structures + """ + pass + #@TODO: Recheck in 0.4.10 def retrieve_key(self, html): -- cgit v1.2.3 From 56389e28ba5d2f5658278bc7f486d73be747f135 Mon Sep 17 00:00:00 2001 From: Walter Purcaro Date: Sun, 19 Jul 2015 11:44:49 +0200 Subject: Rename self.core to self.pyload (plugins only) --- module/plugins/internal/Captcha.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'module/plugins/internal/Captcha.py') diff --git a/module/plugins/internal/Captcha.py b/module/plugins/internal/Captcha.py index 1309b0d6b..6ca754a06 100644 --- a/module/plugins/internal/Captcha.py +++ b/module/plugins/internal/Captcha.py @@ -14,7 +14,8 @@ class Captcha(Plugin): def __init__(self, plugin): - super(Captcha, self).__init__(plugin.core) + self.pyload = plugin.core + self.info = {} #: Provide information in dict here self.plugin = plugin self.key = None #: Last key detected -- cgit v1.2.3 From d38e830b7c0b3c6561a0072c74bbccb5fcdf4a61 Mon Sep 17 00:00:00 2001 From: Walter Purcaro Date: Sun, 19 Jul 2015 14:43:42 +0200 Subject: New __status__ magic key --- module/plugins/internal/Captcha.py | 1 + 1 file changed, 1 insertion(+) (limited to 'module/plugins/internal/Captcha.py') diff --git a/module/plugins/internal/Captcha.py b/module/plugins/internal/Captcha.py index 6ca754a06..814c36756 100644 --- a/module/plugins/internal/Captcha.py +++ b/module/plugins/internal/Captcha.py @@ -7,6 +7,7 @@ class Captcha(Plugin): __name__ = "Captcha" __type__ = "captcha" __version__ = "0.31" + __status__ = "stable" __description__ = """Base captcha service plugin""" __license__ = "GPLv3" -- cgit v1.2.3 From 027cb529d79558de19c47da88a782b31745a65c9 Mon Sep 17 00:00:00 2001 From: Walter Purcaro Date: Tue, 21 Jul 2015 22:53:37 +0200 Subject: New Captcha skeleton --- module/plugins/internal/Captcha.py | 102 +++++++++++++++++++++++++++++-------- 1 file changed, 82 insertions(+), 20 deletions(-) (limited to 'module/plugins/internal/Captcha.py') diff --git a/module/plugins/internal/Captcha.py b/module/plugins/internal/Captcha.py index 814c36756..af7f66ed5 100644 --- a/module/plugins/internal/Captcha.py +++ b/module/plugins/internal/Captcha.py @@ -6,24 +6,28 @@ from module.plugins.internal.Plugin import Plugin class Captcha(Plugin): __name__ = "Captcha" __type__ = "captcha" - __version__ = "0.31" + __version__ = "0.01" __status__ = "stable" - __description__ = """Base captcha service plugin""" + __description__ = """Base anti-captcha plugin""" __license__ = "GPLv3" __authors__ = [("Walter Purcaro", "vuolter@gmail.com")] - def __init__(self, plugin): + def __init__(self, plugin): #@TODO: pass pyfile instead plugin, so store plugin's html in its associated pyfile as data self.pyload = plugin.core self.info = {} #: Provide information in dict here self.plugin = plugin - self.key = None #: Last key detected + self.task = None #: captchaManager task self.init() + def _log(self, type, args): + return super(Captcha, self)._log(type, (self.plugin.__name__,) + args) + + def init(self): """ Initialize additional data structures @@ -31,29 +35,87 @@ class Captcha(Plugin): pass - #@TODO: Recheck in 0.4.10 - def retrieve_key(self, html): - if self.detect_key(html): - return self.key + def decrypt_image(self, url, get={}, post={}, ref=False, cookies=False, decode=False, + input_type='png', output_type='textual', try_ocr=True): + image = self.load(url, get=get, post=post, ref=ref, cookies=cookies, decode=decode) + return self.decrypt(image, input_type, output_type, try_ocr) + + + def decrypt(self, data, input_type='png', output_type='textual', try_ocr=True): + """ + Loads a captcha and decrypts it with ocr, plugin, user input + + :param url: url of captcha image + :param get: get part for request + :param post: post part for request + :param cookies: True if cookies should be enabled + :param input_type: Type of the Image + :param output_type: 'textual' if text is written on the captcha\ + or 'positional' for captcha where the user have to click\ + on a specific region on the captcha + :param try_ocr: if True, ocr is not used + + :return: result of decrypting + """ + id = ("%.2f" % time.time())[-6:].replace(".", "") + + with open(os.path.join("tmp", "tmpCaptcha_%s_%s.%s" % (self.plugin.__name__, id, input_type)), "wb") as tmpCaptcha: + tmpCaptcha.write(img) + + has_plugin = self.plugin.__name__ in self.pyload.pluginManager.ocrPlugins + + if self.pyload.captcha: + Ocr = self.pyload.pluginManager.loadClass("ocr", self.plugin.__name__) else: - self.fail(_("%s key not found") % self.__name__) + Ocr = None + if Ocr and try_ocr: + time.sleep(random.randint(3000, 5000) / 1000.0) + if self.pyfile.abort: + self.abort() - #@TODO: Recheck in 0.4.10 - def retrieve_html(self): - if hasattr(self.plugin, "html") and self.plugin.html: - return self.plugin.html + ocr = Ocr(self.pyfile) + result = ocr.get_captcha(tmpCaptcha.name) else: - self.fail(_("%s html not found") % self.__name__) + captchaManager = self.pyload.captchaManager + task = captchaManager.newTask(img, input_type, tmpCaptcha.name, output_type) + self.task = task + captchaManager.handleCaptcha(task) + + while task.isWaiting(): + if self.pyfile.abort: + captchaManager.removeTask(task) + self.abort() + time.sleep(1) + + captchaManager.removeTask(task) + + if task.error and has_plugin: #: Ignore default error message since the user could use try_ocr + self.fail(_("Pil and tesseract not installed and no Client connected for captcha decrypting")) + elif task.error: + self.fail(task.error) + elif not task.result: + self.fail(_("No captcha result obtained in appropiate time by any of the plugins")) + + result = task.result + self.log_debug("Received captcha result: %s" % result) + if not self.pyload.debug: + try: + os.remove(tmpCaptcha.name) + except Exception: + pass - def detect_key(self, html=None): - raise NotImplementedError + return result - def challenge(self, key=None, html=None): - raise NotImplementedError + def invalid(self): + self.log_error(_("Invalid captcha")) + if self.task: + self.task.invalid() - def result(self, server, challenge): - raise NotImplementedError + def correct(self): + self.log_info(_("Correct captcha")) + if self.task: + self.task.correct() -- cgit v1.2.3 From 6af9b38a8d5d49355b85aef6ddd003605d6bba05 Mon Sep 17 00:00:00 2001 From: Walter Purcaro Date: Thu, 23 Jul 2015 23:44:45 +0200 Subject: Improve Captcha --- module/plugins/internal/Captcha.py | 89 ++++++++++++++++++++------------------ 1 file changed, 48 insertions(+), 41 deletions(-) (limited to 'module/plugins/internal/Captcha.py') diff --git a/module/plugins/internal/Captcha.py b/module/plugins/internal/Captcha.py index af7f66ed5..942021f26 100644 --- a/module/plugins/internal/Captcha.py +++ b/module/plugins/internal/Captcha.py @@ -1,12 +1,14 @@ # -*- coding: utf-8 -*- +import time + from module.plugins.internal.Plugin import Plugin class Captcha(Plugin): __name__ = "Captcha" __type__ = "captcha" - __version__ = "0.01" + __version__ = "0.02" __status__ = "stable" __description__ = """Base anti-captcha plugin""" @@ -35,13 +37,21 @@ class Captcha(Plugin): pass - def decrypt_image(self, url, get={}, post={}, ref=False, cookies=False, decode=False, - input_type='png', output_type='textual', try_ocr=True): - image = self.load(url, get=get, post=post, ref=ref, cookies=cookies, decode=decode) - return self.decrypt(image, input_type, output_type, try_ocr) + def recognize(self, image): + """ + Extend to build your custom anti-captcha ocr + """ + pass + + + def decrypt(self, url, get={}, post={}, ref=False, cookies=False, decode=False, + input_type='png', output_type='textual', ocr=True): + img = self.load(url, get=get, post=post, ref=ref, cookies=cookies, decode=decode) + return self._decrypt(img, input_type, output_type, ocr) - def decrypt(self, data, input_type='png', output_type='textual', try_ocr=True): + #@TODO: Definitely dhoose a better name for this method! + def _decrypt(self, raw, input_type='png', output_type='textual', ocr=None): """ Loads a captcha and decrypts it with ocr, plugin, user input @@ -53,56 +63,53 @@ class Captcha(Plugin): :param output_type: 'textual' if text is written on the captcha\ or 'positional' for captcha where the user have to click\ on a specific region on the captcha - :param try_ocr: if True, ocr is not used + :param ocr: if True, ocr is not used :return: result of decrypting """ - id = ("%.2f" % time.time())[-6:].replace(".", "") + 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: + tmp_img.write(raw) + + if ocr is not False: + if isinstance(ocr, basestring): + OCR = self.pyload.pluginManager.loadClass("captcha", ocr) #: Rename `captcha` to `ocr` in 0.4.10 - with open(os.path.join("tmp", "tmpCaptcha_%s_%s.%s" % (self.plugin.__name__, id, input_type)), "wb") as tmpCaptcha: - tmpCaptcha.write(img) + if self.plugin.pyfile.abort: + self.abort() - has_plugin = self.plugin.__name__ in self.pyload.pluginManager.ocrPlugins + result = OCR(self.plugin.pyfile).recognize(tmp_img.name) - if self.pyload.captcha: - Ocr = self.pyload.pluginManager.loadClass("ocr", self.plugin.__name__) - else: - Ocr = None + else: + result = self.recognize(tmp_img.name) - if Ocr and try_ocr: - time.sleep(random.randint(3000, 5000) / 1000.0) - if self.pyfile.abort: - self.abort() + else: + captchaManager = self.pyload.captchaManager - ocr = Ocr(self.pyfile) - result = ocr.get_captcha(tmpCaptcha.name) - else: - captchaManager = self.pyload.captchaManager - task = captchaManager.newTask(img, input_type, tmpCaptcha.name, output_type) - self.task = task - captchaManager.handleCaptcha(task) + try: + self.task = captchaManager.newTask(img, input_type, tmp_img.name, output_type) + captchaManager.handleCaptcha(self.task) - while task.isWaiting(): - if self.pyfile.abort: - captchaManager.removeTask(task) - self.abort() - time.sleep(1) + while self.task.isWaiting(): + if self.plugin.pyfile.abort: + self.abort() + time.sleep(1) + finally: + captchaManager.removeTask(self.task) - captchaManager.removeTask(task) + if self.task.error: + self.fail(task.error) - if task.error and has_plugin: #: Ignore default error message since the user could use try_ocr - self.fail(_("Pil and tesseract not installed and no Client connected for captcha decrypting")) - elif task.error: - self.fail(task.error) - elif not task.result: - self.fail(_("No captcha result obtained in appropiate time by any of the plugins")) + elif not self.task.result: + self.fail(_("No captcha result obtained in appropiate time by any of the plugins")) - result = task.result - self.log_debug("Received captcha result: %s" % result) + result = task.result + self.log_debug("Received captcha result: %s" % result) #@TODO: Remove from here? if not self.pyload.debug: try: - os.remove(tmpCaptcha.name) + os.remove(tmp_img.name) except Exception: pass -- cgit v1.2.3 From 12cbb11279ebfa2f2945c5adb093b97924a8cfc3 Mon Sep 17 00:00:00 2001 From: Walter Purcaro Date: Fri, 24 Jul 2015 00:33:19 +0200 Subject: Small __init__ fixes --- module/plugins/internal/Captcha.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'module/plugins/internal/Captcha.py') diff --git a/module/plugins/internal/Captcha.py b/module/plugins/internal/Captcha.py index 942021f26..1d23eb16e 100644 --- a/module/plugins/internal/Captcha.py +++ b/module/plugins/internal/Captcha.py @@ -16,8 +16,8 @@ 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.pyload = plugin.core + def __init__(self, plugin): #@TODO: Pass pyfile instead plugin, so store plugin's html in its associated pyfile as data + self.pyload = plugin.pyload self.info = {} #: Provide information in dict here self.plugin = plugin @@ -79,7 +79,7 @@ class Captcha(Plugin): if self.plugin.pyfile.abort: self.abort() - result = OCR(self.plugin.pyfile).recognize(tmp_img.name) + result = OCR(self.plugin).recognize(tmp_img.name) else: result = self.recognize(tmp_img.name) -- cgit v1.2.3 From f7df6ef48a7c0a8ab6351e046cd12160257c4ef5 Mon Sep 17 00:00:00 2001 From: Walter Purcaro Date: Fri, 24 Jul 2015 02:15:31 +0200 Subject: Hotfixes --- module/plugins/internal/Captcha.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) (limited to 'module/plugins/internal/Captcha.py') diff --git a/module/plugins/internal/Captcha.py b/module/plugins/internal/Captcha.py index 1d23eb16e..1345f1784 100644 --- a/module/plugins/internal/Captcha.py +++ b/module/plugins/internal/Captcha.py @@ -1,6 +1,7 @@ # -*- coding: utf-8 -*- import time +import traceback from module.plugins.internal.Plugin import Plugin @@ -110,8 +111,9 @@ class Captcha(Plugin): if not self.pyload.debug: try: os.remove(tmp_img.name) - except Exception: - pass + except OSError, e: + self.log_warning(_("Error removing: %s") % tmp_img.name, e) + traceback.print_exc() return result -- cgit v1.2.3 From 94d017cd2a5c1f194960827a8c7e46afc3682008 Mon Sep 17 00:00:00 2001 From: Walter Purcaro Date: Fri, 24 Jul 2015 06:55:49 +0200 Subject: Hotfixes (2) --- module/plugins/internal/Captcha.py | 20 ++++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) (limited to 'module/plugins/internal/Captcha.py') diff --git a/module/plugins/internal/Captcha.py b/module/plugins/internal/Captcha.py index 1345f1784..89cace612 100644 --- a/module/plugins/internal/Captcha.py +++ b/module/plugins/internal/Captcha.py @@ -9,8 +9,8 @@ from module.plugins.internal.Plugin import Plugin class Captcha(Plugin): __name__ = "Captcha" __type__ = "captcha" - __version__ = "0.02" - __status__ = "stable" + __version__ = "0.31" + __status__ = "testing" __description__ = """Base anti-captcha plugin""" __license__ = "GPLv3" @@ -27,8 +27,8 @@ class Captcha(Plugin): self.init() - def _log(self, type, args): - return super(Captcha, self)._log(type, (self.plugin.__name__,) + args) + def _log(self, level, args): + return self.plugin._log(level, (self.__name__,) + args) def init(self): @@ -119,12 +119,16 @@ class Captcha(Plugin): def invalid(self): + if not self.task: + return + self.log_error(_("Invalid captcha")) - if self.task: - self.task.invalid() + self.task.invalid() def correct(self): + if not self.task: + return + self.log_info(_("Correct captcha")) - if self.task: - self.task.correct() + self.task.correct() -- cgit v1.2.3 From a95c217627a1cb651b24e69f20640df40797aff9 Mon Sep 17 00:00:00 2001 From: Walter Purcaro Date: Sat, 25 Jul 2015 09:34:18 +0200 Subject: Account rewritten (2) --- module/plugins/internal/Captcha.py | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) (limited to 'module/plugins/internal/Captcha.py') diff --git a/module/plugins/internal/Captcha.py b/module/plugins/internal/Captcha.py index 89cace612..ec618e353 100644 --- a/module/plugins/internal/Captcha.py +++ b/module/plugins/internal/Captcha.py @@ -1,5 +1,6 @@ # -*- coding: utf-8 -*- +import os import time import traceback @@ -27,10 +28,6 @@ class Captcha(Plugin): self.init() - def _log(self, level, args): - return self.plugin._log(level, (self.__name__,) + args) - - def init(self): """ Initialize additional data structures -- cgit v1.2.3 From f83389333ec10376452aa5f6d5ccd3963c6bafa1 Mon Sep 17 00:00:00 2001 From: Walter Purcaro Date: Mon, 27 Jul 2015 10:28:30 +0200 Subject: Update internal plugins --- module/plugins/internal/Captcha.py | 26 +++++++++++++++----------- 1 file changed, 15 insertions(+), 11 deletions(-) (limited to 'module/plugins/internal/Captcha.py') diff --git a/module/plugins/internal/Captcha.py b/module/plugins/internal/Captcha.py index ec618e353..32d882fac 100644 --- a/module/plugins/internal/Captcha.py +++ b/module/plugins/internal/Captcha.py @@ -10,7 +10,7 @@ from module.plugins.internal.Plugin import Plugin class Captcha(Plugin): __name__ = "Captcha" __type__ = "captcha" - __version__ = "0.31" + __version__ = "0.32" __status__ = "testing" __description__ = """Base anti-captcha plugin""" @@ -20,9 +20,8 @@ class Captcha(Plugin): def __init__(self, plugin): #@TODO: Pass pyfile instead plugin, so store plugin's html in its associated pyfile as data self.pyload = plugin.pyload - self.info = {} #: Provide information in dict here - self.plugin = plugin + self.info = {} #: Provide information in dict here self.task = None #: captchaManager task self.init() @@ -35,6 +34,10 @@ class Captcha(Plugin): pass + def _log(self, level, args): + return self.plugin._log(level, (self.__name__,) + args) + + def recognize(self, image): """ Extend to build your custom anti-captcha ocr @@ -43,17 +46,17 @@ class Captcha(Plugin): def decrypt(self, url, get={}, post={}, ref=False, cookies=False, decode=False, - input_type='png', output_type='textual', ocr=True): + input_type='jpg', output_type='textual', ocr=True): img = self.load(url, get=get, post=post, ref=ref, cookies=cookies, decode=decode) return self._decrypt(img, input_type, output_type, ocr) #@TODO: Definitely dhoose a better name for this method! - def _decrypt(self, raw, input_type='png', output_type='textual', ocr=None): + def _decrypt(self, raw, input_type='jpg', output_type='textual', ocr=None): """ Loads a captcha and decrypts it with ocr, plugin, user input - :param url: url of captcha image + :param raw: image raw data :param get: get part for request :param post: post part for request :param cookies: True if cookies should be enabled @@ -75,7 +78,7 @@ class Captcha(Plugin): OCR = self.pyload.pluginManager.loadClass("captcha", ocr) #: Rename `captcha` to `ocr` in 0.4.10 if self.plugin.pyfile.abort: - self.abort() + self.plugin.abort() result = OCR(self.plugin).recognize(tmp_img.name) @@ -86,12 +89,12 @@ class Captcha(Plugin): captchaManager = self.pyload.captchaManager try: - self.task = captchaManager.newTask(img, input_type, tmp_img.name, output_type) + self.task = captchaManager.newTask(raw, input_type, tmp_img.name, output_type) captchaManager.handleCaptcha(self.task) while self.task.isWaiting(): if self.plugin.pyfile.abort: - self.abort() + self.plugin.abort() time.sleep(1) finally: captchaManager.removeTask(self.task) @@ -102,12 +105,13 @@ class Captcha(Plugin): elif not self.task.result: self.fail(_("No captcha result obtained in appropiate time by any of the plugins")) - result = task.result - self.log_debug("Received captcha result: %s" % result) #@TODO: Remove from here? + result = self.task.result + self.log_info(_("Captcha result: ") + result) #@TODO: Remove from here? if not self.pyload.debug: try: os.remove(tmp_img.name) + except OSError, e: self.log_warning(_("Error removing: %s") % tmp_img.name, e) traceback.print_exc() -- cgit v1.2.3 From 0fd83be485e6cca2f6b18a08dfa4328d2e793230 Mon Sep 17 00:00:00 2001 From: Walter Purcaro Date: Mon, 27 Jul 2015 20:16:07 +0200 Subject: Fix captcha timeout --- module/plugins/internal/Captcha.py | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) (limited to 'module/plugins/internal/Captcha.py') diff --git a/module/plugins/internal/Captcha.py b/module/plugins/internal/Captcha.py index 32d882fac..8ba1a1829 100644 --- a/module/plugins/internal/Captcha.py +++ b/module/plugins/internal/Captcha.py @@ -10,7 +10,7 @@ from module.plugins.internal.Plugin import Plugin class Captcha(Plugin): __name__ = "Captcha" __type__ = "captcha" - __version__ = "0.32" + __version__ = "0.33" __status__ = "testing" __description__ = """Base anti-captcha plugin""" @@ -46,13 +46,13 @@ class Captcha(Plugin): def decrypt(self, url, get={}, post={}, ref=False, cookies=False, decode=False, - input_type='jpg', output_type='textual', ocr=True): + input_type='jpg', output_type='textual', ocr=True, timeout=300): img = self.load(url, get=get, post=post, ref=ref, cookies=cookies, decode=decode) - return self._decrypt(img, input_type, output_type, ocr) + return self._decrypt(img, input_type, output_type, ocr, timeout) - #@TODO: Definitely dhoose a better name for this method! - def _decrypt(self, raw, input_type='jpg', output_type='textual', ocr=None): + #@TODO: Definitely choose a better name for this method! + def _decrypt(self, raw, input_type='jpg', output_type='textual', ocr=None, timeout=300): """ Loads a captcha and decrypts it with ocr, plugin, user input @@ -91,11 +91,13 @@ class Captcha(Plugin): try: self.task = captchaManager.newTask(raw, input_type, tmp_img.name, output_type) captchaManager.handleCaptcha(self.task) + self.task.setWaiting(max(timeout, 50)) #@TODO: Move to `CaptchaManager` in 0.4.10 while self.task.isWaiting(): if self.plugin.pyfile.abort: self.plugin.abort() time.sleep(1) + finally: captchaManager.removeTask(self.task) @@ -103,7 +105,8 @@ class Captcha(Plugin): self.fail(task.error) elif not self.task.result: - self.fail(_("No captcha result obtained in appropiate time by any of the plugins")) + self.captcha.invalid() + self.plugin.retry(reason=_("No captcha result obtained in appropiate time")) result = self.task.result self.log_info(_("Captcha result: ") + result) #@TODO: Remove from here? -- cgit v1.2.3 From 2e4f84afb8ae79241c805e441281ff14a2c50783 Mon Sep 17 00:00:00 2001 From: Walter Purcaro Date: Tue, 28 Jul 2015 00:14:43 +0200 Subject: Fix https://github.com/pyload/pyload/pull/1564 (thx Nippey) --- module/plugins/internal/Captcha.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'module/plugins/internal/Captcha.py') diff --git a/module/plugins/internal/Captcha.py b/module/plugins/internal/Captcha.py index 8ba1a1829..57105caea 100644 --- a/module/plugins/internal/Captcha.py +++ b/module/plugins/internal/Captcha.py @@ -46,13 +46,13 @@ class Captcha(Plugin): def decrypt(self, url, get={}, post={}, ref=False, cookies=False, decode=False, - input_type='jpg', output_type='textual', ocr=True, timeout=300): + input_type='jpg', output_type='textual', ocr=True, timeout=120): img = self.load(url, get=get, post=post, ref=ref, cookies=cookies, decode=decode) return self._decrypt(img, input_type, output_type, ocr, timeout) #@TODO: Definitely choose a better name for this method! - def _decrypt(self, raw, input_type='jpg', output_type='textual', ocr=None, timeout=300): + def _decrypt(self, raw, input_type='jpg', output_type='textual', ocr=None, timeout=120): """ Loads a captcha and decrypts it with ocr, plugin, user input -- cgit v1.2.3 From 6f387ff66b93e24cc52db7a5ea277265d35f051d Mon Sep 17 00:00:00 2001 From: Walter Purcaro Date: Tue, 28 Jul 2015 00:29:19 +0200 Subject: Missed to bump up some plugin __version__ --- module/plugins/internal/Captcha.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'module/plugins/internal/Captcha.py') diff --git a/module/plugins/internal/Captcha.py b/module/plugins/internal/Captcha.py index 57105caea..db2d25a8a 100644 --- a/module/plugins/internal/Captcha.py +++ b/module/plugins/internal/Captcha.py @@ -10,7 +10,7 @@ from module.plugins.internal.Plugin import Plugin class Captcha(Plugin): __name__ = "Captcha" __type__ = "captcha" - __version__ = "0.33" + __version__ = "0.34" __status__ = "testing" __description__ = """Base anti-captcha plugin""" -- cgit v1.2.3 From ecf37227de05c73b7ffe2da89a5eda1259a72543 Mon Sep 17 00:00:00 2001 From: Walter Purcaro Date: Tue, 28 Jul 2015 01:09:59 +0200 Subject: Improve _log method --- module/plugins/internal/Captcha.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'module/plugins/internal/Captcha.py') diff --git a/module/plugins/internal/Captcha.py b/module/plugins/internal/Captcha.py index db2d25a8a..486d92c19 100644 --- a/module/plugins/internal/Captcha.py +++ b/module/plugins/internal/Captcha.py @@ -10,7 +10,7 @@ from module.plugins.internal.Plugin import Plugin class Captcha(Plugin): __name__ = "Captcha" __type__ = "captcha" - __version__ = "0.34" + __version__ = "0.35" __status__ = "testing" __description__ = """Base anti-captcha plugin""" @@ -34,8 +34,8 @@ class Captcha(Plugin): pass - def _log(self, level, args): - return self.plugin._log(level, (self.__name__,) + args) + def _log(self, level, plugintype, pluginname, messages): + return self.plugin._log(level, plugintype, pluginname, (self.__name__,) + messages) def recognize(self, image): -- cgit v1.2.3 From 179b7a30c15e298b612509c474503155df9dddb9 Mon Sep 17 00:00:00 2001 From: Walter Purcaro Date: Tue, 28 Jul 2015 01:47:40 +0200 Subject: Fix https://github.com/pyload/pyload/issues/1575 --- module/plugins/internal/Captcha.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) (limited to 'module/plugins/internal/Captcha.py') diff --git a/module/plugins/internal/Captcha.py b/module/plugins/internal/Captcha.py index 486d92c19..dd2c7c762 100644 --- a/module/plugins/internal/Captcha.py +++ b/module/plugins/internal/Captcha.py @@ -1,5 +1,7 @@ # -*- coding: utf-8 -*- +from __future__ import with_statement + import os import time import traceback @@ -10,7 +12,7 @@ from module.plugins.internal.Plugin import Plugin class Captcha(Plugin): __name__ = "Captcha" __type__ = "captcha" - __version__ = "0.35" + __version__ = "0.36" __status__ = "testing" __description__ = """Base anti-captcha plugin""" -- cgit v1.2.3 From 5a2781c923ecd13f3e671366fa6fa311d92d8547 Mon Sep 17 00:00:00 2001 From: Walter Purcaro Date: Wed, 29 Jul 2015 08:21:04 +0200 Subject: Fix https://github.com/pyload/pyload/issues/1586 --- module/plugins/internal/Captcha.py | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) (limited to 'module/plugins/internal/Captcha.py') diff --git a/module/plugins/internal/Captcha.py b/module/plugins/internal/Captcha.py index dd2c7c762..92bcf9f84 100644 --- a/module/plugins/internal/Captcha.py +++ b/module/plugins/internal/Captcha.py @@ -12,7 +12,7 @@ from module.plugins.internal.Plugin import Plugin class Captcha(Plugin): __name__ = "Captcha" __type__ = "captcha" - __version__ = "0.36" + __version__ = "0.37" __status__ = "testing" __description__ = """Base anti-captcha plugin""" @@ -37,7 +37,10 @@ class Captcha(Plugin): def _log(self, level, plugintype, pluginname, messages): - return self.plugin._log(level, plugintype, pluginname, (self.__name__,) + messages) + return self.plugin._log(level, + plugintype, + "%s: %s" % (self.plugin.__name__, self.__name__), + messages) def recognize(self, image): @@ -107,7 +110,7 @@ class Captcha(Plugin): self.fail(task.error) elif not self.task.result: - self.captcha.invalid() + self.invalid() self.plugin.retry(reason=_("No captcha result obtained in appropiate time")) result = self.task.result -- cgit v1.2.3 From 91e0803c1f47444072ca7381d789a8e98160ae78 Mon Sep 17 00:00:00 2001 From: Walter Purcaro Date: Wed, 29 Jul 2015 21:11:29 +0200 Subject: Still improving _log methods --- module/plugins/internal/Captcha.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'module/plugins/internal/Captcha.py') diff --git a/module/plugins/internal/Captcha.py b/module/plugins/internal/Captcha.py index 92bcf9f84..f126ca85e 100644 --- a/module/plugins/internal/Captcha.py +++ b/module/plugins/internal/Captcha.py @@ -12,7 +12,7 @@ from module.plugins.internal.Plugin import Plugin class Captcha(Plugin): __name__ = "Captcha" __type__ = "captcha" - __version__ = "0.37" + __version__ = "0.38" __status__ = "testing" __description__ = """Base anti-captcha plugin""" @@ -39,8 +39,8 @@ class Captcha(Plugin): def _log(self, level, plugintype, pluginname, messages): return self.plugin._log(level, plugintype, - "%s: %s" % (self.plugin.__name__, self.__name__), - messages) + self.plugin.__name__, + (self.__name__,) + messages) def recognize(self, image): -- cgit v1.2.3 From dc47212c8e801d380e4db4bd1bec0bf183de9de1 Mon Sep 17 00:00:00 2001 From: Walter Purcaro Date: Fri, 31 Jul 2015 05:48:44 +0200 Subject: [Captcha] Fix _decrypt method --- module/plugins/internal/Captcha.py | 20 +++++++++----------- 1 file changed, 9 insertions(+), 11 deletions(-) (limited to 'module/plugins/internal/Captcha.py') diff --git a/module/plugins/internal/Captcha.py b/module/plugins/internal/Captcha.py index f126ca85e..14308fbf5 100644 --- a/module/plugins/internal/Captcha.py +++ b/module/plugins/internal/Captcha.py @@ -12,7 +12,7 @@ from module.plugins.internal.Plugin import Plugin class Captcha(Plugin): __name__ = "Captcha" __type__ = "captcha" - __version__ = "0.38" + __version__ = "0.39" __status__ = "testing" __description__ = """Base anti-captcha plugin""" @@ -57,7 +57,7 @@ class Captcha(Plugin): #@TODO: Definitely choose a better name for this method! - def _decrypt(self, raw, input_type='jpg', output_type='textual', ocr=None, timeout=120): + def _decrypt(self, raw, input_type='jpg', output_type='textual', ocr=False, timeout=120): """ Loads a captcha and decrypts it with ocr, plugin, user input @@ -73,31 +73,28 @@ class Captcha(Plugin): :return: result of decrypting """ + 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: tmp_img.write(raw) - if ocr is not False: + if ocr: if isinstance(ocr, basestring): OCR = self.pyload.pluginManager.loadClass("captcha", ocr) #: Rename `captcha` to `ocr` in 0.4.10 - - if self.plugin.pyfile.abort: - self.plugin.abort() - result = OCR(self.plugin).recognize(tmp_img.name) - else: result = self.recognize(tmp_img.name) - else: + if not result: captchaManager = self.pyload.captchaManager try: self.task = captchaManager.newTask(raw, input_type, tmp_img.name, output_type) + captchaManager.handleCaptcha(self.task) - self.task.setWaiting(max(timeout, 50)) #@TODO: Move to `CaptchaManager` in 0.4.10 + self.task.setWaiting(max(timeout, 50)) #@TODO: Move to `CaptchaManager` in 0.4.10 while self.task.isWaiting(): if self.plugin.pyfile.abort: self.plugin.abort() @@ -114,7 +111,6 @@ class Captcha(Plugin): self.plugin.retry(reason=_("No captcha result obtained in appropiate time")) result = self.task.result - self.log_info(_("Captcha result: ") + result) #@TODO: Remove from here? if not self.pyload.debug: try: @@ -124,6 +120,8 @@ class Captcha(Plugin): self.log_warning(_("Error removing: %s") % tmp_img.name, e) traceback.print_exc() + self.log_info(_("Captcha result: ") + result) #@TODO: Remove from here? + return result -- cgit v1.2.3 From 84f2193d76f7c6f47c834dc8902d8ead8e45a11a Mon Sep 17 00:00:00 2001 From: Walter Purcaro Date: Sun, 2 Aug 2015 07:44:07 +0200 Subject: Fix https://github.com/pyload/pyload/issues/1640 (2) --- module/plugins/internal/Captcha.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'module/plugins/internal/Captcha.py') diff --git a/module/plugins/internal/Captcha.py b/module/plugins/internal/Captcha.py index 14308fbf5..3ebe42a89 100644 --- a/module/plugins/internal/Captcha.py +++ b/module/plugins/internal/Captcha.py @@ -12,7 +12,7 @@ from module.plugins.internal.Plugin import Plugin class Captcha(Plugin): __name__ = "Captcha" __type__ = "captcha" - __version__ = "0.39" + __version__ = "0.40" __status__ = "testing" __description__ = """Base anti-captcha plugin""" @@ -21,9 +21,9 @@ class Captcha(Plugin): def __init__(self, plugin): #@TODO: Pass pyfile instead plugin, so store plugin's html in its associated pyfile as data - self.pyload = plugin.pyload + self._init(plugin.pyload) + self.plugin = plugin - self.info = {} #: Provide information in dict here self.task = None #: captchaManager task self.init() -- cgit v1.2.3 From 04f4b7aa724454a69588ecc9fa46f7dd6e65c747 Mon Sep 17 00:00:00 2001 From: Walter Purcaro Date: Sun, 2 Aug 2015 09:16:39 +0200 Subject: Fix https://github.com/pyload/pyload/issues/1630 --- module/plugins/internal/Captcha.py | 50 +++++++++++++++++++------------------- 1 file changed, 25 insertions(+), 25 deletions(-) (limited to 'module/plugins/internal/Captcha.py') diff --git a/module/plugins/internal/Captcha.py b/module/plugins/internal/Captcha.py index 3ebe42a89..8564d88d9 100644 --- a/module/plugins/internal/Captcha.py +++ b/module/plugins/internal/Captcha.py @@ -12,7 +12,7 @@ from module.plugins.internal.Plugin import Plugin class Captcha(Plugin): __name__ = "Captcha" __type__ = "captcha" - __version__ = "0.40" + __version__ = "0.41" __status__ = "testing" __description__ = """Base anti-captcha plugin""" @@ -79,38 +79,38 @@ class Captcha(Plugin): with open(os.path.join("tmp", "captcha_image_%s_%s.%s" % (self.plugin.__name__, time_ref, input_type)), "wb") as tmp_img: tmp_img.write(raw) - 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) - else: - result = self.recognize(tmp_img.name) + 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) + else: + result = self.recognize(tmp_img.name) - if not result: - captchaManager = self.pyload.captchaManager + if not result: + captchaManager = self.pyload.captchaManager - try: - self.task = captchaManager.newTask(raw, input_type, tmp_img.name, output_type) + try: + self.task = captchaManager.newTask(raw, input_type, tmp_img.name, output_type) - captchaManager.handleCaptcha(self.task) + captchaManager.handleCaptcha(self.task) - self.task.setWaiting(max(timeout, 50)) #@TODO: Move to `CaptchaManager` in 0.4.10 - while self.task.isWaiting(): - if self.plugin.pyfile.abort: - self.plugin.abort() - time.sleep(1) + self.task.setWaiting(max(timeout, 50)) #@TODO: Move to `CaptchaManager` in 0.4.10 + while self.task.isWaiting(): + if self.plugin.pyfile.abort: + self.plugin.abort() + time.sleep(1) - finally: - captchaManager.removeTask(self.task) + finally: + captchaManager.removeTask(self.task) - if self.task.error: - self.fail(task.error) + if self.task.error: + self.fail(task.error) - elif not self.task.result: - self.invalid() - self.plugin.retry(reason=_("No captcha result obtained in appropiate time")) + elif not self.task.result: + self.invalid() + self.plugin.retry(reason=_("No captcha result obtained in appropiate time")) - result = self.task.result + result = self.task.result if not self.pyload.debug: try: -- cgit v1.2.3 From 8a97cd05eda1301dd2ac915f0eb9d8a57564fb70 Mon Sep 17 00:00:00 2001 From: Walter Purcaro Date: Sun, 2 Aug 2015 10:22:15 +0200 Subject: Fix https://github.com/pyload/pyload/issues/1650 --- module/plugins/internal/Captcha.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'module/plugins/internal/Captcha.py') diff --git a/module/plugins/internal/Captcha.py b/module/plugins/internal/Captcha.py index 8564d88d9..c08050ee8 100644 --- a/module/plugins/internal/Captcha.py +++ b/module/plugins/internal/Captcha.py @@ -12,7 +12,7 @@ from module.plugins.internal.Plugin import Plugin class Captcha(Plugin): __name__ = "Captcha" __type__ = "captcha" - __version__ = "0.41" + __version__ = "0.42" __status__ = "testing" __description__ = """Base anti-captcha plugin""" @@ -104,7 +104,7 @@ class Captcha(Plugin): captchaManager.removeTask(self.task) if self.task.error: - self.fail(task.error) + self.fail(self.task.error) elif not self.task.result: self.invalid() -- cgit v1.2.3