diff options
Diffstat (limited to 'module/plugins/captcha')
| -rw-r--r-- | module/plugins/captcha/LinksaveIn.py | 1 | ||||
| -rw-r--r-- | module/plugins/captcha/MegauploadCom.py | 1 | ||||
| -rw-r--r-- | module/plugins/captcha/NetloadIn.py | 1 | ||||
| -rw-r--r-- | module/plugins/captcha/ShareonlineBiz.py | 2 | ||||
| -rw-r--r-- | module/plugins/captcha/captcha.py | 37 | 
5 files changed, 34 insertions, 8 deletions
| diff --git a/module/plugins/captcha/LinksaveIn.py b/module/plugins/captcha/LinksaveIn.py index ff6bbebba..3ad7b265a 100644 --- a/module/plugins/captcha/LinksaveIn.py +++ b/module/plugins/captcha/LinksaveIn.py @@ -7,6 +7,7 @@ from glob import glob  class LinksaveIn(OCR): +    __name__ = "LinksaveIn"      def __init__(self):          OCR.__init__(self)          self.data_dir = dirname(abspath(__file__)) + sep + "LinksaveIn" + sep diff --git a/module/plugins/captcha/MegauploadCom.py b/module/plugins/captcha/MegauploadCom.py index da8ab2cb9..469ee4094 100644 --- a/module/plugins/captcha/MegauploadCom.py +++ b/module/plugins/captcha/MegauploadCom.py @@ -1,6 +1,7 @@  from captcha import OCR  class MegauploadCom(OCR): +    __name__ = "MegauploadCom"      def __init__(self):          OCR.__init__(self) diff --git a/module/plugins/captcha/NetloadIn.py b/module/plugins/captcha/NetloadIn.py index 75f3f2e8b..7f2e6a8d1 100644 --- a/module/plugins/captcha/NetloadIn.py +++ b/module/plugins/captcha/NetloadIn.py @@ -1,6 +1,7 @@  from captcha import OCR  class NetloadIn(OCR): +    __name__ = "NetloadIn"      def __init__(self):          OCR.__init__(self) diff --git a/module/plugins/captcha/ShareonlineBiz.py b/module/plugins/captcha/ShareonlineBiz.py index 7bd5d7960..b07fb9b0f 100644 --- a/module/plugins/captcha/ShareonlineBiz.py +++ b/module/plugins/captcha/ShareonlineBiz.py @@ -20,6 +20,8 @@  from captcha import OCR  class ShareonlineBiz(OCR): +    __name__ = "ShareonlineBiz" +          def __init__(self):          OCR.__init__(self) diff --git a/module/plugins/captcha/captcha.py b/module/plugins/captcha/captcha.py index b4a6b0a37..60705f9e8 100644 --- a/module/plugins/captcha/captcha.py +++ b/module/plugins/captcha/captcha.py @@ -20,9 +20,10 @@  from __future__ import with_statement  import os  from os.path import join +from os.path import abspath  import logging  import subprocess -import tempfile +#import tempfile  import threading  import Image @@ -54,6 +55,9 @@ class RunThread(threading.Thread):          self.result = outputdata  class OCR(object): +     +    __name__ = "OCR" +          def __init__(self):          self.logger = logging.getLogger("log") @@ -85,22 +89,30 @@ class OCR(object):      def run_tesser(self, subset=False, digits=True, lowercase=True, uppercase=True):          #self.logger.debug("create tmp tif") -        tmp = tempfile.NamedTemporaryFile(suffix=".tif") +         +         +        #tmp = tempfile.NamedTemporaryFile(suffix=".tif") +        tmp = open(join("tmp", "tmpTif_%s.tif" % self.__name__), "wb") +        tmp.close()          #self.logger.debug("create tmp txt") -        tmpTxt = tempfile.NamedTemporaryFile(suffix=".txt") +        #tmpTxt = tempfile.NamedTemporaryFile(suffix=".txt") +        tmpTxt = open(join("tmp", "tmpTxt_%s.txt" % self.__name__), "wb") +        tmpTxt.close() +                  self.logger.debug("save tiff")          self.image.save(tmp.name, 'TIFF')          if os.name == "nt": -            tessparams = [join(pydir,"tesseract","tesseract.exe")] +            tessparams = [join(pypath,"tesseract","tesseract.exe")]          else:              tessparams = ['tesseract'] -        tessparams.extend( [tmp.name, tmpTxt.name.replace(".txt", "")] ) +        tessparams.extend( [abspath(tmp.name), abspath(tmpTxt.name).replace(".txt", "")] )          if subset and (digits or lowercase or uppercase):              #self.logger.debug("create temp subset config") -            tmpSub = tempfile.NamedTemporaryFile(suffix=".subset") +            #tmpSub = tempfile.NamedTemporaryFile(suffix=".subset") +            tmpSub = open(join("tmp", "tmpSub_%s.subset" % self.__name__), "wb")              tmpSub.write("tessedit_char_whitelist ")              if digits:                  tmpSub.write("0123456789") @@ -110,8 +122,8 @@ class OCR(object):                  tmpSub.write("ABCDEFGHIJKLMNOPQRSTUVWXYZ")              tmpSub.write("\n")              tessparams.append("nobatch") -            tessparams.append(tmpSub.name) -            tmpSub.flush() +            tessparams.append(abspath(tmpSub.name)) +            tmpSub.close()          self.logger.debug("run tesseract")          self.run(tessparams) @@ -121,6 +133,15 @@ class OCR(object):              self.result_captcha = f.read().replace("\n", "")          self.logger.debug(self.result_captcha) +         +        try: +            os.remove(tmp.name) +            os.remove(tmpTxt.name) +            if subset and (digits or lowercase or uppercase): +                os.remove(tmpSub.name) +        except: +            pass +              def get_captcha(self):          raise NotImplementedError | 
