summaryrefslogtreecommitdiffstats
path: root/module/plugins/captcha
diff options
context:
space:
mode:
authorGravatar Walter Purcaro <vuolter@gmail.com> 2014-04-11 12:18:22 +0200
committerGravatar Stefano <l.stickell@yahoo.it> 2014-04-11 12:18:22 +0200
commitd68938a9a7fbfb079b0a6de469de766b5892d769 (patch)
tree443b21cc277126fa44486bc940f8aa521f92564d /module/plugins/captcha
parentUse wait to set time in SimpleHoster plugins (diff)
downloadpyload-d68938a9a7fbfb079b0a6de469de766b5892d769.tar.xz
Remove bad whitespaces
Merges vuolter/pyload@e4b2562
Diffstat (limited to 'module/plugins/captcha')
-rw-r--r--module/plugins/captcha/GigasizeCom.py4
-rw-r--r--module/plugins/captcha/LinksaveIn.py26
-rw-r--r--module/plugins/captcha/NetloadIn.py4
-rw-r--r--module/plugins/captcha/ShareonlineBiz.py6
-rw-r--r--module/plugins/captcha/captcha.py17
5 files changed, 28 insertions, 29 deletions
diff --git a/module/plugins/captcha/GigasizeCom.py b/module/plugins/captcha/GigasizeCom.py
index d31742eb5..adf97c080 100644
--- a/module/plugins/captcha/GigasizeCom.py
+++ b/module/plugins/captcha/GigasizeCom.py
@@ -4,7 +4,7 @@ from captcha import OCR
class GigasizeCom(OCR):
def __init__(self):
OCR.__init__(self)
-
+
def get_captcha(self, image):
self.load_image(image)
self.threshold(2.8)
@@ -15,5 +15,5 @@ if __name__ == '__main__':
ocr = GigasizeCom()
import urllib
urllib.urlretrieve('http://www.gigasize.com/randomImage.php', "gigasize_tmp.jpg")
-
+
print ocr.get_captcha('gigasize_tmp.jpg')
diff --git a/module/plugins/captcha/LinksaveIn.py b/module/plugins/captcha/LinksaveIn.py
index e3cdf5a45..df885044a 100644
--- a/module/plugins/captcha/LinksaveIn.py
+++ b/module/plugins/captcha/LinksaveIn.py
@@ -11,7 +11,7 @@ class LinksaveIn(OCR):
def __init__(self):
OCR.__init__(self)
self.data_dir = dirname(abspath(__file__)) + sep + "LinksaveIn" + sep
-
+
def load_image(self, image):
im = Image.open(image)
frame_nr = 0
@@ -38,7 +38,7 @@ class LinksaveIn(OCR):
self.image = new.copy()
self.pixels = self.image.load()
self.result_captcha = ''
-
+
def get_bg(self):
stat = {}
cstat = {}
@@ -46,15 +46,15 @@ class LinksaveIn(OCR):
for bgpath in glob(self.data_dir+"bg/*.gif"):
stat[bgpath] = 0
bg = Image.open(bgpath)
-
+
bglut = bg.resize((256, 1))
bglut.putdata(range(256))
bglut = list(bglut.convert("RGB").getdata())
-
+
lut = img.resize((256, 1))
lut.putdata(range(256))
lut = list(lut.convert("RGB").getdata())
-
+
bgpix = bg.load()
pix = img.load()
for x in xrange(bg.size[0]):
@@ -74,19 +74,19 @@ class LinksaveIn(OCR):
bg = bgpath
max_p = value
return bg
-
+
def substract_bg(self, bgpath):
bg = Image.open(bgpath)
img = self.image.convert("P")
-
+
bglut = bg.resize((256, 1))
bglut.putdata(range(256))
bglut = list(bglut.convert("RGB").getdata())
-
+
lut = img.resize((256, 1))
lut.putdata(range(256))
lut = list(lut.convert("RGB").getdata())
-
+
bgpix = bg.load()
pix = img.load()
orgpix = self.image.load()
@@ -96,7 +96,7 @@ class LinksaveIn(OCR):
rgb_c = lut[pix[x, y]]
if rgb_c == rgb_bg:
orgpix[x, y] = (255,255,255)
-
+
def eval_black_white(self):
new = Image.new("RGB", (140, 75))
pix = new.load()
@@ -117,7 +117,7 @@ class LinksaveIn(OCR):
pix[x, y] = (0,0,0)
self.image = new
self.pixels = self.image.load()
-
+
def get_captcha(self, image):
self.load_image(image)
bg = self.get_bg()
@@ -135,7 +135,7 @@ class LinksaveIn(OCR):
self.image.save(ocr.data_dir+"letter%d.png" % n)
self.run_tesser(True, True, False, False)
final += self.result_captcha
-
+
return final
if __name__ == '__main__':
@@ -143,5 +143,5 @@ if __name__ == '__main__':
ocr = LinksaveIn()
testurl = "http://linksave.in/captcha/cap.php?hsh=2229185&code=ZzHdhl3UffV3lXTH5U4b7nShXj%2Bwma1vyoNBcbc6lcc%3D"
urllib.urlretrieve(testurl, ocr.data_dir+"captcha.gif")
-
+
print ocr.get_captcha(ocr.data_dir+'captcha.gif')
diff --git a/module/plugins/captcha/NetloadIn.py b/module/plugins/captcha/NetloadIn.py
index 7f2e6a8d1..b7ad9d310 100644
--- a/module/plugins/captcha/NetloadIn.py
+++ b/module/plugins/captcha/NetloadIn.py
@@ -11,9 +11,9 @@ class NetloadIn(OCR):
self.clean(3)
self.clean(3)
self.run_tesser(True, True, False, False)
-
+
self.result_captcha = self.result_captcha.replace(" ", "")[:4] # cut to 4 numbers
-
+
return self.result_captcha
if __name__ == '__main__':
diff --git a/module/plugins/captcha/ShareonlineBiz.py b/module/plugins/captcha/ShareonlineBiz.py
index b07fb9b0f..a759f80ce 100644
--- a/module/plugins/captcha/ShareonlineBiz.py
+++ b/module/plugins/captcha/ShareonlineBiz.py
@@ -21,10 +21,10 @@ from captcha import OCR
class ShareonlineBiz(OCR):
__name__ = "ShareonlineBiz"
-
+
def __init__(self):
OCR.__init__(self)
-
+
def get_captcha(self, image):
self.load_image(image)
self.to_greyscale()
@@ -35,7 +35,7 @@ class ShareonlineBiz(OCR):
#self.derotate_by_average()
letters = self.split_captcha_letters()
-
+
final = ""
for letter in letters:
self.image = letter
diff --git a/module/plugins/captcha/captcha.py b/module/plugins/captcha/captcha.py
index 66f093e40..3a854f5de 100644
--- a/module/plugins/captcha/captcha.py
+++ b/module/plugins/captcha/captcha.py
@@ -33,9 +33,9 @@ import JpegImagePlugin
class OCR(object):
-
+
__name__ = "OCR"
-
+
def __init__(self):
self.logger = logging.getLogger("log")
@@ -53,7 +53,7 @@ class OCR(object):
def run(self, command):
"""Run a command"""
-
+
popen = subprocess.Popen(command, bufsize = -1, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
popen.wait()
output = popen.stdout.read() +" | "+ popen.stderr.read()
@@ -63,8 +63,7 @@ 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 = open(join("tmp", "tmpTif_%s.tif" % self.__name__), "wb")
tmp.close()
@@ -72,7 +71,7 @@ class OCR(object):
#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')
@@ -80,7 +79,7 @@ class OCR(object):
tessparams = [join(pypath,"tesseract","tesseract.exe")]
else:
tessparams = ['tesseract']
-
+
tessparams.extend( [abspath(tmp.name), abspath(tmpTxt.name).replace(".txt", "")] )
if subset and (digits or lowercase or uppercase):
@@ -98,7 +97,7 @@ class OCR(object):
tessparams.append("nobatch")
tessparams.append(abspath(tmpSub.name))
tmpSub.close()
-
+
self.logger.debug("run tesseract")
self.run(tessparams)
self.logger.debug("read txt")
@@ -117,7 +116,7 @@ class OCR(object):
os.remove(tmpSub.name)
except:
pass
-
+
def get_captcha(self, name):
raise NotImplementedError