From 7dc0b955b6e3d4448c173447c700717e8cdbbe95 Mon Sep 17 00:00:00 2001 From: Walter Purcaro Date: Sun, 14 Jun 2015 19:43:37 +0200 Subject: Move OCR to internal plugin folder --- module/plugins/captcha/CircleCaptcha.py | 4 +- module/plugins/captcha/GigasizeCom.py | 4 +- module/plugins/captcha/LinksaveIn.py | 4 +- module/plugins/captcha/NetloadIn.py | 4 +- module/plugins/captcha/OCR.py | 319 ------------------------------- module/plugins/captcha/ShareonlineBiz.py | 4 +- 6 files changed, 10 insertions(+), 329 deletions(-) delete mode 100644 module/plugins/captcha/OCR.py (limited to 'module/plugins/captcha') diff --git a/module/plugins/captcha/CircleCaptcha.py b/module/plugins/captcha/CircleCaptcha.py index d4f08018d..a79198314 100644 --- a/module/plugins/captcha/CircleCaptcha.py +++ b/module/plugins/captcha/CircleCaptcha.py @@ -9,7 +9,7 @@ import math import operator import urllib -from module.plugins.captcha.OCR import OCR +from module.plugins.internal.OCR import OCR class ImageSequence: @@ -29,7 +29,7 @@ class ImageSequence: class CircleCaptcha(OCR): __name__ = "CircleCaptcha" __type__ = "ocr" - __version__ = "1.00" + __version__ = "1.01" __description__ = """Circle captcha ocr plugin""" __license__ = "GPLv3" diff --git a/module/plugins/captcha/GigasizeCom.py b/module/plugins/captcha/GigasizeCom.py index 52c41729b..66b848e3f 100644 --- a/module/plugins/captcha/GigasizeCom.py +++ b/module/plugins/captcha/GigasizeCom.py @@ -1,12 +1,12 @@ # -*- coding: utf-8 -*- -from module.plugins.captcha.OCR import OCR +from module.plugins.internal.OCR import OCR class GigasizeCom(OCR): __name__ = "GigasizeCom" __type__ = "ocr" - __version__ = "0.11" + __version__ = "0.12" __description__ = """Gigasize.com ocr plugin""" __license__ = "GPLv3" diff --git a/module/plugins/captcha/LinksaveIn.py b/module/plugins/captcha/LinksaveIn.py index 95b107977..f5cfbc97b 100644 --- a/module/plugins/captcha/LinksaveIn.py +++ b/module/plugins/captcha/LinksaveIn.py @@ -8,13 +8,13 @@ except ImportError: import glob import os -from module.plugins.captcha.OCR import OCR +from module.plugins.internal.OCR import OCR class LinksaveIn(OCR): __name__ = "LinksaveIn" __type__ = "ocr" - __version__ = "0.11" + __version__ = "0.12" __description__ = """Linksave.in ocr plugin""" __license__ = "GPLv3" diff --git a/module/plugins/captcha/NetloadIn.py b/module/plugins/captcha/NetloadIn.py index 1fb258c47..2f1477f5d 100644 --- a/module/plugins/captcha/NetloadIn.py +++ b/module/plugins/captcha/NetloadIn.py @@ -1,12 +1,12 @@ # -*- coding: utf-8 -*- -from module.plugins.captcha.OCR import OCR +from module.plugins.internal.OCR import OCR class NetloadIn(OCR): __name__ = "NetloadIn" __type__ = "ocr" - __version__ = "0.11" + __version__ = "0.12" __description__ = """Netload.in ocr plugin""" __license__ = "GPLv3" diff --git a/module/plugins/captcha/OCR.py b/module/plugins/captcha/OCR.py deleted file mode 100644 index 1874ba07d..000000000 --- a/module/plugins/captcha/OCR.py +++ /dev/null @@ -1,319 +0,0 @@ -# -*- coding: utf-8 -*- - -from __future__ import with_statement - -try: - from PIL import Image, GifImagePlugin, JpegImagePlugin, PngImagePlugin, TiffImagePlugin - -except ImportError: - import Image, GifImagePlugin, JpegImagePlugin, PngImagePlugin, TiffImagePlugin - -import logging -import os -import subprocess -#import tempfile - -from module.utils import save_join - - -class OCR(object): - __name__ = "OCR" - __type__ = "ocr" - __version__ = "0.11" - - __description__ = """OCR base plugin""" - __license__ = "GPLv3" - __authors__ = [("pyLoad Team", "admin@pyload.org")] - - - def __init__(self): - self.logger = logging.getLogger("log") - - - def load_image(self, image): - self.image = Image.open(image) - self.pixels = self.image.load() - self.result_captcha = '' - - - def unload(self): - """delete all tmp images""" - pass - - - def threshold(self, value): - self.image = self.image.point(lambda a: a * value + 10) - - - 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() - popen.stdout.close() - popen.stderr.close() - self.logger.debug("Tesseract ReturnCode %s Output: %s" % (popen.returncode, output)) - - - def run_tesser(self, subset=False, digits=True, lowercase=True, uppercase=True): - #tmpTif = tempfile.NamedTemporaryFile(suffix=".tif") - try: - tmpTif = open(save_join("tmp", "tmpTif_%s.tif" % self.__name__), "wb") - tmpTif.close() - - #tmpTxt = tempfile.NamedTemporaryFile(suffix=".txt") - tmpTxt = open(save_join("tmp", "tmpTxt_%s.txt" % self.__name__), "wb") - tmpTxt.close() - - except IOError, e: - self.logError(e) - return - - self.logger.debug("save tiff") - self.image.save(tmpTif.name, 'TIFF') - - if os.name == "nt": - tessparams = [os.path.join(pypath, "tesseract", "tesseract.exe")] - else: - tessparams = ["tesseract"] - - tessparams.extend( [os.path.abspath(tmpTif.name), os.path.abspath(tmpTxt.name).replace(".txt", "")] ) - - if subset and (digits or lowercase or uppercase): - #tmpSub = tempfile.NamedTemporaryFile(suffix=".subset") - with open(save_join("tmp", "tmpSub_%s.subset" % self.__name__), "wb") as tmpSub: - tmpSub.write("tessedit_char_whitelist ") - - if digits: - tmpSub.write("0123456789") - if lowercase: - tmpSub.write("abcdefghijklmnopqrstuvwxyz") - if uppercase: - tmpSub.write("ABCDEFGHIJKLMNOPQRSTUVWXYZ") - - tmpSub.write("\n") - tessparams.append("nobatch") - tessparams.append(os.path.abspath(tmpSub.name)) - - self.logger.debug("run tesseract") - self.run(tessparams) - self.logger.debug("read txt") - - try: - with open(tmpTxt.name, 'r') as f: - self.result_captcha = f.read().replace("\n", "") - except Exception: - self.result_captcha = "" - - self.logger.debug(self.result_captcha) - try: - os.remove(tmpTif.name) - os.remove(tmpTxt.name) - if subset and (digits or lowercase or uppercase): - os.remove(tmpSub.name) - except Exception: - pass - - - def get_captcha(self, name): - raise NotImplementedError - - - def to_greyscale(self): - if self.image.mode != 'L': - self.image = self.image.convert('L') - - self.pixels = self.image.load() - - - def eval_black_white(self, limit): - self.pixels = self.image.load() - w, h = self.image.size - for x in xrange(w): - for y in xrange(h): - if self.pixels[x, y] > limit: - self.pixels[x, y] = 255 - else: - self.pixels[x, y] = 0 - - - def clean(self, allowed): - pixels = self.pixels - - w, h = self.image.size - - for x in xrange(w): - for y in xrange(h): - if pixels[x, y] == 255: - continue - # No point in processing white pixels since we only want to remove black pixel - count = 0 - - try: - if pixels[x-1, y-1] != 255: - count += 1 - if pixels[x-1, y] != 255: - count += 1 - if pixels[x-1, y + 1] != 255: - count += 1 - if pixels[x, y + 1] != 255: - count += 1 - if pixels[x + 1, y + 1] != 255: - count += 1 - if pixels[x + 1, y] != 255: - count += 1 - if pixels[x + 1, y-1] != 255: - count += 1 - if pixels[x, y-1] != 255: - count += 1 - except Exception: - pass - - # not enough neighbors are dark pixels so mark this pixel - # to be changed to white - if count < allowed: - pixels[x, y] = 1 - - # second pass: this time set all 1's to 255 (white) - for x in xrange(w): - for y in xrange(h): - if pixels[x, y] == 1: - pixels[x, y] = 255 - - self.pixels = pixels - - - def derotate_by_average(self): - """rotate by checking each angle and guess most suitable""" - - w, h = self.image.size - pixels = self.pixels - - for x in xrange(w): - for y in xrange(h): - if pixels[x, y] == 0: - pixels[x, y] = 155 - - highest = {} - counts = {} - - for angle in xrange(-45, 45): - - tmpimage = self.image.rotate(angle) - - pixels = tmpimage.load() - - w, h = self.image.size - - for x in xrange(w): - for y in xrange(h): - if pixels[x, y] == 0: - pixels[x, y] = 255 - - - count = {} - - for x in xrange(w): - count[x] = 0 - for y in xrange(h): - if pixels[x, y] == 155: - count[x] += 1 - - sum = 0 - cnt = 0 - - for x in count.values(): - if x != 0: - sum += x - cnt += 1 - - avg = sum / cnt - counts[angle] = cnt - highest[angle] = 0 - for x in count.values(): - if x > highest[angle]: - highest[angle] = x - - highest[angle] = highest[angle] - avg - - hkey = 0 - hvalue = 0 - - for key, value in highest.iteritems(): - if value > hvalue: - hkey = key - hvalue = value - - self.image = self.image.rotate(hkey) - pixels = self.image.load() - - for x in xrange(w): - for y in xrange(h): - if pixels[x, y] == 0: - pixels[x, y] = 255 - - if pixels[x, y] == 155: - pixels[x, y] = 0 - - self.pixels = pixels - - - def split_captcha_letters(self): - captcha = self.image - started = False - letters = [] - width, height = captcha.size - bottomY, topY = 0, height - pixels = captcha.load() - - for x in xrange(width): - black_pixel_in_col = False - for y in xrange(height): - if pixels[x, y] != 255: - if not started: - started = True - firstX = x - lastX = x - - if y > bottomY: - bottomY = y - if y < topY: - topY = y - if x > lastX: - lastX = x - - black_pixel_in_col = True - - if black_pixel_in_col is False and started is True: - rect = (firstX, topY, lastX, bottomY) - new_captcha = captcha.crop(rect) - - w, h = new_captcha.size - if w > 5 and h > 5: - letters.append(new_captcha) - - started = False - bottomY, topY = 0, height - - return letters - - - def correct(self, values, var=None): - if var: - result = var - else: - result = self.result_captcha - - for key, item in values.iteritems(): - - if key.__class__ == str: - result = result.replace(key, item) - else: - for expr in key: - result = result.replace(expr, item) - - if var: - return result - else: - self.result_captcha = result diff --git a/module/plugins/captcha/ShareonlineBiz.py b/module/plugins/captcha/ShareonlineBiz.py index 6fad66600..a95435444 100644 --- a/module/plugins/captcha/ShareonlineBiz.py +++ b/module/plugins/captcha/ShareonlineBiz.py @@ -1,12 +1,12 @@ # -*- coding: utf-8 -*- -from module.plugins.captcha.OCR import OCR +from module.plugins.internal.OCR import OCR class ShareonlineBiz(OCR): __name__ = "ShareonlineBiz" __type__ = "ocr" - __version__ = "0.11" + __version__ = "0.12" __description__ = """Shareonline.biz ocr plugin""" __license__ = "GPLv3" -- cgit v1.2.3 From 164512b6a74c94a731fcee7435dce1ccfa2f71e7 Mon Sep 17 00:00:00 2001 From: Walter Purcaro Date: Wed, 17 Jun 2015 18:29:50 +0200 Subject: Spare code cosmetics --- module/plugins/captcha/CircleCaptcha.py | 3 --- 1 file changed, 3 deletions(-) (limited to 'module/plugins/captcha') diff --git a/module/plugins/captcha/CircleCaptcha.py b/module/plugins/captcha/CircleCaptcha.py index a79198314..8b59c6703 100644 --- a/module/plugins/captcha/CircleCaptcha.py +++ b/module/plugins/captcha/CircleCaptcha.py @@ -241,7 +241,6 @@ class CircleCaptcha(OCR): -1 -> Not found circle -2 -> Found black position then leave position """ - imageheight = range(int(c[1]-c[2]),int(c[1]+c[2])) imagewidth = range(int(c[0]-c[2]),int(c[0]+c[2])) @@ -323,7 +322,6 @@ class CircleCaptcha(OCR): -1 -> Not found circle -2 -> Found black position then leave position """ - imageheight = range(int(c[1]-c[2]),int(c[1]+c[2])) imagewidth = range(int(c[0]-c[2]),int(c[0]+c[2])) @@ -485,7 +483,6 @@ class CircleCaptcha(OCR): if maxX - minX < c[2] * 2 * 0.10 and maxY - minY < c[2] * 2 * 0.10: return -1; """ - if missing / howmany > 0.25 or \ missingconsecutive >= (howmany / 4) * 2 or \ howmany < 80: -- cgit v1.2.3 From 20b6a2ec022202b0efb6cb69415239fb8f4d1445 Mon Sep 17 00:00:00 2001 From: Walter Purcaro Date: Wed, 17 Jun 2015 18:59:20 +0200 Subject: Spare code cosmetics (2) --- module/plugins/captcha/CircleCaptcha.py | 294 ++++++++++++++++---------------- 1 file changed, 147 insertions(+), 147 deletions(-) (limited to 'module/plugins/captcha') diff --git a/module/plugins/captcha/CircleCaptcha.py b/module/plugins/captcha/CircleCaptcha.py index 8b59c6703..6c758d3de 100644 --- a/module/plugins/captcha/CircleCaptcha.py +++ b/module/plugins/captcha/CircleCaptcha.py @@ -59,25 +59,25 @@ class CircleCaptcha(OCR): if curpix > self.BACKGROUND: if howmany <= cleandeep and howmany > 0: - # clean pixel + #: clean pixel for ic in range(1,cleandeep+1): if x -ic > 0: pix[x-ic,y] = self.BACKGROUND jump = False howmany = 0 curcolor = curpix - # print (x, y), jump,2 + #: print (x, y), jump,2 else: if howmany == 0: - # found pixel + #: found pixel jump = True howmany = howmany + 1 curcolor = curpix - # print (x, y), jump,2 + #: print (x, y), jump,2 else: howmany = howmany + 1 if howmany == 1: - # clean pixel + #: clean pixel pix[x-1,y] = self.BACKGROUND curcolor = self.BACKGROUND @@ -86,32 +86,32 @@ class CircleCaptcha(OCR): howmany = 0 for y in imageheight: curpix = pix[x,y] - # if jump == True: + #: if jump == True: if curpix > self.BACKGROUND: if howmany <= cleandeep and howmany > 0: - # clean pixel + #: clean pixel for ic in range(1,cleandeep+1): - # raw_input('2'+str(ic)) + #: raw_input('2'+str(ic)) if y-ic > 0: pix[x,y-ic] = self.BACKGROUND jump = False howmany = 0 curcolor = curpix - # print (x, y), jump + #: print (x, y), jump else: if howmany == 0: - # found pixel + #: found pixel jump = True howmany = howmany + 1 curcolor = curpix - # print (x, y), jump + #: print (x, y), jump else: howmany = howmany + 1 if howmany == 1: - # clean pixel + #: clean pixel pix[x-1,y] = self.BACKGROUND - # return -1 + #: return -1 def findFirstPixelX(self, im, pix, curx, cury, color = -1, ExitWithBlack = False): @@ -126,21 +126,21 @@ class CircleCaptcha(OCR): if curpix < self.BLACKCOLOR: blackfound = blackfound + 1 if ExitWithBlack == True and blackfound >= 3: - break; #exit if found black + break #: exit if found black else: - continue; + continue if curpix >= self.BACKGROUND: - # found first pixel white + #: found first pixel white jump = False - continue; + continue if (curpix < self.BACKGROUND and color == -1) or (curpix == color and color > -1): if jump == False: - # found pixel + #: found pixel curcolor = curpix newx = x, curcolor - break; + break return newx @@ -156,17 +156,17 @@ class CircleCaptcha(OCR): if curpix < self.BLACKCOLOR: blackfound = blackfound + 1 if ExitWithBlack == True and blackfound >= 3: - break; #exit if found black + break #: exit if found black else: - continue; + continue if curpix >= self.BACKGROUND: if newx != (-1,-1): - # found last pixel and the first white - break; + #: found last pixel and the first white + break if (curpix < self.BACKGROUND and color == -1) or (curpix == color and color > -1): - # found pixel + #: found pixel curcolor = curpix newx = x, curcolor @@ -187,17 +187,17 @@ class CircleCaptcha(OCR): if curpix < self.BLACKCOLOR: blackfound = blackfound + 1 if ExitWithBlack == True and blackfound >= 3: - break; #exit if found black + break #: exit if found black else: - continue; + continue if curpix >= self.BACKGROUND: if newy != (-1,-1): - # found last pixel and the first white - break; + #: found last pixel and the first white + break if (curpix < self.BACKGROUND and color == -1) or (curpix == color and color > -1): - # found pixel + #: found pixel curcolor = curpix newy = y, color @@ -205,24 +205,24 @@ class CircleCaptcha(OCR): def findCircle(self, pix, x1, y1, x2, y2, x3, y3): - # trasposizione coordinate - # A(0,0) B(x2-x1,y2-y1) C(x3-x1,y3-y1) - # x**2+y**2+ax+bx+c=0 + #: trasposizione coordinate + #: A(0,0) B(x2-x1,y2-y1) C(x3-x1,y3-y1) + #: x**2+y**2+ax+bx+c=0 p1 = (0,0) p2 = (x2-x1,y2-y1) p3 = (x3-x1,y3-y1) - # 1 + #: 1 c=0 - # 2 - # p2[0]**2+a*p2[0]+c=0 - # a*p2[0]=-1*(p2[0]**2-c) - # a=(-1*(p2[0]**2-c))/p2[0] + #: 2 + #: p2[0]**2+a*p2[0]+c=0 + #: a*p2[0]=-1*(p2[0]**2-c) + #: a=(-1*(p2[0]**2-c))/p2[0] a=(-1*(p2[0]**2-c))/p2[0] - # 3 - # p3[0]**2+p3[1]**2+a*p3[0]+b*p3[1]+c=0 - # b*p3[1]=-(p3[0]**2+p3[1]**2+a*p3[0]+c) - # b=(-1 * (p3[0]**2+p3[1]**2+a*p3[0]+c)) / p3[1] + #: 3 + #: p3[0]**2+p3[1]**2+a*p3[0]+b*p3[1]+c=0 + #: b*p3[1]=-(p3[0]**2+p3[1]**2+a*p3[0]+c) + #: b=(-1 * (p3[0]**2+p3[1]**2+a*p3[0]+c)) / p3[1] b=(-1 * (p3[0]**2+p3[1]**2+a*p3[0]+c)) / p3[1] r=math.floor(math.sqrt((-1*(a/2))**2+(-1*(b/2))**2)) @@ -252,44 +252,44 @@ class CircleCaptcha(OCR): missing = 0 missingconsecutive = 0 missinglist = [] - minX = 0; maxX = 0; minY = 0; maxY = 0 + minX = 0 maxX = 0 minY = 0 maxY = 0 pointsofcircle = [] if (c[2] < min_ray) or (c[2] > max_ray): return -1 - # check cardinal points (at least 3) (if found i have to leave this position) + #: check cardinal points (at least 3) (if found i have to leave this position) if pix[c[0] + c[2],c[1]] < self.BLACKCOLOR: - return -2; + return -2 if pix[c[0] - c[2],c[1]] < self.BLACKCOLOR: - return -2; + return -2 if pix[c[0],c[1] + c[2]] < self.BLACKCOLOR: - return -2; + return -2 if pix[c[0],c[1] - c[2]] < self.BLACKCOLOR: - return -2; + return -2 cardinalpoints = 0 if self.verifyPoint(im, pix,c[0] + c[2],c[1],True) == 1: cardinalpoints = cardinalpoints + 1 if self.verifyPoint(im, pix,c[0] + c[2],c[1],False) == -1: - return -2; + return -2 if self.verifyPoint(im, pix,c[0] - c[2],c[1],True) == 1: cardinalpoints = cardinalpoints + 1 if self.verifyPoint(im, pix,c[0] - c[2],c[1],False) == -1: - return -2; + return -2 if self.verifyPoint(im, pix,c[0],c[1] + c[2],True) == 1: cardinalpoints = cardinalpoints + 1 if self.verifyPoint(im, pix,c[0],c[1] + c[2],False) == -1: - return -2; + return -2 if self.verifyPoint(im, pix,c[0],c[1] - c[2],True) == 1: cardinalpoints = cardinalpoints + 1 if self.verifyPoint(im, pix,c[0],c[1] - c[2],False) == -1: - return -2; + return -2 if cardinalpoints < 3: - return -1; + return -1 for x in imagewidth: - # Pitagora + #: Pitagora y = int(round(c[1]- math.sqrt(c[2]**2-(c[0]-x)**2))) y2= int(round(c[1]+ math.sqrt(c[2]**2-(c[0]-x)**2))) @@ -301,7 +301,7 @@ class CircleCaptcha(OCR): pointsofcircle.append((x,y)) if self.verifyPoint(im, pix, x,y,False) == -1: - return -2; + return -2 if self.verifyPoint(im, pix, x,y2,exactfind) == 0: missing = missing + 1 @@ -310,7 +310,7 @@ class CircleCaptcha(OCR): pointsofcircle.append((x,y2)) if self.verifyPoint(im, pix, x,y2,False) == -1: - return -2; + return -2 def verifyCircle(self, im, pix, c): @@ -333,44 +333,44 @@ class CircleCaptcha(OCR): missing = 0 missingconsecutive = 0 missinglist = [] - minX = 0; maxX = 0; minY = 0; maxY = 0 + minX = 0 maxX = 0 minY = 0 maxY = 0 pointsofcircle = [] if (c[2] < min_ray) or (c[2] > max_ray): return -1 - # check cardinal points (at least 3) (if found i have to leave this position) + #: check cardinal points (at least 3) (if found i have to leave this position) if pix[c[0] + c[2],c[1]] < self.BLACKCOLOR: - return -2; + return -2 if pix[c[0] - c[2],c[1]] < self.BLACKCOLOR: - return -2; + return -2 if pix[c[0],c[1] + c[2]] < self.BLACKCOLOR: - return -2; + return -2 if pix[c[0],c[1] - c[2]] < self.BLACKCOLOR: - return -2; + return -2 cardinalpoints = 0 if self.verifyPoint(im, pix,c[0] + c[2],c[1],True) == 1: cardinalpoints = cardinalpoints + 1 if self.verifyPoint(im, pix,c[0] + c[2],c[1],False) == -1: - return -2; + return -2 if self.verifyPoint(im, pix,c[0] - c[2],c[1],True) == 1: cardinalpoints = cardinalpoints + 1 if self.verifyPoint(im, pix,c[0] - c[2],c[1],False) == -1: - return -2; + return -2 if self.verifyPoint(im, pix,c[0],c[1] + c[2],True) == 1: cardinalpoints = cardinalpoints + 1 if self.verifyPoint(im, pix,c[0],c[1] + c[2],False) == -1: - return -2; + return -2 if self.verifyPoint(im, pix,c[0],c[1] - c[2],True) == 1: cardinalpoints = cardinalpoints + 1 if self.verifyPoint(im, pix,c[0],c[1] - c[2],False) == -1: - return -2; + return -2 if cardinalpoints < 3: - return -1; + return -1 for x in imagewidth: - # Pitagora + #: Pitagora y = int(round(c[1]- math.sqrt(c[2]**2-(c[0]-x)**2))) y2= int(round(c[1]+ math.sqrt(c[2]**2-(c[0]-x)**2))) @@ -382,7 +382,7 @@ class CircleCaptcha(OCR): pointsofcircle.append((x,y)) if self.verifyPoint(im, pix, x,y,False) == -1: - return -2; + return -2 if self.verifyPoint(im, pix, x,y2,exactfind) == 0: missing = missing + 1 @@ -391,10 +391,10 @@ class CircleCaptcha(OCR): pointsofcircle.append((x,y2)) if self.verifyPoint(im, pix, x,y2,False) == -1: - return -2; + return -2 for y in imageheight: - # Pitagora + #: Pitagora x = int(round(c[0]- math.sqrt(c[2]**2-(c[1]-y)**2))) x2= int(round(c[0]+ math.sqrt(c[2]**2-(c[1]-y)**2))) @@ -406,7 +406,7 @@ class CircleCaptcha(OCR): pointsofcircle.append((x,y)) if self.verifyPoint(im, pix, x,y,False) == -1: - return -2; + return -2 if self.verifyPoint(im, pix, x2,y,exactfind) == 0: missing = missing + 1 @@ -415,21 +415,21 @@ class CircleCaptcha(OCR): pointsofcircle.append((x2,y)) if self.verifyPoint(im, pix, x2,y,exactfind) == -1: - return -2; + return -2 for p in missinglist: - # left and bottom + #: left and bottom if (self.verifyPoint(im, pix, p[0]-1, p[1],exactfind) == 1 and \ self.verifyPoint(im, pix, p[0], p[1]+1,exactfind) == 1): missing = missing - 1 elif (self.verifyPoint(im, pix, p[0]-1, p[1],exactfind) == 1 and \ self.verifyPoint(im, pix, p[0], p[1]-1,exactfind) == 1): missing = missing - 1 - # right and bottom + #: right and bottom elif (self.verifyPoint(im, pix, p[0]+1, p[1],exactfind) == 1 and \ self.verifyPoint(im, pix, p[0], p[1]+1,exactfind) == 1): missing = missing - 1 - # right and up + #: right and up elif (self.verifyPoint(im, pix, p[0]+1, p[1],exactfind) == 1 and \ self.verifyPoint(im, pix, p[0], p[1]-1,exactfind) == 1): missing = missing - 1 @@ -445,7 +445,7 @@ class CircleCaptcha(OCR): self.verifyPoint(im, pix, p[0], p[1],False) == 1: missingconsecutive = missingconsecutive + 1 # else: - # pix[p[0], p[1]] = 0 + # pix[p[0], p[1]] = 0 if missing / howmany > 0: indice = c[2] * (missing / howmany) @@ -459,7 +459,7 @@ class CircleCaptcha(OCR): minY = min(missinglist, key=operator.itemgetter(1))[1] maxY = max(missinglist, key=operator.itemgetter(1))[1] - # Assial Simmetric + #: Assial Simmetric if self._DEBUG == True: print "Center: " + str(c) print "Missing: " + str(missing) @@ -471,41 +471,41 @@ class CircleCaptcha(OCR): print "Ratio without consecutives: " + str((missing - missingconsecutive) / howmany) print "List missing: " + str(missinglist) - # Lenght of missing cannot be over 75% of diameter + #: Lenght of missing cannot be over 75% of diameter if maxX - minX >= c[2] * 2 * 0.75: - return -1; + return -1 if maxY - minY >= c[2] * 2 * 0.75: - # raw_input('tro') - return -1; + #: raw_input('tro') + return -1 """ - # Lenght of missing cannot be less 10% of diameter + #: Lenght of missing cannot be less 10% of diameter if maxX - minX < c[2] * 2 * 0.10 and maxY - minY < c[2] * 2 * 0.10: - return -1; + return -1 """ if missing / howmany > 0.25 or \ missingconsecutive >= (howmany / 4) * 2 or \ howmany < 80: - return -1; - # elif missing / howmany < 0.10: + return -1 + #: elif missing / howmany < 0.10: elif missing == 0: self.pointsofcirclefound.extend(pointsofcircle) - return 1; + return 1 elif (missing - missingconsecutive) / howmany < 0.20: - return 0; + return 0 else: self.pointsofcirclefound.extend(pointsofcircle) - return 1; + return 1 def verifyPoint(self, im, pix, x,y,exact,color = -1): - # Verify point + #: Verify point result = 0 if x < 0 or x >= im.size[0]: - return result; + return result if y < 0 or y >= im.size[1]: - return result; + return result curpix = pix[x,y] if (curpix == color and color > -1) or (curpix < self.BACKGROUND and color == -1): @@ -514,7 +514,7 @@ class CircleCaptcha(OCR): else: result = -1 - # Verify around + #: Verify around if (exact == False): if x + 1 < im.size[0]: curpix = pix[x+1,y] @@ -531,7 +531,7 @@ class CircleCaptcha(OCR): result = 1 if curpix <= self.BLACKCOLOR: result = -1 - # print str((x,y)) + " = " + str(result); + #: print str((x,y)) + " = " + str(result) return result @@ -547,14 +547,14 @@ class CircleCaptcha(OCR): if self._DEBUG == True: iDebugSaveFile = iDebugSaveFile + 1 - # if iDebugSaveFile < 7: continue; + #: if iDebugSaveFile < 7: continue im.save("output" + str(iDebugSaveFile) + ".png", "png") raw_input('frame: '+ str(im)) pix = im.load() stepheight = range(1,im.size[1],2) - # stepheight = range(45,47) + #: stepheight = range(45,47) imagewidth = range(1,im.size[0]) lstPoints = [] # Declares an empty list for the points lstX = [] # CoordinateX @@ -568,14 +568,14 @@ class CircleCaptcha(OCR): draw = ImageDraw.Draw(imdebug) pixcopy = imdebug.load() - # Clean image for powerfull search + #: Clean image for powerfull search self.cleanImage(im, pix) im.save("cleaned" + str(iDebugSaveFile) + ".png", "png") found = set() findnewcircle = True - # finding all the circles + #: finding all the circles for y1 in stepheight: x1 = 1 curcolor = -1 @@ -585,17 +585,17 @@ class CircleCaptcha(OCR): x1 = retval[0] curcolor = retval[1] if x1 == -2: - break; + break if x1 == -1: - break; + break if self._DEBUG == True: print "x1, y1 -> " + str((x1,y1)) + ": " + str(pix[x1,y1]) if (x1,y1) in self.pointsofcirclefound: if self._DEBUG == True: print 'found ' + str((x1,y1)) - continue; + continue if self._DEBUG == True: pixcopy[x1,y1] = 45 #(255,0,0,255) - # found 1 pixel, seeking x2,y2 + #: found 1 pixel, seeking x2,y2 x2 = x1 y2 = y1 for i in range(1,100): @@ -603,52 +603,52 @@ class CircleCaptcha(OCR): x2 = retval[0] if x1 == -2: findnewcircle = True - break; + break if x2 == -1: - break; + break if self._DEBUG == True: print "x2, y2 -> " + str((x2,y1)) + ": " + str(pix[x2,y1]) if abs(x2 - x1) < min_distance: - continue; + continue if abs(x2 - x1) > (im.size[1] * 2 / 3): - break; + break if abs(x2 - x1) > max_diameter: - break; + break if self._DEBUG == True: pixcopy[x2,y2] = 65 #(0,255,0,255) - # found 2 pixel, seeking x3,y3 - # verify cord + #: found 2 pixel, seeking x3,y3 + #: verify cord for invert in range(0,2): x3 = math.floor(x2 - ((x2 - x1) / 2)) y3 = y1 for j in range(1,50): retval = self.findLastPixelY(im, pix, x3, y3, True if invert == 1 else False, -1, True) - # print (x3, y3,retval[0],invert) + #: print (x3, y3,retval[0],invert) y3 = retval[0] if y3 == -2: findnewcircle = True - break; + break if y3 == -1: - break; + break if self._DEBUG == True: print "x3, y3 -> " + str((x3,y3)) + ": " + str(pix[x3,y3]) - # verify cord + #: verify cord if abs(y3 - y2) < min_distance: - continue; + continue if abs(y3 - y2) > (im.size[1] * 2 / 3): - break; + break if abs(y3 - y2) > max_diameter: - break; + break if self._DEBUG == True: pixcopy[x3,y3] = 85 - # found 3 pixel. try circle + #: found 3 pixel. try circle c = self.findCircle(pix, x1,y1,x2,y2,x3,y3) if c[0] + c[2] >= im.size[0] or c[1] + c[2] >= im.size[1] or c[0] - c[2] <= 0 or c[1] - c[2] <= 0: - continue; + continue if self._DEBUG == True: pixcopy[c[0],c[1]] = 0 - # (x-r, y-r, x+r, y+r) + #: (x-r, y-r, x+r, y+r) verified = self.verifyCircle(im, pix, c) if verified == -1: @@ -662,10 +662,10 @@ class CircleCaptcha(OCR): if self._DEBUG == True: _pause = "" - # if verified == -1: - # draw.ellipse((c[0]-c[2],c[1]-c[2],c[0]+c[2],c[1]+c[2]),outline=0) - # _pause = "NOTDOUND" - # imdebug.save("debug.png", "png") + #: if verified == -1: + #: draw.ellipse((c[0]-c[2],c[1]-c[2],c[0]+c[2],c[1]+c[2]),outline=0) + #: _pause = "NOTDOUND" + #: imdebug.save("debug.png", "png") if verified == 0: draw.ellipse((c[0]-c[2],c[1]-c[2],c[0]+c[2],c[1]+c[2]),outline=120) _pause = "OPENED" @@ -679,19 +679,19 @@ class CircleCaptcha(OCR): if _pause != "": valore = raw_input('Found ' + _pause + ' CIRCLE circle press [Enter] = continue / [q] for Quit: ' + str(verified)) if valore == 'q': - sys.exit(); + sys.exit() if findnewcircle == True: - break; + break if findnewcircle == True: - break; + break if findnewcircle == True: - break; + break if self._DEBUG == True: print 'Howmany opened circle? ' + str(len(found)) + ' ' + str(found) - # clean results + #: clean results for c in found: verify = c[1] if verify == 0: @@ -707,7 +707,7 @@ class CircleCaptcha(OCR): ((p[0]-1, p[1]-1,p[2]),1) in found \ ): - # delete nearly circle + #: delete nearly circle verify = -1 if ( ((p[0], p[1]+1,p[2]+1),1) in found or \ @@ -720,7 +720,7 @@ class CircleCaptcha(OCR): ((p[0]-1, p[1]-1,p[2]+1),1) in found \ ): - # delete nearly circle + #: delete nearly circle verify = -1 if ( ((p[0], p[1]+1,p[2]-1),1) in found or \ @@ -733,38 +733,38 @@ class CircleCaptcha(OCR): ((p[0]-1, p[1]-1,p[2]-1),1) in found \ ): - # delete nearly circle + #: delete nearly circle verify = -1 - # if verify == 0: - # if self._DEBUG == True: - # pix[c[0][0],c[0][1]] = 90 #(255,255,0) - # im.save("output.png", "png") - # return c[0][0],c[0][1] - # elif verify == 1: - # if self._DEBUG == True: - # pix[c[0][0],c[0][1]] = 40 #(255,0,0) - # im.save("output.png", "png") - # else: - # if self._DEBUG == True: - # pix[c[0][0],c[0][1]] = 180 #(0,0,255) - # im.save("output.png", "png") + #: if verify == 0: + #: if self._DEBUG == True: + #: pix[c[0][0],c[0][1]] = 90 #(255,255,0) + #: im.save("output.png", "png") + #: return c[0][0],c[0][1] + #: elif verify == 1: + #: if self._DEBUG == True: + #: pix[c[0][0],c[0][1]] = 40 #(255,0,0) + #: im.save("output.png", "png") + #: else: + #: if self._DEBUG == True: + #: pix[c[0][0],c[0][1]] = 180 #(0,0,255) + #: im.save("output.png", "png") if self._DEBUG == True: im.save("output.png", "png") - # Return coordinates of opened circle (eg (x,y)) + #: Return coordinates of opened circle (eg (x,y)) def decrypt_from_web(self, url): file = cStringIO.StringIO(urllib.urlopen(url).read()) img = Image.open(file) - coords = self.decrypt(img); + coords = self.decrypt(img) print "Coords: " + str(coords) - # Return coordinates of opened circle (eg (x,y)) + #: Return coordinates of opened circle (eg (x,y)) def decrypt_from_file(self, filename): - coords = self.decrypt(Image.open(filename)); #Can be many different formats. + coords = self.decrypt(Image.open(filename)) #: Can be many different formats. print "Coords: " + str(coords) -- cgit v1.2.3 From 9305859b64a2f0aef3f27fb7e5b75caa0cb836a6 Mon Sep 17 00:00:00 2001 From: Walter Purcaro Date: Wed, 17 Jun 2015 19:24:49 +0200 Subject: Spare code cosmetics (3) --- module/plugins/captcha/CircleCaptcha.py | 244 ++++++++++++++++---------------- module/plugins/captcha/LinksaveIn.py | 10 +- 2 files changed, 127 insertions(+), 127 deletions(-) (limited to 'module/plugins/captcha') diff --git a/module/plugins/captcha/CircleCaptcha.py b/module/plugins/captcha/CircleCaptcha.py index 6c758d3de..c7a3a3fe9 100644 --- a/module/plugins/captcha/CircleCaptcha.py +++ b/module/plugins/captcha/CircleCaptcha.py @@ -46,8 +46,8 @@ class CircleCaptcha(OCR): def cleanImage(self, im, pix): cleandeep = 1 - imageheight = range(1,int(im.size[1])) - imagewidth = range(1,int(im.size[0])) + imageheight = xrange(1, int(im.size[1])) + imagewidth = xrange(1, int(im.size[0])) howmany = 0 curcolor = self.BACKGROUND @@ -55,45 +55,45 @@ class CircleCaptcha(OCR): jump = True howmany = 0 for x in imagewidth: - curpix = pix[x,y] + curpix = pix[x, y] if curpix > self.BACKGROUND: if howmany <= cleandeep and howmany > 0: #: clean pixel - for ic in range(1,cleandeep+1): + for ic in xrange(1, cleandeep+1): if x -ic > 0: - pix[x-ic,y] = self.BACKGROUND + pix[x-ic, y] = self.BACKGROUND jump = False howmany = 0 curcolor = curpix - #: print (x, y), jump,2 + #: print (x, y), jump, 2 else: if howmany == 0: #: found pixel jump = True howmany = howmany + 1 curcolor = curpix - #: print (x, y), jump,2 + #: print (x, y), jump, 2 else: howmany = howmany + 1 if howmany == 1: #: clean pixel - pix[x-1,y] = self.BACKGROUND + pix[x-1, y] = self.BACKGROUND curcolor = self.BACKGROUND for x in imagewidth: jump = True howmany = 0 for y in imageheight: - curpix = pix[x,y] + curpix = pix[x, y] #: if jump == True: if curpix > self.BACKGROUND: if howmany <= cleandeep and howmany > 0: #: clean pixel - for ic in range(1,cleandeep+1): + for ic in xrange(1, cleandeep+1): #: raw_input('2'+str(ic)) if y-ic > 0: - pix[x,y-ic] = self.BACKGROUND + pix[x, y-ic] = self.BACKGROUND jump = False howmany = 0 curcolor = curpix @@ -109,19 +109,19 @@ class CircleCaptcha(OCR): howmany = howmany + 1 if howmany == 1: #: clean pixel - pix[x-1,y] = self.BACKGROUND + pix[x-1, y] = self.BACKGROUND #: return -1 def findFirstPixelX(self, im, pix, curx, cury, color = -1, ExitWithBlack = False): - imageheight = range(1,int(im.size[1])) - imagewidth = range(curx+1,int(im.size[0])) + imageheight = xrange(1, int(im.size[1])) + imagewidth = xrange(curx+1, int(im.size[0])) jump = True newx = (-1,-1) blackfound = 0 for x in imagewidth: - curpix = pix[x,cury] + curpix = pix[x, cury] if curpix < self.BLACKCOLOR: blackfound = blackfound + 1 @@ -146,12 +146,12 @@ class CircleCaptcha(OCR): def findLastPixelX(self, im, pix, curx, cury, color = -1, ExitWithBlack = False): - imageheight = range(1,int(im.size[1])) - imagewidth = range(curx+1,int(im.size[0])) + imageheight = xrange(1, int(im.size[1])) + imagewidth = xrange(curx+1, int(im.size[0])) newx = (-1,-1) blackfound = 0 for x in imagewidth: - curpix = pix[x,cury] + curpix = pix[x, cury] if curpix < self.BLACKCOLOR: blackfound = blackfound + 1 @@ -175,14 +175,14 @@ class CircleCaptcha(OCR): def findLastPixelY(self, im, pix, curx, cury, DownToUp, color = -1, ExitWithBlack = False): if DownToUp == False: - imageheight = range(int(cury)+1,int(im.size[1])-1) + imageheight = xrange(int(cury)+1, int(im.size[1])-1) else: - imageheight = range(int(cury)-1,1,-1) - imagewidth = range(int(curx),int(im.size[0])) + imageheight = xrange(int(cury)-1, 1,-1) + imagewidth = xrange(int(curx),int(im.size[0])) newy = (-1,-1) blackfound = 0 for y in imageheight: - curpix = pix[curx,y] + curpix = pix[curx, y] if curpix < self.BLACKCOLOR: blackfound = blackfound + 1 @@ -206,11 +206,11 @@ class CircleCaptcha(OCR): def findCircle(self, pix, x1, y1, x2, y2, x3, y3): #: trasposizione coordinate - #: A(0,0) B(x2-x1,y2-y1) C(x3-x1,y3-y1) + #: A(0, 0) B(x2-x1, y2-y1) C(x3-x1, y3-y1) #: x**2+y**2+ax+bx+c=0 - p1 = (0,0) - p2 = (x2-x1,y2-y1) - p3 = (x3-x1,y3-y1) + p1 = (0, 0) + p2 = (x2-x1, y2-y1) + p3 = (x3-x1, y3-y1) #: 1 c=0 @@ -229,7 +229,7 @@ class CircleCaptcha(OCR): cx=math.floor((-1*(a/2))+x1) cy=math.floor((-1*(b/2))+y1) - return cx,cy,r + return cx, cy, r def verifyCircleNew(self, im, pix, c): @@ -241,8 +241,8 @@ class CircleCaptcha(OCR): -1 -> Not found circle -2 -> Found black position then leave position """ - imageheight = range(int(c[1]-c[2]),int(c[1]+c[2])) - imagewidth = range(int(c[0]-c[2]),int(c[0]+c[2])) + imageheight = xrange(int(c[1]-c[2]),int(c[1]+c[2])) + imagewidth = xrange(int(c[0]-c[2]),int(c[0]+c[2])) min_ray = 15 max_ray = 30 @@ -269,21 +269,21 @@ class CircleCaptcha(OCR): return -2 cardinalpoints = 0 - if self.verifyPoint(im, pix,c[0] + c[2],c[1],True) == 1: + if self.verifyPoint(im, pix, c[0] + c[2],c[1],True) == 1: cardinalpoints = cardinalpoints + 1 - if self.verifyPoint(im, pix,c[0] + c[2],c[1],False) == -1: + if self.verifyPoint(im, pix, c[0] + c[2],c[1],False) == -1: return -2 - if self.verifyPoint(im, pix,c[0] - c[2],c[1],True) == 1: + if self.verifyPoint(im, pix, c[0] - c[2],c[1],True) == 1: cardinalpoints = cardinalpoints + 1 - if self.verifyPoint(im, pix,c[0] - c[2],c[1],False) == -1: + if self.verifyPoint(im, pix, c[0] - c[2],c[1],False) == -1: return -2 - if self.verifyPoint(im, pix,c[0],c[1] + c[2],True) == 1: + if self.verifyPoint(im, pix, c[0],c[1] + c[2],True) == 1: cardinalpoints = cardinalpoints + 1 - if self.verifyPoint(im, pix,c[0],c[1] + c[2],False) == -1: + if self.verifyPoint(im, pix, c[0],c[1] + c[2],False) == -1: return -2 - if self.verifyPoint(im, pix,c[0],c[1] - c[2],True) == 1: + if self.verifyPoint(im, pix, c[0],c[1] - c[2],True) == 1: cardinalpoints = cardinalpoints + 1 - if self.verifyPoint(im, pix,c[0],c[1] - c[2],False) == -1: + if self.verifyPoint(im, pix, c[0],c[1] - c[2],False) == -1: return -2 if cardinalpoints < 3: return -1 @@ -294,22 +294,22 @@ class CircleCaptcha(OCR): y2= int(round(c[1]+ math.sqrt(c[2]**2-(c[0]-x)**2))) howmany = howmany + 2 - if self.verifyPoint(im, pix, x,y,exactfind) == 0: + if self.verifyPoint(im, pix, x, y, exactfind) == 0: missing = missing + 1 - missinglist.append((x,y)) + missinglist.append((x, y)) else: - pointsofcircle.append((x,y)) + pointsofcircle.append((x, y)) - if self.verifyPoint(im, pix, x,y,False) == -1: + if self.verifyPoint(im, pix, x, y, False) == -1: return -2 - if self.verifyPoint(im, pix, x,y2,exactfind) == 0: + if self.verifyPoint(im, pix, x, y2, exactfind) == 0: missing = missing + 1 - missinglist.append((x,y2)) + missinglist.append((x, y2)) else: - pointsofcircle.append((x,y2)) + pointsofcircle.append((x, y2)) - if self.verifyPoint(im, pix, x,y2,False) == -1: + if self.verifyPoint(im, pix, x, y2, False) == -1: return -2 @@ -322,8 +322,8 @@ class CircleCaptcha(OCR): -1 -> Not found circle -2 -> Found black position then leave position """ - imageheight = range(int(c[1]-c[2]),int(c[1]+c[2])) - imagewidth = range(int(c[0]-c[2]),int(c[0]+c[2])) + imageheight = xrange(int(c[1]-c[2]),int(c[1]+c[2])) + imagewidth = xrange(int(c[0]-c[2]),int(c[0]+c[2])) min_ray = 15 max_ray = 30 @@ -350,21 +350,21 @@ class CircleCaptcha(OCR): return -2 cardinalpoints = 0 - if self.verifyPoint(im, pix,c[0] + c[2],c[1],True) == 1: + if self.verifyPoint(im, pix, c[0] + c[2],c[1],True) == 1: cardinalpoints = cardinalpoints + 1 - if self.verifyPoint(im, pix,c[0] + c[2],c[1],False) == -1: + if self.verifyPoint(im, pix, c[0] + c[2],c[1],False) == -1: return -2 - if self.verifyPoint(im, pix,c[0] - c[2],c[1],True) == 1: + if self.verifyPoint(im, pix, c[0] - c[2],c[1],True) == 1: cardinalpoints = cardinalpoints + 1 - if self.verifyPoint(im, pix,c[0] - c[2],c[1],False) == -1: + if self.verifyPoint(im, pix, c[0] - c[2],c[1],False) == -1: return -2 - if self.verifyPoint(im, pix,c[0],c[1] + c[2],True) == 1: + if self.verifyPoint(im, pix, c[0],c[1] + c[2],True) == 1: cardinalpoints = cardinalpoints + 1 - if self.verifyPoint(im, pix,c[0],c[1] + c[2],False) == -1: + if self.verifyPoint(im, pix, c[0],c[1] + c[2],False) == -1: return -2 - if self.verifyPoint(im, pix,c[0],c[1] - c[2],True) == 1: + if self.verifyPoint(im, pix, c[0],c[1] - c[2],True) == 1: cardinalpoints = cardinalpoints + 1 - if self.verifyPoint(im, pix,c[0],c[1] - c[2],False) == -1: + if self.verifyPoint(im, pix, c[0],c[1] - c[2],False) == -1: return -2 if cardinalpoints < 3: return -1 @@ -375,22 +375,22 @@ class CircleCaptcha(OCR): y2= int(round(c[1]+ math.sqrt(c[2]**2-(c[0]-x)**2))) howmany = howmany + 2 - if self.verifyPoint(im, pix, x,y,exactfind) == 0: + if self.verifyPoint(im, pix, x, y, exactfind) == 0: missing = missing + 1 - missinglist.append((x,y)) + missinglist.append((x, y)) else: - pointsofcircle.append((x,y)) + pointsofcircle.append((x, y)) - if self.verifyPoint(im, pix, x,y,False) == -1: + if self.verifyPoint(im, pix, x, y, False) == -1: return -2 - if self.verifyPoint(im, pix, x,y2,exactfind) == 0: + if self.verifyPoint(im, pix, x, y2, exactfind) == 0: missing = missing + 1 - missinglist.append((x,y2)) + missinglist.append((x, y2)) else: - pointsofcircle.append((x,y2)) + pointsofcircle.append((x, y2)) - if self.verifyPoint(im, pix, x,y2,False) == -1: + if self.verifyPoint(im, pix, x, y2, False) == -1: return -2 for y in imageheight: @@ -399,39 +399,39 @@ class CircleCaptcha(OCR): x2= int(round(c[0]+ math.sqrt(c[2]**2-(c[1]-y)**2))) howmany = howmany + 2 - if self.verifyPoint(im, pix, x,y,exactfind) == 0: + if self.verifyPoint(im, pix, x, y, exactfind) == 0: missing = missing + 1 - missinglist.append((x,y)) + missinglist.append((x, y)) else: - pointsofcircle.append((x,y)) + pointsofcircle.append((x, y)) - if self.verifyPoint(im, pix, x,y,False) == -1: + if self.verifyPoint(im, pix, x, y, False) == -1: return -2 - if self.verifyPoint(im, pix, x2,y,exactfind) == 0: + if self.verifyPoint(im, pix, x2, y, exactfind) == 0: missing = missing + 1 - missinglist.append((x2,y)) + missinglist.append((x2, y)) else: - pointsofcircle.append((x2,y)) + pointsofcircle.append((x2, y)) - if self.verifyPoint(im, pix, x2,y,exactfind) == -1: + if self.verifyPoint(im, pix, x2, y, exactfind) == -1: return -2 for p in missinglist: #: left and bottom if (self.verifyPoint(im, pix, p[0]-1, p[1],exactfind) == 1 and \ - self.verifyPoint(im, pix, p[0], p[1]+1,exactfind) == 1): + self.verifyPoint(im, pix, p[0], p[1]+1, exactfind) == 1): missing = missing - 1 elif (self.verifyPoint(im, pix, p[0]-1, p[1],exactfind) == 1 and \ - self.verifyPoint(im, pix, p[0], p[1]-1,exactfind) == 1): + self.verifyPoint(im, pix, p[0], p[1]-1, exactfind) == 1): missing = missing - 1 #: right and bottom elif (self.verifyPoint(im, pix, p[0]+1, p[1],exactfind) == 1 and \ - self.verifyPoint(im, pix, p[0], p[1]+1,exactfind) == 1): + self.verifyPoint(im, pix, p[0], p[1]+1, exactfind) == 1): missing = missing - 1 #: right and up elif (self.verifyPoint(im, pix, p[0]+1, p[1],exactfind) == 1 and \ - self.verifyPoint(im, pix, p[0], p[1]-1,exactfind) == 1): + self.verifyPoint(im, pix, p[0], p[1]-1, exactfind) == 1): missing = missing - 1 if (p[0], p[1]+1) in missinglist or \ @@ -498,7 +498,7 @@ class CircleCaptcha(OCR): return 1 - def verifyPoint(self, im, pix, x,y,exact,color = -1): + def verifyPoint(self, im, pix, x, y, exact, color = -1): #: Verify point result = 0 @@ -507,7 +507,7 @@ class CircleCaptcha(OCR): if y < 0 or y >= im.size[1]: return result - curpix = pix[x,y] + curpix = pix[x, y] if (curpix == color and color > -1) or (curpix < self.BACKGROUND and color == -1): if curpix > self.BLACKCOLOR: result = 1 @@ -517,7 +517,7 @@ class CircleCaptcha(OCR): #: Verify around if (exact == False): if x + 1 < im.size[0]: - curpix = pix[x+1,y] + curpix = pix[x+1, y] if (curpix == color and color > -1) or (curpix < self.BACKGROUND and color == -1): if curpix > self.BLACKCOLOR: result = 1 @@ -525,13 +525,13 @@ class CircleCaptcha(OCR): result = -1 if x > 0: - curpix = pix[x-1,y] + curpix = pix[x-1, y] if (curpix == color and color > -1) or (curpix < self.BACKGROUND and color == -1): if curpix > self.BLACKCOLOR: result = 1 if curpix <= self.BLACKCOLOR: result = -1 - #: print str((x,y)) + " = " + str(result) + #: print str((x, y)) + " = " + str(result) return result @@ -553,9 +553,9 @@ class CircleCaptcha(OCR): pix = im.load() - stepheight = range(1,im.size[1],2) - #: stepheight = range(45,47) - imagewidth = range(1,im.size[0]) + stepheight = xrange(1, im.size[1],2) + #: stepheight = xrange(45, 47) + imagewidth = xrange(1, im.size[0]) lstPoints = [] # Declares an empty list for the points lstX = [] # CoordinateX lstY = [] # CoordinateY @@ -579,7 +579,7 @@ class CircleCaptcha(OCR): for y1 in stepheight: x1 = 1 curcolor = -1 - for k in range(1,100): + for k in xrange(1, 100): findnewcircle = False retval = self.findFirstPixelX(im, pix, x1, y1, -1, False) x1 = retval[0] @@ -588,17 +588,17 @@ class CircleCaptcha(OCR): break if x1 == -1: break - if self._DEBUG == True: print "x1, y1 -> " + str((x1,y1)) + ": " + str(pix[x1,y1]) + if self._DEBUG == True: print "x1, y1 -> " + str((x1, y1)) + ": " + str(pix[x1, y1]) - if (x1,y1) in self.pointsofcirclefound: - if self._DEBUG == True: print 'found ' + str((x1,y1)) + if (x1, y1) in self.pointsofcirclefound: + if self._DEBUG == True: print 'found ' + str((x1, y1)) continue - if self._DEBUG == True: pixcopy[x1,y1] = 45 #(255,0,0,255) - #: found 1 pixel, seeking x2,y2 + if self._DEBUG == True: pixcopy[x1, y1] = 45 #(255, 0, 0, 255) + #: found 1 pixel, seeking x2, y2 x2 = x1 y2 = y1 - for i in range(1,100): + for i in xrange(1, 100): retval = self.findLastPixelX(im, pix, x2, y2, -1, True) x2 = retval[0] if x1 == -2: @@ -606,7 +606,7 @@ class CircleCaptcha(OCR): break if x2 == -1: break - if self._DEBUG == True: print "x2, y2 -> " + str((x2,y1)) + ": " + str(pix[x2,y1]) + if self._DEBUG == True: print "x2, y2 -> " + str((x2, y1)) + ": " + str(pix[x2, y1]) if abs(x2 - x1) < min_distance: continue if abs(x2 - x1) > (im.size[1] * 2 / 3): @@ -614,16 +614,16 @@ class CircleCaptcha(OCR): if abs(x2 - x1) > max_diameter: break - if self._DEBUG == True: pixcopy[x2,y2] = 65 #(0,255,0,255) - #: found 2 pixel, seeking x3,y3 + if self._DEBUG == True: pixcopy[x2, y2] = 65 #(0, 255, 0, 255) + #: found 2 pixel, seeking x3, y3 #: verify cord - for invert in range(0,2): + for invert in xrange(0, 2): x3 = math.floor(x2 - ((x2 - x1) / 2)) y3 = y1 - for j in range(1,50): + for j in xrange(1, 50): retval = self.findLastPixelY(im, pix, x3, y3, True if invert == 1 else False, -1, True) - #: print (x3, y3,retval[0],invert) + #: print (x3, y3, retval[0],invert) y3 = retval[0] if y3 == -2: findnewcircle = True @@ -631,7 +631,7 @@ class CircleCaptcha(OCR): if y3 == -1: break - if self._DEBUG == True: print "x3, y3 -> " + str((x3,y3)) + ": " + str(pix[x3,y3]) + if self._DEBUG == True: print "x3, y3 -> " + str((x3, y3)) + ": " + str(pix[x3, y3]) #: verify cord if abs(y3 - y2) < min_distance: continue @@ -640,9 +640,9 @@ class CircleCaptcha(OCR): if abs(y3 - y2) > max_diameter: break - if self._DEBUG == True: pixcopy[x3,y3] = 85 + if self._DEBUG == True: pixcopy[x3, y3] = 85 #: found 3 pixel. try circle - c = self.findCircle(pix, x1,y1,x2,y2,x3,y3) + c = self.findCircle(pix, x1, y1, x2, y2, x3, y3) if c[0] + c[2] >= im.size[0] or c[1] + c[2] >= im.size[1] or c[0] - c[2] <= 0 or c[1] - c[2] <= 0: continue @@ -697,40 +697,40 @@ class CircleCaptcha(OCR): if verify == 0: p = c[0] if ( - ((p[0], p[1]+1,p[2]),1) in found or \ - ((p[0], p[1]-1,p[2]),1) in found or \ + ((p[0], p[1]+1, p[2]),1) in found or \ + ((p[0], p[1]-1, p[2]),1) in found or \ ((p[0]+1, p[1],p[2]),1) in found or \ ((p[0]-1, p[1],p[2]),1) in found or \ - ((p[0]+1, p[1]+1,p[2]),1) in found or \ - ((p[0]-1, p[1]+1,p[2]),1) in found or \ - ((p[0]+1, p[1]-1,p[2]),1) in found or \ - ((p[0]-1, p[1]-1,p[2]),1) in found \ + ((p[0]+1, p[1]+1, p[2]),1) in found or \ + ((p[0]-1, p[1]+1, p[2]),1) in found or \ + ((p[0]+1, p[1]-1, p[2]),1) in found or \ + ((p[0]-1, p[1]-1, p[2]),1) in found \ ): #: delete nearly circle verify = -1 if ( - ((p[0], p[1]+1,p[2]+1),1) in found or \ - ((p[0], p[1]-1,p[2]+1),1) in found or \ + ((p[0], p[1]+1, p[2]+1),1) in found or \ + ((p[0], p[1]-1, p[2]+1),1) in found or \ ((p[0]+1, p[1],p[2]+1),1) in found or \ ((p[0]-1, p[1],p[2]+1),1) in found or \ - ((p[0]+1, p[1]+1,p[2]+1),1) in found or \ - ((p[0]-1, p[1]+1,p[2]+1),1) in found or \ - ((p[0]+1, p[1]-1,p[2]+1),1) in found or \ - ((p[0]-1, p[1]-1,p[2]+1),1) in found \ + ((p[0]+1, p[1]+1, p[2]+1),1) in found or \ + ((p[0]-1, p[1]+1, p[2]+1),1) in found or \ + ((p[0]+1, p[1]-1, p[2]+1),1) in found or \ + ((p[0]-1, p[1]-1, p[2]+1),1) in found \ ): #: delete nearly circle verify = -1 if ( - ((p[0], p[1]+1,p[2]-1),1) in found or \ - ((p[0], p[1]-1,p[2]-1),1) in found or \ + ((p[0], p[1]+1, p[2]-1),1) in found or \ + ((p[0], p[1]-1, p[2]-1),1) in found or \ ((p[0]+1, p[1],p[2]-1),1) in found or \ ((p[0]-1, p[1],p[2]-1),1) in found or \ - ((p[0]+1, p[1]+1,p[2]-1),1) in found or \ - ((p[0]-1, p[1]+1,p[2]-1),1) in found or \ - ((p[0]+1, p[1]-1,p[2]-1),1) in found or \ - ((p[0]-1, p[1]-1,p[2]-1),1) in found \ + ((p[0]+1, p[1]+1, p[2]-1),1) in found or \ + ((p[0]-1, p[1]+1, p[2]-1),1) in found or \ + ((p[0]+1, p[1]-1, p[2]-1),1) in found or \ + ((p[0]-1, p[1]-1, p[2]-1),1) in found \ ): #: delete nearly circle @@ -738,23 +738,23 @@ class CircleCaptcha(OCR): #: if verify == 0: #: if self._DEBUG == True: - #: pix[c[0][0],c[0][1]] = 90 #(255,255,0) + #: pix[c[0][0],c[0][1]] = 90 #(255, 255, 0) #: im.save("output.png", "png") #: return c[0][0],c[0][1] #: elif verify == 1: #: if self._DEBUG == True: - #: pix[c[0][0],c[0][1]] = 40 #(255,0,0) + #: pix[c[0][0],c[0][1]] = 40 #(255, 0, 0) #: im.save("output.png", "png") #: else: #: if self._DEBUG == True: - #: pix[c[0][0],c[0][1]] = 180 #(0,0,255) + #: pix[c[0][0],c[0][1]] = 180 #(0, 0, 255) #: im.save("output.png", "png") if self._DEBUG == True: im.save("output.png", "png") - #: Return coordinates of opened circle (eg (x,y)) + #: Return coordinates of opened circle (eg (x, y)) def decrypt_from_web(self, url): file = cStringIO.StringIO(urllib.urlopen(url).read()) img = Image.open(file) @@ -762,7 +762,7 @@ class CircleCaptcha(OCR): print "Coords: " + str(coords) - #: Return coordinates of opened circle (eg (x,y)) + #: Return coordinates of opened circle (eg (x, y)) def decrypt_from_file(self, filename): coords = self.decrypt(Image.open(filename)) #: Can be many different formats. print "Coords: " + str(coords) diff --git a/module/plugins/captcha/LinksaveIn.py b/module/plugins/captcha/LinksaveIn.py index f5cfbc97b..7aeffbe79 100644 --- a/module/plugins/captcha/LinksaveIn.py +++ b/module/plugins/captcha/LinksaveIn.py @@ -31,7 +31,7 @@ class LinksaveIn(OCR): frame_nr = 0 lut = im.resize((256, 1)) - lut.putdata(range(256)) + lut.putdata(xrange(256)) lut = list(lut.convert("RGB").getdata()) new = Image.new("RGB", im.size) @@ -63,11 +63,11 @@ class LinksaveIn(OCR): bg = Image.open(bgpath) bglut = bg.resize((256, 1)) - bglut.putdata(range(256)) + bglut.putdata(xrange(256)) bglut = list(bglut.convert("RGB").getdata()) lut = img.resize((256, 1)) - lut.putdata(range(256)) + lut.putdata(xrange(256)) lut = list(lut.convert("RGB").getdata()) bgpix = bg.load() @@ -96,11 +96,11 @@ class LinksaveIn(OCR): img = self.image.convert("P") bglut = bg.resize((256, 1)) - bglut.putdata(range(256)) + bglut.putdata(xrange(256)) bglut = list(bglut.convert("RGB").getdata()) lut = img.resize((256, 1)) - lut.putdata(range(256)) + lut.putdata(xrange(256)) lut = list(lut.convert("RGB").getdata()) bgpix = bg.load() -- 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/captcha/CircleCaptcha.py | 104 +++++++++++++++---------------- module/plugins/captcha/GigasizeCom.py | 2 +- module/plugins/captcha/LinksaveIn.py | 2 +- module/plugins/captcha/NetloadIn.py | 2 +- module/plugins/captcha/ShareonlineBiz.py | 8 +-- 5 files changed, 59 insertions(+), 59 deletions(-) (limited to 'module/plugins/captcha') diff --git a/module/plugins/captcha/CircleCaptcha.py b/module/plugins/captcha/CircleCaptcha.py index c7a3a3fe9..54bd5a975 100644 --- a/module/plugins/captcha/CircleCaptcha.py +++ b/module/plugins/captcha/CircleCaptcha.py @@ -29,7 +29,7 @@ class ImageSequence: class CircleCaptcha(OCR): __name__ = "CircleCaptcha" __type__ = "ocr" - __version__ = "1.01" + __version__ = "1.02" __description__ = """Circle captcha ocr plugin""" __license__ = "GPLv3" @@ -43,7 +43,7 @@ class CircleCaptcha(OCR): BLACKCOLOR = 5 - def cleanImage(self, im, pix): + def clean_image(self, im, pix): cleandeep = 1 imageheight = xrange(1, int(im.size[1])) @@ -114,7 +114,7 @@ class CircleCaptcha(OCR): #: return -1 - def findFirstPixelX(self, im, pix, curx, cury, color = -1, ExitWithBlack = False): + def find_first_pixel_x(self, im, pix, curx, cury, color = -1, ExitWithBlack = False): imageheight = xrange(1, int(im.size[1])) imagewidth = xrange(curx+1, int(im.size[0])) jump = True @@ -145,7 +145,7 @@ class CircleCaptcha(OCR): return newx - def findLastPixelX(self, im, pix, curx, cury, color = -1, ExitWithBlack = False): + def find_last_pixel_x(self, im, pix, curx, cury, color = -1, ExitWithBlack = False): imageheight = xrange(1, int(im.size[1])) imagewidth = xrange(curx+1, int(im.size[0])) newx = (-1,-1) @@ -173,7 +173,7 @@ class CircleCaptcha(OCR): return newx - def findLastPixelY(self, im, pix, curx, cury, DownToUp, color = -1, ExitWithBlack = False): + def find_last_pixel_y(self, im, pix, curx, cury, DownToUp, color = -1, ExitWithBlack = False): if DownToUp == False: imageheight = xrange(int(cury)+1, int(im.size[1])-1) else: @@ -204,7 +204,7 @@ class CircleCaptcha(OCR): return newy - def findCircle(self, pix, x1, y1, x2, y2, x3, y3): + def find_circle(self, pix, x1, y1, x2, y2, x3, y3): #: trasposizione coordinate #: A(0, 0) B(x2-x1, y2-y1) C(x3-x1, y3-y1) #: x**2+y**2+ax+bx+c=0 @@ -232,7 +232,7 @@ class CircleCaptcha(OCR): return cx, cy, r - def verifyCircleNew(self, im, pix, c): + def verify_circle_new(self, im, pix, c): """ This is the MAIN function to recognize the circle returns: @@ -269,21 +269,21 @@ class CircleCaptcha(OCR): return -2 cardinalpoints = 0 - if self.verifyPoint(im, pix, c[0] + c[2],c[1],True) == 1: + if self.verify_point(im, pix, c[0] + c[2],c[1],True) == 1: cardinalpoints = cardinalpoints + 1 - if self.verifyPoint(im, pix, c[0] + c[2],c[1],False) == -1: + if self.verify_point(im, pix, c[0] + c[2],c[1],False) == -1: return -2 - if self.verifyPoint(im, pix, c[0] - c[2],c[1],True) == 1: + if self.verify_point(im, pix, c[0] - c[2],c[1],True) == 1: cardinalpoints = cardinalpoints + 1 - if self.verifyPoint(im, pix, c[0] - c[2],c[1],False) == -1: + if self.verify_point(im, pix, c[0] - c[2],c[1],False) == -1: return -2 - if self.verifyPoint(im, pix, c[0],c[1] + c[2],True) == 1: + if self.verify_point(im, pix, c[0],c[1] + c[2],True) == 1: cardinalpoints = cardinalpoints + 1 - if self.verifyPoint(im, pix, c[0],c[1] + c[2],False) == -1: + if self.verify_point(im, pix, c[0],c[1] + c[2],False) == -1: return -2 - if self.verifyPoint(im, pix, c[0],c[1] - c[2],True) == 1: + if self.verify_point(im, pix, c[0],c[1] - c[2],True) == 1: cardinalpoints = cardinalpoints + 1 - if self.verifyPoint(im, pix, c[0],c[1] - c[2],False) == -1: + if self.verify_point(im, pix, c[0],c[1] - c[2],False) == -1: return -2 if cardinalpoints < 3: return -1 @@ -294,26 +294,26 @@ class CircleCaptcha(OCR): y2= int(round(c[1]+ math.sqrt(c[2]**2-(c[0]-x)**2))) howmany = howmany + 2 - if self.verifyPoint(im, pix, x, y, exactfind) == 0: + if self.verify_point(im, pix, x, y, exactfind) == 0: missing = missing + 1 missinglist.append((x, y)) else: pointsofcircle.append((x, y)) - if self.verifyPoint(im, pix, x, y, False) == -1: + if self.verify_point(im, pix, x, y, False) == -1: return -2 - if self.verifyPoint(im, pix, x, y2, exactfind) == 0: + if self.verify_point(im, pix, x, y2, exactfind) == 0: missing = missing + 1 missinglist.append((x, y2)) else: pointsofcircle.append((x, y2)) - if self.verifyPoint(im, pix, x, y2, False) == -1: + if self.verify_point(im, pix, x, y2, False) == -1: return -2 - def verifyCircle(self, im, pix, c): + def verify_circle(self, im, pix, c): """ This is the MAIN function to recognize the circle returns: @@ -350,21 +350,21 @@ class CircleCaptcha(OCR): return -2 cardinalpoints = 0 - if self.verifyPoint(im, pix, c[0] + c[2],c[1],True) == 1: + if self.verify_point(im, pix, c[0] + c[2],c[1],True) == 1: cardinalpoints = cardinalpoints + 1 - if self.verifyPoint(im, pix, c[0] + c[2],c[1],False) == -1: + if self.verify_point(im, pix, c[0] + c[2],c[1],False) == -1: return -2 - if self.verifyPoint(im, pix, c[0] - c[2],c[1],True) == 1: + if self.verify_point(im, pix, c[0] - c[2],c[1],True) == 1: cardinalpoints = cardinalpoints + 1 - if self.verifyPoint(im, pix, c[0] - c[2],c[1],False) == -1: + if self.verify_point(im, pix, c[0] - c[2],c[1],False) == -1: return -2 - if self.verifyPoint(im, pix, c[0],c[1] + c[2],True) == 1: + if self.verify_point(im, pix, c[0],c[1] + c[2],True) == 1: cardinalpoints = cardinalpoints + 1 - if self.verifyPoint(im, pix, c[0],c[1] + c[2],False) == -1: + if self.verify_point(im, pix, c[0],c[1] + c[2],False) == -1: return -2 - if self.verifyPoint(im, pix, c[0],c[1] - c[2],True) == 1: + if self.verify_point(im, pix, c[0],c[1] - c[2],True) == 1: cardinalpoints = cardinalpoints + 1 - if self.verifyPoint(im, pix, c[0],c[1] - c[2],False) == -1: + if self.verify_point(im, pix, c[0],c[1] - c[2],False) == -1: return -2 if cardinalpoints < 3: return -1 @@ -375,22 +375,22 @@ class CircleCaptcha(OCR): y2= int(round(c[1]+ math.sqrt(c[2]**2-(c[0]-x)**2))) howmany = howmany + 2 - if self.verifyPoint(im, pix, x, y, exactfind) == 0: + if self.verify_point(im, pix, x, y, exactfind) == 0: missing = missing + 1 missinglist.append((x, y)) else: pointsofcircle.append((x, y)) - if self.verifyPoint(im, pix, x, y, False) == -1: + if self.verify_point(im, pix, x, y, False) == -1: return -2 - if self.verifyPoint(im, pix, x, y2, exactfind) == 0: + if self.verify_point(im, pix, x, y2, exactfind) == 0: missing = missing + 1 missinglist.append((x, y2)) else: pointsofcircle.append((x, y2)) - if self.verifyPoint(im, pix, x, y2, False) == -1: + if self.verify_point(im, pix, x, y2, False) == -1: return -2 for y in imageheight: @@ -399,39 +399,39 @@ class CircleCaptcha(OCR): x2= int(round(c[0]+ math.sqrt(c[2]**2-(c[1]-y)**2))) howmany = howmany + 2 - if self.verifyPoint(im, pix, x, y, exactfind) == 0: + if self.verify_point(im, pix, x, y, exactfind) == 0: missing = missing + 1 missinglist.append((x, y)) else: pointsofcircle.append((x, y)) - if self.verifyPoint(im, pix, x, y, False) == -1: + if self.verify_point(im, pix, x, y, False) == -1: return -2 - if self.verifyPoint(im, pix, x2, y, exactfind) == 0: + if self.verify_point(im, pix, x2, y, exactfind) == 0: missing = missing + 1 missinglist.append((x2, y)) else: pointsofcircle.append((x2, y)) - if self.verifyPoint(im, pix, x2, y, exactfind) == -1: + if self.verify_point(im, pix, x2, y, exactfind) == -1: return -2 for p in missinglist: #: left and bottom - if (self.verifyPoint(im, pix, p[0]-1, p[1],exactfind) == 1 and \ - self.verifyPoint(im, pix, p[0], p[1]+1, exactfind) == 1): + if (self.verify_point(im, pix, p[0]-1, p[1],exactfind) == 1 and \ + self.verify_point(im, pix, p[0], p[1]+1, exactfind) == 1): missing = missing - 1 - elif (self.verifyPoint(im, pix, p[0]-1, p[1],exactfind) == 1 and \ - self.verifyPoint(im, pix, p[0], p[1]-1, exactfind) == 1): + elif (self.verify_point(im, pix, p[0]-1, p[1],exactfind) == 1 and \ + self.verify_point(im, pix, p[0], p[1]-1, exactfind) == 1): missing = missing - 1 #: right and bottom - elif (self.verifyPoint(im, pix, p[0]+1, p[1],exactfind) == 1 and \ - self.verifyPoint(im, pix, p[0], p[1]+1, exactfind) == 1): + elif (self.verify_point(im, pix, p[0]+1, p[1],exactfind) == 1 and \ + self.verify_point(im, pix, p[0], p[1]+1, exactfind) == 1): missing = missing - 1 #: right and up - elif (self.verifyPoint(im, pix, p[0]+1, p[1],exactfind) == 1 and \ - self.verifyPoint(im, pix, p[0], p[1]-1, exactfind) == 1): + elif (self.verify_point(im, pix, p[0]+1, p[1],exactfind) == 1 and \ + self.verify_point(im, pix, p[0], p[1]-1, exactfind) == 1): missing = missing - 1 if (p[0], p[1]+1) in missinglist or \ @@ -442,7 +442,7 @@ class CircleCaptcha(OCR): (p[0]-1, p[1]+1) in missinglist or \ (p[0]+1, p[1]-1) in missinglist or \ (p[0]-1, p[1]-1) in missinglist or \ - self.verifyPoint(im, pix, p[0], p[1],False) == 1: + self.verify_point(im, pix, p[0], p[1],False) == 1: missingconsecutive = missingconsecutive + 1 # else: # pix[p[0], p[1]] = 0 @@ -498,7 +498,7 @@ class CircleCaptcha(OCR): return 1 - def verifyPoint(self, im, pix, x, y, exact, color = -1): + def verify_point(self, im, pix, x, y, exact, color = -1): #: Verify point result = 0 @@ -569,7 +569,7 @@ class CircleCaptcha(OCR): pixcopy = imdebug.load() #: Clean image for powerfull search - self.cleanImage(im, pix) + self.clean_image(im, pix) im.save("cleaned" + str(iDebugSaveFile) + ".png", "png") found = set() @@ -581,7 +581,7 @@ class CircleCaptcha(OCR): curcolor = -1 for k in xrange(1, 100): findnewcircle = False - retval = self.findFirstPixelX(im, pix, x1, y1, -1, False) + retval = self.find_first_pixel_x(im, pix, x1, y1, -1, False) x1 = retval[0] curcolor = retval[1] if x1 == -2: @@ -599,7 +599,7 @@ class CircleCaptcha(OCR): x2 = x1 y2 = y1 for i in xrange(1, 100): - retval = self.findLastPixelX(im, pix, x2, y2, -1, True) + retval = self.find_last_pixel_x(im, pix, x2, y2, -1, True) x2 = retval[0] if x1 == -2: findnewcircle = True @@ -622,7 +622,7 @@ class CircleCaptcha(OCR): x3 = math.floor(x2 - ((x2 - x1) / 2)) y3 = y1 for j in xrange(1, 50): - retval = self.findLastPixelY(im, pix, x3, y3, True if invert == 1 else False, -1, True) + retval = self.find_last_pixel_y(im, pix, x3, y3, True if invert == 1 else False, -1, True) #: print (x3, y3, retval[0],invert) y3 = retval[0] if y3 == -2: @@ -642,14 +642,14 @@ class CircleCaptcha(OCR): if self._DEBUG == True: pixcopy[x3, y3] = 85 #: found 3 pixel. try circle - c = self.findCircle(pix, x1, y1, x2, y2, x3, y3) + c = self.find_circle(pix, x1, y1, x2, y2, x3, y3) if c[0] + c[2] >= im.size[0] or c[1] + c[2] >= im.size[1] or c[0] - c[2] <= 0 or c[1] - c[2] <= 0: continue if self._DEBUG == True: pixcopy[c[0],c[1]] = 0 #: (x-r, y-r, x+r, y+r) - verified = self.verifyCircle(im, pix, c) + verified = self.verify_circle(im, pix, c) if verified == -1: verified = -1 diff --git a/module/plugins/captcha/GigasizeCom.py b/module/plugins/captcha/GigasizeCom.py index 66b848e3f..83fc393e4 100644 --- a/module/plugins/captcha/GigasizeCom.py +++ b/module/plugins/captcha/GigasizeCom.py @@ -6,7 +6,7 @@ from module.plugins.internal.OCR import OCR class GigasizeCom(OCR): __name__ = "GigasizeCom" __type__ = "ocr" - __version__ = "0.12" + __version__ = "0.13" __description__ = """Gigasize.com ocr plugin""" __license__ = "GPLv3" diff --git a/module/plugins/captcha/LinksaveIn.py b/module/plugins/captcha/LinksaveIn.py index 7aeffbe79..cf00acf15 100644 --- a/module/plugins/captcha/LinksaveIn.py +++ b/module/plugins/captcha/LinksaveIn.py @@ -14,7 +14,7 @@ from module.plugins.internal.OCR import OCR class LinksaveIn(OCR): __name__ = "LinksaveIn" __type__ = "ocr" - __version__ = "0.12" + __version__ = "0.13" __description__ = """Linksave.in ocr plugin""" __license__ = "GPLv3" diff --git a/module/plugins/captcha/NetloadIn.py b/module/plugins/captcha/NetloadIn.py index 2f1477f5d..16902128d 100644 --- a/module/plugins/captcha/NetloadIn.py +++ b/module/plugins/captcha/NetloadIn.py @@ -6,7 +6,7 @@ from module.plugins.internal.OCR import OCR class NetloadIn(OCR): __name__ = "NetloadIn" __type__ = "ocr" - __version__ = "0.12" + __version__ = "0.13" __description__ = """Netload.in ocr plugin""" __license__ = "GPLv3" diff --git a/module/plugins/captcha/ShareonlineBiz.py b/module/plugins/captcha/ShareonlineBiz.py index a95435444..a8c1a3abe 100644 --- a/module/plugins/captcha/ShareonlineBiz.py +++ b/module/plugins/captcha/ShareonlineBiz.py @@ -6,7 +6,7 @@ from module.plugins.internal.OCR import OCR class ShareonlineBiz(OCR): __name__ = "ShareonlineBiz" __type__ = "ocr" - __version__ = "0.12" + __version__ = "0.13" __description__ = """Shareonline.biz ocr plugin""" __license__ = "GPLv3" @@ -23,8 +23,8 @@ class ShareonlineBiz(OCR): self.image = self.image.resize((160, 50)) self.pixels = self.image.load() self.threshold(1.85) - #self.eval_black_white(240) - #self.derotate_by_average() + # self.eval_black_white(240) + # self.derotate_by_average() letters = self.split_captcha_letters() @@ -36,4 +36,4 @@ class ShareonlineBiz(OCR): return final - #tesseract at 60% + # tesseract at 60% -- cgit v1.2.3 From 9e5d813d7721e351ac02ba72bdc473a7d77ba6b7 Mon Sep 17 00:00:00 2001 From: Walter Purcaro Date: Sat, 18 Jul 2015 20:04:36 +0200 Subject: Code cosmetics --- module/plugins/captcha/LinksaveIn.py | 1 + 1 file changed, 1 insertion(+) (limited to 'module/plugins/captcha') diff --git a/module/plugins/captcha/LinksaveIn.py b/module/plugins/captcha/LinksaveIn.py index cf00acf15..a9fe2d630 100644 --- a/module/plugins/captcha/LinksaveIn.py +++ b/module/plugins/captcha/LinksaveIn.py @@ -2,6 +2,7 @@ try: from PIL import Image + except ImportError: import Image -- 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/captcha/CircleCaptcha.py | 120 ++++++++++++++++--------------- module/plugins/captcha/ShareonlineBiz.py | 2 +- 2 files changed, 63 insertions(+), 59 deletions(-) (limited to 'module/plugins/captcha') diff --git a/module/plugins/captcha/CircleCaptcha.py b/module/plugins/captcha/CircleCaptcha.py index 54bd5a975..a76cbc679 100644 --- a/module/plugins/captcha/CircleCaptcha.py +++ b/module/plugins/captcha/CircleCaptcha.py @@ -59,25 +59,25 @@ class CircleCaptcha(OCR): if curpix > self.BACKGROUND: if howmany <= cleandeep and howmany > 0: - #: clean pixel + #: Clean pixel for ic in xrange(1, cleandeep+1): if x -ic > 0: pix[x-ic, y] = self.BACKGROUND jump = False howmany = 0 curcolor = curpix - #: print (x, y), jump, 2 + # print (x, y), jump, 2 else: if howmany == 0: - #: found pixel + #: Found pixel jump = True howmany = howmany + 1 curcolor = curpix - #: print (x, y), jump, 2 + # print (x, y), jump, 2 else: howmany = howmany + 1 if howmany == 1: - #: clean pixel + #: Clean pixel pix[x-1, y] = self.BACKGROUND curcolor = self.BACKGROUND @@ -86,10 +86,10 @@ class CircleCaptcha(OCR): howmany = 0 for y in imageheight: curpix = pix[x, y] - #: if jump == True: + # if jump == True: if curpix > self.BACKGROUND: if howmany <= cleandeep and howmany > 0: - #: clean pixel + #: Clean pixel for ic in xrange(1, cleandeep+1): #: raw_input('2'+str(ic)) if y-ic > 0: @@ -97,18 +97,18 @@ class CircleCaptcha(OCR): jump = False howmany = 0 curcolor = curpix - #: print (x, y), jump + # print (x, y), jump else: if howmany == 0: - #: found pixel + #: Found pixel jump = True howmany = howmany + 1 curcolor = curpix - #: print (x, y), jump + # print (x, y), jump else: howmany = howmany + 1 if howmany == 1: - #: clean pixel + #: Clean pixel pix[x-1, y] = self.BACKGROUND #: return -1 @@ -126,18 +126,18 @@ class CircleCaptcha(OCR): if curpix < self.BLACKCOLOR: blackfound = blackfound + 1 if ExitWithBlack == True and blackfound >= 3: - break #: exit if found black + break #: Exit if found black else: continue if curpix >= self.BACKGROUND: - #: found first pixel white + #: Found first pixel white jump = False continue if (curpix < self.BACKGROUND and color == -1) or (curpix == color and color > -1): if jump == False: - #: found pixel + #: Found pixel curcolor = curpix newx = x, curcolor break @@ -156,17 +156,17 @@ class CircleCaptcha(OCR): if curpix < self.BLACKCOLOR: blackfound = blackfound + 1 if ExitWithBlack == True and blackfound >= 3: - break #: exit if found black + break #: Exit if found black else: continue if curpix >= self.BACKGROUND: if newx != (-1,-1): - #: found last pixel and the first white + #: Found last pixel and the first white break if (curpix < self.BACKGROUND and color == -1) or (curpix == color and color > -1): - #: found pixel + #: Found pixel curcolor = curpix newx = x, curcolor @@ -187,17 +187,17 @@ class CircleCaptcha(OCR): if curpix < self.BLACKCOLOR: blackfound = blackfound + 1 if ExitWithBlack == True and blackfound >= 3: - break #: exit if found black + break #: Exit if found black else: continue if curpix >= self.BACKGROUND: if newy != (-1,-1): - #: found last pixel and the first white + #: Found last pixel and the first white break if (curpix < self.BACKGROUND and color == -1) or (curpix == color and color > -1): - #: found pixel + #: Found pixel curcolor = curpix newy = y, color @@ -205,7 +205,7 @@ class CircleCaptcha(OCR): def find_circle(self, pix, x1, y1, x2, y2, x3, y3): - #: trasposizione coordinate + #: Trasposizione coordinate #: A(0, 0) B(x2-x1, y2-y1) C(x3-x1, y3-y1) #: x**2+y**2+ax+bx+c=0 p1 = (0, 0) @@ -258,7 +258,7 @@ class CircleCaptcha(OCR): if (c[2] < min_ray) or (c[2] > max_ray): return -1 - #: check cardinal points (at least 3) (if found i have to leave this position) + #: Check cardinal points (at least 3) (if found i have to leave this position) if pix[c[0] + c[2],c[1]] < self.BLACKCOLOR: return -2 if pix[c[0] - c[2],c[1]] < self.BLACKCOLOR: @@ -339,7 +339,7 @@ class CircleCaptcha(OCR): if (c[2] < min_ray) or (c[2] > max_ray): return -1 - #: check cardinal points (at least 3) (if found i have to leave this position) + #: Check cardinal points (at least 3) (if found i have to leave this position) if pix[c[0] + c[2],c[1]] < self.BLACKCOLOR: return -2 if pix[c[0] - c[2],c[1]] < self.BLACKCOLOR: @@ -418,18 +418,18 @@ class CircleCaptcha(OCR): return -2 for p in missinglist: - #: left and bottom + #: Left and bottom if (self.verify_point(im, pix, p[0]-1, p[1],exactfind) == 1 and \ self.verify_point(im, pix, p[0], p[1]+1, exactfind) == 1): missing = missing - 1 elif (self.verify_point(im, pix, p[0]-1, p[1],exactfind) == 1 and \ self.verify_point(im, pix, p[0], p[1]-1, exactfind) == 1): missing = missing - 1 - #: right and bottom + #: Right and bottom elif (self.verify_point(im, pix, p[0]+1, p[1],exactfind) == 1 and \ self.verify_point(im, pix, p[0], p[1]+1, exactfind) == 1): missing = missing - 1 - #: right and up + #: Right and up elif (self.verify_point(im, pix, p[0]+1, p[1],exactfind) == 1 and \ self.verify_point(im, pix, p[0], p[1]-1, exactfind) == 1): missing = missing - 1 @@ -487,7 +487,7 @@ class CircleCaptcha(OCR): missingconsecutive >= (howmany / 4) * 2 or \ howmany < 80: return -1 - #: elif missing / howmany < 0.10: + # elif missing / howmany < 0.10: elif missing == 0: self.pointsofcirclefound.extend(pointsofcircle) return 1 @@ -531,7 +531,7 @@ class CircleCaptcha(OCR): result = 1 if curpix <= self.BLACKCOLOR: result = -1 - #: print str((x, y)) + " = " + str(result) + # print str((x, y)) + " = " + str(result) return result @@ -547,7 +547,7 @@ class CircleCaptcha(OCR): if self._DEBUG == True: iDebugSaveFile = iDebugSaveFile + 1 - #: if iDebugSaveFile < 7: continue + # if iDebugSaveFile < 7: continue im.save("output" + str(iDebugSaveFile) + ".png", "png") raw_input('frame: '+ str(im)) @@ -575,7 +575,7 @@ class CircleCaptcha(OCR): found = set() findnewcircle = True - #: finding all the circles + #: Finding all the circles for y1 in stepheight: x1 = 1 curcolor = -1 @@ -588,10 +588,12 @@ class CircleCaptcha(OCR): break if x1 == -1: break - if self._DEBUG == True: print "x1, y1 -> " + str((x1, y1)) + ": " + str(pix[x1, y1]) + if self._DEBUG == True: + print "x1, y1 -> " + str((x1, y1)) + ": " + str(pix[x1, y1]) if (x1, y1) in self.pointsofcirclefound: - if self._DEBUG == True: print 'found ' + str((x1, y1)) + if self._DEBUG == True: + print 'found ' + str((x1, y1)) continue if self._DEBUG == True: pixcopy[x1, y1] = 45 #(255, 0, 0, 255) @@ -606,7 +608,8 @@ class CircleCaptcha(OCR): break if x2 == -1: break - if self._DEBUG == True: print "x2, y2 -> " + str((x2, y1)) + ": " + str(pix[x2, y1]) + if self._DEBUG == True: + print "x2, y2 -> " + str((x2, y1)) + ": " + str(pix[x2, y1]) if abs(x2 - x1) < min_distance: continue if abs(x2 - x1) > (im.size[1] * 2 / 3): @@ -616,14 +619,14 @@ class CircleCaptcha(OCR): if self._DEBUG == True: pixcopy[x2, y2] = 65 #(0, 255, 0, 255) #: found 2 pixel, seeking x3, y3 - #: verify cord + #: Verify cord for invert in xrange(0, 2): x3 = math.floor(x2 - ((x2 - x1) / 2)) y3 = y1 for j in xrange(1, 50): retval = self.find_last_pixel_y(im, pix, x3, y3, True if invert == 1 else False, -1, True) - #: print (x3, y3, retval[0],invert) + # print (x3, y3, retval[0],invert) y3 = retval[0] if y3 == -2: findnewcircle = True @@ -631,8 +634,9 @@ class CircleCaptcha(OCR): if y3 == -1: break - if self._DEBUG == True: print "x3, y3 -> " + str((x3, y3)) + ": " + str(pix[x3, y3]) - #: verify cord + if self._DEBUG == True: + print "x3, y3 -> " + str((x3, y3)) + ": " + str(pix[x3, y3]) + #: Verify cord if abs(y3 - y2) < min_distance: continue if abs(y3 - y2) > (im.size[1] * 2 / 3): @@ -662,10 +666,10 @@ class CircleCaptcha(OCR): if self._DEBUG == True: _pause = "" - #: if verified == -1: - #: draw.ellipse((c[0]-c[2],c[1]-c[2],c[0]+c[2],c[1]+c[2]),outline=0) - #: _pause = "NOTDOUND" - #: imdebug.save("debug.png", "png") + # if verified == -1: + # draw.ellipse((c[0]-c[2],c[1]-c[2],c[0]+c[2],c[1]+c[2]),outline=0) + # _pause = "NOTDOUND" + # imdebug.save("debug.png", "png") if verified == 0: draw.ellipse((c[0]-c[2],c[1]-c[2],c[0]+c[2],c[1]+c[2]),outline=120) _pause = "OPENED" @@ -691,7 +695,7 @@ class CircleCaptcha(OCR): if self._DEBUG == True: print 'Howmany opened circle? ' + str(len(found)) + ' ' + str(found) - #: clean results + #: Clean results for c in found: verify = c[1] if verify == 0: @@ -707,7 +711,7 @@ class CircleCaptcha(OCR): ((p[0]-1, p[1]-1, p[2]),1) in found \ ): - #: delete nearly circle + #: Delete nearly circle verify = -1 if ( ((p[0], p[1]+1, p[2]+1),1) in found or \ @@ -720,7 +724,7 @@ class CircleCaptcha(OCR): ((p[0]-1, p[1]-1, p[2]+1),1) in found \ ): - #: delete nearly circle + #: Delete nearly circle verify = -1 if ( ((p[0], p[1]+1, p[2]-1),1) in found or \ @@ -733,22 +737,22 @@ class CircleCaptcha(OCR): ((p[0]-1, p[1]-1, p[2]-1),1) in found \ ): - #: delete nearly circle + #: Delete nearly circle verify = -1 - #: if verify == 0: - #: if self._DEBUG == True: - #: pix[c[0][0],c[0][1]] = 90 #(255, 255, 0) - #: im.save("output.png", "png") - #: return c[0][0],c[0][1] - #: elif verify == 1: - #: if self._DEBUG == True: - #: pix[c[0][0],c[0][1]] = 40 #(255, 0, 0) - #: im.save("output.png", "png") - #: else: - #: if self._DEBUG == True: - #: pix[c[0][0],c[0][1]] = 180 #(0, 0, 255) - #: im.save("output.png", "png") + # if verify == 0: + # if self._DEBUG == True: + # pix[c[0][0],c[0][1]] = 90 #(255, 255, 0) + # im.save("output.png", "png") + # return c[0][0],c[0][1] + # elif verify == 1: + # if self._DEBUG == True: + # pix[c[0][0],c[0][1]] = 40 #(255, 0, 0) + # im.save("output.png", "png") + # else: + # if self._DEBUG == True: + # pix[c[0][0],c[0][1]] = 180 #(0, 0, 255) + # im.save("output.png", "png") if self._DEBUG == True: im.save("output.png", "png") diff --git a/module/plugins/captcha/ShareonlineBiz.py b/module/plugins/captcha/ShareonlineBiz.py index a8c1a3abe..234f39a51 100644 --- a/module/plugins/captcha/ShareonlineBiz.py +++ b/module/plugins/captcha/ShareonlineBiz.py @@ -36,4 +36,4 @@ class ShareonlineBiz(OCR): return final - # tesseract at 60% + #: Tesseract at 60% -- cgit v1.2.3 From ff9383bfe06d14d23bc0ed6af79aa8967965d078 Mon Sep 17 00:00:00 2001 From: Walter Purcaro Date: Sun, 19 Jul 2015 10:59:52 +0200 Subject: Code cosmetics (3) --- module/plugins/captcha/LinksaveIn.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'module/plugins/captcha') diff --git a/module/plugins/captcha/LinksaveIn.py b/module/plugins/captcha/LinksaveIn.py index a9fe2d630..f263f4588 100644 --- a/module/plugins/captcha/LinksaveIn.py +++ b/module/plugins/captcha/LinksaveIn.py @@ -52,7 +52,7 @@ class LinksaveIn(OCR): new.save(self.data_dir+"unblacked.png") self.image = new.copy() self.pixels = self.image.load() - self.result_captcha = '' + self.result_captcha = "" def get_bg(self): -- cgit v1.2.3 From 33e2b36605e41962a2e8eee304a7f3d29690ffa8 Mon Sep 17 00:00:00 2001 From: Walter Purcaro Date: Sun, 19 Jul 2015 13:42:29 +0200 Subject: [OCR] Fix __init__ (2) --- module/plugins/captcha/GigasizeCom.py | 6 +----- module/plugins/captcha/LinksaveIn.py | 5 ++--- module/plugins/captcha/NetloadIn.py | 6 +----- module/plugins/captcha/ShareonlineBiz.py | 6 +----- 4 files changed, 5 insertions(+), 18 deletions(-) (limited to 'module/plugins/captcha') diff --git a/module/plugins/captcha/GigasizeCom.py b/module/plugins/captcha/GigasizeCom.py index 83fc393e4..8ec8e367b 100644 --- a/module/plugins/captcha/GigasizeCom.py +++ b/module/plugins/captcha/GigasizeCom.py @@ -6,17 +6,13 @@ from module.plugins.internal.OCR import OCR class GigasizeCom(OCR): __name__ = "GigasizeCom" __type__ = "ocr" - __version__ = "0.13" + __version__ = "0.14" __description__ = """Gigasize.com ocr plugin""" __license__ = "GPLv3" __authors__ = [("pyLoad Team", "admin@pyload.org")] - def __init__(self): - OCR.__init__(self) - - def get_captcha(self, image): self.load_image(image) self.threshold(2.8) diff --git a/module/plugins/captcha/LinksaveIn.py b/module/plugins/captcha/LinksaveIn.py index f263f4588..23944369b 100644 --- a/module/plugins/captcha/LinksaveIn.py +++ b/module/plugins/captcha/LinksaveIn.py @@ -15,15 +15,14 @@ from module.plugins.internal.OCR import OCR class LinksaveIn(OCR): __name__ = "LinksaveIn" __type__ = "ocr" - __version__ = "0.13" + __version__ = "0.14" __description__ = """Linksave.in ocr plugin""" __license__ = "GPLv3" __authors__ = [("pyLoad Team", "admin@pyload.org")] - def __init__(self): - OCR.__init__(self) + def init(self): self.data_dir = os.path.dirname(os.path.abspath(__file__)) + os.sep + "LinksaveIn" + os.sep diff --git a/module/plugins/captcha/NetloadIn.py b/module/plugins/captcha/NetloadIn.py index 16902128d..bc31eaaff 100644 --- a/module/plugins/captcha/NetloadIn.py +++ b/module/plugins/captcha/NetloadIn.py @@ -6,17 +6,13 @@ from module.plugins.internal.OCR import OCR class NetloadIn(OCR): __name__ = "NetloadIn" __type__ = "ocr" - __version__ = "0.13" + __version__ = "0.14" __description__ = """Netload.in ocr plugin""" __license__ = "GPLv3" __authors__ = [("pyLoad Team", "admin@pyload.org")] - def __init__(self): - OCR.__init__(self) - - def get_captcha(self, image): self.load_image(image) self.to_greyscale() diff --git a/module/plugins/captcha/ShareonlineBiz.py b/module/plugins/captcha/ShareonlineBiz.py index 234f39a51..b96781f9b 100644 --- a/module/plugins/captcha/ShareonlineBiz.py +++ b/module/plugins/captcha/ShareonlineBiz.py @@ -6,17 +6,13 @@ from module.plugins.internal.OCR import OCR class ShareonlineBiz(OCR): __name__ = "ShareonlineBiz" __type__ = "ocr" - __version__ = "0.13" + __version__ = "0.14" __description__ = """Shareonline.biz ocr plugin""" __license__ = "GPLv3" __authors__ = [("RaNaN", "RaNaN@pyload.org")] - def __init__(self): - OCR.__init__(self) - - def get_captcha(self, image): self.load_image(image) self.to_greyscale() -- 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/captcha/CircleCaptcha.py | 1 + module/plugins/captcha/GigasizeCom.py | 1 + module/plugins/captcha/LinksaveIn.py | 1 + module/plugins/captcha/NetloadIn.py | 1 + module/plugins/captcha/ShareonlineBiz.py | 1 + 5 files changed, 5 insertions(+) (limited to 'module/plugins/captcha') diff --git a/module/plugins/captcha/CircleCaptcha.py b/module/plugins/captcha/CircleCaptcha.py index a76cbc679..4c7a82d95 100644 --- a/module/plugins/captcha/CircleCaptcha.py +++ b/module/plugins/captcha/CircleCaptcha.py @@ -30,6 +30,7 @@ class CircleCaptcha(OCR): __name__ = "CircleCaptcha" __type__ = "ocr" __version__ = "1.02" + __status__ = "stable" __description__ = """Circle captcha ocr plugin""" __license__ = "GPLv3" diff --git a/module/plugins/captcha/GigasizeCom.py b/module/plugins/captcha/GigasizeCom.py index 8ec8e367b..19ad9d680 100644 --- a/module/plugins/captcha/GigasizeCom.py +++ b/module/plugins/captcha/GigasizeCom.py @@ -7,6 +7,7 @@ class GigasizeCom(OCR): __name__ = "GigasizeCom" __type__ = "ocr" __version__ = "0.14" + __status__ = "stable" __description__ = """Gigasize.com ocr plugin""" __license__ = "GPLv3" diff --git a/module/plugins/captcha/LinksaveIn.py b/module/plugins/captcha/LinksaveIn.py index 23944369b..68704f21d 100644 --- a/module/plugins/captcha/LinksaveIn.py +++ b/module/plugins/captcha/LinksaveIn.py @@ -16,6 +16,7 @@ class LinksaveIn(OCR): __name__ = "LinksaveIn" __type__ = "ocr" __version__ = "0.14" + __status__ = "stable" __description__ = """Linksave.in ocr plugin""" __license__ = "GPLv3" diff --git a/module/plugins/captcha/NetloadIn.py b/module/plugins/captcha/NetloadIn.py index bc31eaaff..b6ba2b6e9 100644 --- a/module/plugins/captcha/NetloadIn.py +++ b/module/plugins/captcha/NetloadIn.py @@ -7,6 +7,7 @@ class NetloadIn(OCR): __name__ = "NetloadIn" __type__ = "ocr" __version__ = "0.14" + __status__ = "stable" __description__ = """Netload.in ocr plugin""" __license__ = "GPLv3" diff --git a/module/plugins/captcha/ShareonlineBiz.py b/module/plugins/captcha/ShareonlineBiz.py index b96781f9b..7f25f164d 100644 --- a/module/plugins/captcha/ShareonlineBiz.py +++ b/module/plugins/captcha/ShareonlineBiz.py @@ -7,6 +7,7 @@ class ShareonlineBiz(OCR): __name__ = "ShareonlineBiz" __type__ = "ocr" __version__ = "0.14" + __status__ = "stable" __description__ = """Shareonline.biz ocr plugin""" __license__ = "GPLv3" -- cgit v1.2.3 From 4fc28dc09f9632eb4a15a1ef48778427f9dcae33 Mon Sep 17 00:00:00 2001 From: Walter Purcaro Date: Thu, 23 Jul 2015 18:53:06 +0200 Subject: Code cosmetics --- module/plugins/captcha/CircleCaptcha.py | 237 ++++++++++++++++---------------- 1 file changed, 122 insertions(+), 115 deletions(-) (limited to 'module/plugins/captcha') diff --git a/module/plugins/captcha/CircleCaptcha.py b/module/plugins/captcha/CircleCaptcha.py index 4c7a82d95..a93defb13 100644 --- a/module/plugins/captcha/CircleCaptcha.py +++ b/module/plugins/captcha/CircleCaptcha.py @@ -1,4 +1,6 @@ # -*- coding: utf-8 -*- +# +#@TODO: Recheck all from __future__ import division @@ -67,14 +69,14 @@ class CircleCaptcha(OCR): jump = False howmany = 0 curcolor = curpix - # print (x, y), jump, 2 + # self.log_debug(x, y, jump, 2) else: if howmany == 0: #: Found pixel jump = True howmany = howmany + 1 curcolor = curpix - # print (x, y), jump, 2 + # self.log_debug(x, y, jump, 2) else: howmany = howmany + 1 if howmany == 1: @@ -98,14 +100,14 @@ class CircleCaptcha(OCR): jump = False howmany = 0 curcolor = curpix - # print (x, y), jump + # self.log_debug(x, y, jump) else: if howmany == 0: #: Found pixel jump = True howmany = howmany + 1 curcolor = curpix - # print (x, y), jump + # self.log_debug(x, y, jump) else: howmany = howmany + 1 if howmany == 1: @@ -119,7 +121,7 @@ class CircleCaptcha(OCR): imageheight = xrange(1, int(im.size[1])) imagewidth = xrange(curx+1, int(im.size[0])) jump = True - newx = (-1,-1) + newx = (-1, -1) blackfound = 0 for x in imagewidth: curpix = pix[x, cury] @@ -149,7 +151,7 @@ class CircleCaptcha(OCR): def find_last_pixel_x(self, im, pix, curx, cury, color = -1, ExitWithBlack = False): imageheight = xrange(1, int(im.size[1])) imagewidth = xrange(curx+1, int(im.size[0])) - newx = (-1,-1) + newx = (-1, -1) blackfound = 0 for x in imagewidth: curpix = pix[x, cury] @@ -162,7 +164,7 @@ class CircleCaptcha(OCR): continue if curpix >= self.BACKGROUND: - if newx != (-1,-1): + if newx != (-1, -1): #: Found last pixel and the first white break @@ -178,9 +180,9 @@ class CircleCaptcha(OCR): if DownToUp == False: imageheight = xrange(int(cury)+1, int(im.size[1])-1) else: - imageheight = xrange(int(cury)-1, 1,-1) - imagewidth = xrange(int(curx),int(im.size[0])) - newy = (-1,-1) + imageheight = xrange(int(cury)-1, 1, -1) + imagewidth = xrange(int(curx), int(im.size[0])) + newy = (-1, -1) blackfound = 0 for y in imageheight: curpix = pix[curx, y] @@ -193,7 +195,7 @@ class CircleCaptcha(OCR): continue if curpix >= self.BACKGROUND: - if newy != (-1,-1): + if newy != (-1, -1): #: Found last pixel and the first white break @@ -242,8 +244,8 @@ class CircleCaptcha(OCR): -1 -> Not found circle -2 -> Found black position then leave position """ - imageheight = xrange(int(c[1]-c[2]),int(c[1]+c[2])) - imagewidth = xrange(int(c[0]-c[2]),int(c[0]+c[2])) + imageheight = xrange(int(c[1]-c[2]), int(c[1]+c[2])) + imagewidth = xrange(int(c[0]-c[2]), int(c[0]+c[2])) min_ray = 15 max_ray = 30 @@ -260,31 +262,31 @@ class CircleCaptcha(OCR): return -1 #: Check cardinal points (at least 3) (if found i have to leave this position) - if pix[c[0] + c[2],c[1]] < self.BLACKCOLOR: + if pix[c[0] + c[2], c[1]] < self.BLACKCOLOR: return -2 - if pix[c[0] - c[2],c[1]] < self.BLACKCOLOR: + if pix[c[0] - c[2], c[1]] < self.BLACKCOLOR: return -2 - if pix[c[0],c[1] + c[2]] < self.BLACKCOLOR: + if pix[c[0], c[1] + c[2]] < self.BLACKCOLOR: return -2 - if pix[c[0],c[1] - c[2]] < self.BLACKCOLOR: + if pix[c[0], c[1] - c[2]] < self.BLACKCOLOR: return -2 cardinalpoints = 0 - if self.verify_point(im, pix, c[0] + c[2],c[1],True) == 1: + if self.verify_point(im, pix, c[0] + c[2], c[1], True) == 1: cardinalpoints = cardinalpoints + 1 - if self.verify_point(im, pix, c[0] + c[2],c[1],False) == -1: + if self.verify_point(im, pix, c[0] + c[2], c[1], False) == -1: return -2 - if self.verify_point(im, pix, c[0] - c[2],c[1],True) == 1: + if self.verify_point(im, pix, c[0] - c[2], c[1], True) == 1: cardinalpoints = cardinalpoints + 1 - if self.verify_point(im, pix, c[0] - c[2],c[1],False) == -1: + if self.verify_point(im, pix, c[0] - c[2], c[1], False) == -1: return -2 - if self.verify_point(im, pix, c[0],c[1] + c[2],True) == 1: + if self.verify_point(im, pix, c[0], c[1] + c[2], True) == 1: cardinalpoints = cardinalpoints + 1 - if self.verify_point(im, pix, c[0],c[1] + c[2],False) == -1: + if self.verify_point(im, pix, c[0], c[1] + c[2], False) == -1: return -2 - if self.verify_point(im, pix, c[0],c[1] - c[2],True) == 1: + if self.verify_point(im, pix, c[0], c[1] - c[2], True) == 1: cardinalpoints = cardinalpoints + 1 - if self.verify_point(im, pix, c[0],c[1] - c[2],False) == -1: + if self.verify_point(im, pix, c[0], c[1] - c[2], False) == -1: return -2 if cardinalpoints < 3: return -1 @@ -323,8 +325,8 @@ class CircleCaptcha(OCR): -1 -> Not found circle -2 -> Found black position then leave position """ - imageheight = xrange(int(c[1]-c[2]),int(c[1]+c[2])) - imagewidth = xrange(int(c[0]-c[2]),int(c[0]+c[2])) + imageheight = xrange(int(c[1]-c[2]), int(c[1]+c[2])) + imagewidth = xrange(int(c[0]-c[2]), int(c[0]+c[2])) min_ray = 15 max_ray = 30 @@ -341,31 +343,31 @@ class CircleCaptcha(OCR): return -1 #: Check cardinal points (at least 3) (if found i have to leave this position) - if pix[c[0] + c[2],c[1]] < self.BLACKCOLOR: + if pix[c[0] + c[2], c[1]] < self.BLACKCOLOR: return -2 - if pix[c[0] - c[2],c[1]] < self.BLACKCOLOR: + if pix[c[0] - c[2], c[1]] < self.BLACKCOLOR: return -2 - if pix[c[0],c[1] + c[2]] < self.BLACKCOLOR: + if pix[c[0], c[1] + c[2]] < self.BLACKCOLOR: return -2 - if pix[c[0],c[1] - c[2]] < self.BLACKCOLOR: + if pix[c[0], c[1] - c[2]] < self.BLACKCOLOR: return -2 cardinalpoints = 0 - if self.verify_point(im, pix, c[0] + c[2],c[1],True) == 1: + if self.verify_point(im, pix, c[0] + c[2], c[1], True) == 1: cardinalpoints = cardinalpoints + 1 - if self.verify_point(im, pix, c[0] + c[2],c[1],False) == -1: + if self.verify_point(im, pix, c[0] + c[2], c[1], False) == -1: return -2 - if self.verify_point(im, pix, c[0] - c[2],c[1],True) == 1: + if self.verify_point(im, pix, c[0] - c[2], c[1], True) == 1: cardinalpoints = cardinalpoints + 1 - if self.verify_point(im, pix, c[0] - c[2],c[1],False) == -1: + if self.verify_point(im, pix, c[0] - c[2], c[1], False) == -1: return -2 - if self.verify_point(im, pix, c[0],c[1] + c[2],True) == 1: + if self.verify_point(im, pix, c[0], c[1] + c[2], True) == 1: cardinalpoints = cardinalpoints + 1 - if self.verify_point(im, pix, c[0],c[1] + c[2],False) == -1: + if self.verify_point(im, pix, c[0], c[1] + c[2], False) == -1: return -2 - if self.verify_point(im, pix, c[0],c[1] - c[2],True) == 1: + if self.verify_point(im, pix, c[0], c[1] - c[2], True) == 1: cardinalpoints = cardinalpoints + 1 - if self.verify_point(im, pix, c[0],c[1] - c[2],False) == -1: + if self.verify_point(im, pix, c[0], c[1] - c[2], False) == -1: return -2 if cardinalpoints < 3: return -1 @@ -420,18 +422,18 @@ class CircleCaptcha(OCR): for p in missinglist: #: Left and bottom - if (self.verify_point(im, pix, p[0]-1, p[1],exactfind) == 1 and \ + if (self.verify_point(im, pix, p[0]-1, p[1], exactfind) == 1 and \ self.verify_point(im, pix, p[0], p[1]+1, exactfind) == 1): missing = missing - 1 - elif (self.verify_point(im, pix, p[0]-1, p[1],exactfind) == 1 and \ + elif (self.verify_point(im, pix, p[0]-1, p[1], exactfind) == 1 and \ self.verify_point(im, pix, p[0], p[1]-1, exactfind) == 1): missing = missing - 1 #: Right and bottom - elif (self.verify_point(im, pix, p[0]+1, p[1],exactfind) == 1 and \ + elif (self.verify_point(im, pix, p[0]+1, p[1], exactfind) == 1 and \ self.verify_point(im, pix, p[0], p[1]+1, exactfind) == 1): missing = missing - 1 #: Right and up - elif (self.verify_point(im, pix, p[0]+1, p[1],exactfind) == 1 and \ + elif (self.verify_point(im, pix, p[0]+1, p[1], exactfind) == 1 and \ self.verify_point(im, pix, p[0], p[1]-1, exactfind) == 1): missing = missing - 1 @@ -443,7 +445,7 @@ class CircleCaptcha(OCR): (p[0]-1, p[1]+1) in missinglist or \ (p[0]+1, p[1]-1) in missinglist or \ (p[0]-1, p[1]-1) in missinglist or \ - self.verify_point(im, pix, p[0], p[1],False) == 1: + self.verify_point(im, pix, p[0], p[1], False) == 1: missingconsecutive = missingconsecutive + 1 # else: # pix[p[0], p[1]] = 0 @@ -461,16 +463,16 @@ class CircleCaptcha(OCR): maxY = max(missinglist, key=operator.itemgetter(1))[1] #: Assial Simmetric - if self._DEBUG == True: - print "Center: " + str(c) - print "Missing: " + str(missing) - print "Howmany: " + str(howmany) - print "Ratio: " + str(missing / howmany) - print "Missing consecutives: " + str(missingconsecutive) - print "Missing X lenght: " + str(minX) + ":" + str(maxX) - print "Missing Y lenght: " + str(minY) + ":" + str(maxY) - print "Ratio without consecutives: " + str((missing - missingconsecutive) / howmany) - print "List missing: " + str(missinglist) + if self.pyload.debug: + self.log_debug("Center: " + str(c), + "Missing: " + str(missing), + "Howmany: " + str(howmany), + "Ratio: " + str(missing / howmany), + "Missing consecutives: " + str(missingconsecutive), + "Missing X lenght: " + str(minX) + ":" + str(maxX), + "Missing Y lenght: " + str(minY) + ":" + str(maxY), + "Ratio without consecutives: " + str((missing - missingconsecutive) / howmany), + "List missing: " + str(missinglist)) #: Lenght of missing cannot be over 75% of diameter @@ -532,7 +534,7 @@ class CircleCaptcha(OCR): result = 1 if curpix <= self.BLACKCOLOR: result = -1 - # print str((x, y)) + " = " + str(result) + # self.log_debug(str((x, y)) + " = " + str(result)) return result @@ -546,15 +548,16 @@ class CircleCaptcha(OCR): mypalette = im.getpalette() im = im.convert('L') - if self._DEBUG == True: + if self.pyload.debug: iDebugSaveFile = iDebugSaveFile + 1 - # if iDebugSaveFile < 7: continue + # if iDebugSaveFile < 7: + # continue im.save("output" + str(iDebugSaveFile) + ".png", "png") raw_input('frame: '+ str(im)) pix = im.load() - stepheight = xrange(1, im.size[1],2) + stepheight = xrange(1, im.size[1], 2) #: stepheight = xrange(45, 47) imagewidth = xrange(1, im.size[0]) lstPoints = [] # Declares an empty list for the points @@ -564,7 +567,7 @@ class CircleCaptcha(OCR): min_distance = 10 max_diameter = 70 - if self._DEBUG == True: + if self.pyload.debug: imdebug = im.copy() draw = ImageDraw.Draw(imdebug) pixcopy = imdebug.load() @@ -589,15 +592,16 @@ class CircleCaptcha(OCR): break if x1 == -1: break - if self._DEBUG == True: - print "x1, y1 -> " + str((x1, y1)) + ": " + str(pix[x1, y1]) + if self.pyload.debug: + self.log_debug("x1, y1 -> " + str((x1, y1)) + ": " + str(pix[x1, y1])) if (x1, y1) in self.pointsofcirclefound: - if self._DEBUG == True: - print 'found ' + str((x1, y1)) + if self.pyload.debug: + self.log_debug("Found " + str((x1, y1))) continue - if self._DEBUG == True: pixcopy[x1, y1] = 45 #(255, 0, 0, 255) + if self.pyload.debug: + pixcopy[x1, y1] = 45 #(255, 0, 0, 255) #: found 1 pixel, seeking x2, y2 x2 = x1 y2 = y1 @@ -609,8 +613,8 @@ class CircleCaptcha(OCR): break if x2 == -1: break - if self._DEBUG == True: - print "x2, y2 -> " + str((x2, y1)) + ": " + str(pix[x2, y1]) + if self.pyload.debug: + self.log_debug("x2, y2 -> " + str((x2, y1)) + ": " + str(pix[x2, y1])) if abs(x2 - x1) < min_distance: continue if abs(x2 - x1) > (im.size[1] * 2 / 3): @@ -618,7 +622,8 @@ class CircleCaptcha(OCR): if abs(x2 - x1) > max_diameter: break - if self._DEBUG == True: pixcopy[x2, y2] = 65 #(0, 255, 0, 255) + if self.pyload.debug: + pixcopy[x2, y2] = 65 #(0, 255, 0, 255) #: found 2 pixel, seeking x3, y3 #: Verify cord @@ -627,7 +632,7 @@ class CircleCaptcha(OCR): y3 = y1 for j in xrange(1, 50): retval = self.find_last_pixel_y(im, pix, x3, y3, True if invert == 1 else False, -1, True) - # print (x3, y3, retval[0],invert) + # self.log_debug(x3, y3, retval[0], invert) y3 = retval[0] if y3 == -2: findnewcircle = True @@ -635,8 +640,8 @@ class CircleCaptcha(OCR): if y3 == -1: break - if self._DEBUG == True: - print "x3, y3 -> " + str((x3, y3)) + ": " + str(pix[x3, y3]) + if self.pyload.debug: + self.log_debug("x3, y3 -> " + str((x3, y3)) + ": " + str(pix[x3, y3])) #: Verify cord if abs(y3 - y2) < min_distance: continue @@ -645,38 +650,40 @@ class CircleCaptcha(OCR): if abs(y3 - y2) > max_diameter: break - if self._DEBUG == True: pixcopy[x3, y3] = 85 + if self.pyload.debug: + pixcopy[x3, y3] = 85 #: found 3 pixel. try circle c = self.find_circle(pix, x1, y1, x2, y2, x3, y3) if c[0] + c[2] >= im.size[0] or c[1] + c[2] >= im.size[1] or c[0] - c[2] <= 0 or c[1] - c[2] <= 0: continue - if self._DEBUG == True: pixcopy[c[0],c[1]] = 0 + if self.pyload.debug: + pixcopy[c[0], c[1]] = 0 #: (x-r, y-r, x+r, y+r) verified = self.verify_circle(im, pix, c) if verified == -1: verified = -1 elif verified == 0: - found.add(((c[0],c[1],c[2]),verified)) + found.add(((c[0], c[1], c[2]), verified)) findnewcircle = True elif verified == 1: - found.add(((c[0],c[1],c[2]),verified)) + found.add(((c[0], c[1], c[2]), verified)) findnewcircle = True - if self._DEBUG == True: + if self.pyload.debug: _pause = "" # if verified == -1: - # draw.ellipse((c[0]-c[2],c[1]-c[2],c[0]+c[2],c[1]+c[2]),outline=0) + # draw.ellipse((c[0]-c[2], c[1]-c[2], c[0]+c[2], c[1]+c[2]), outline=0) # _pause = "NOTDOUND" # imdebug.save("debug.png", "png") if verified == 0: - draw.ellipse((c[0]-c[2],c[1]-c[2],c[0]+c[2],c[1]+c[2]),outline=120) + draw.ellipse((c[0]-c[2], c[1]-c[2], c[0]+c[2], c[1]+c[2]), outline=120) _pause = "OPENED" if verified == 1: - draw.ellipse((c[0]-c[2],c[1]-c[2],c[0]+c[2],c[1]+c[2]),outline=65) + draw.ellipse((c[0]-c[2], c[1]-c[2], c[0]+c[2], c[1]+c[2]), outline=65) _pause = "CLOSED" imdebug.save("debug.png", "png") @@ -693,8 +700,8 @@ class CircleCaptcha(OCR): if findnewcircle == True: break - if self._DEBUG == True: - print 'Howmany opened circle? ' + str(len(found)) + ' ' + str(found) + if self.pyload.debug: + self.log_debug('Howmany opened circle? ' + str(len(found)) + ' ' + str(found)) #: Clean results for c in found: @@ -702,60 +709,60 @@ class CircleCaptcha(OCR): if verify == 0: p = c[0] if ( - ((p[0], p[1]+1, p[2]),1) in found or \ - ((p[0], p[1]-1, p[2]),1) in found or \ - ((p[0]+1, p[1],p[2]),1) in found or \ - ((p[0]-1, p[1],p[2]),1) in found or \ - ((p[0]+1, p[1]+1, p[2]),1) in found or \ - ((p[0]-1, p[1]+1, p[2]),1) in found or \ - ((p[0]+1, p[1]-1, p[2]),1) in found or \ - ((p[0]-1, p[1]-1, p[2]),1) in found \ + ((p[0], p[1]+1, p[2]), 1) in found or \ + ((p[0], p[1]-1, p[2]), 1) in found or \ + ((p[0]+1, p[1], p[2]), 1) in found or \ + ((p[0]-1, p[1], p[2]), 1) in found or \ + ((p[0]+1, p[1]+1, p[2]), 1) in found or \ + ((p[0]-1, p[1]+1, p[2]), 1) in found or \ + ((p[0]+1, p[1]-1, p[2]), 1) in found or \ + ((p[0]-1, p[1]-1, p[2]), 1) in found \ ): #: Delete nearly circle verify = -1 if ( - ((p[0], p[1]+1, p[2]+1),1) in found or \ - ((p[0], p[1]-1, p[2]+1),1) in found or \ - ((p[0]+1, p[1],p[2]+1),1) in found or \ - ((p[0]-1, p[1],p[2]+1),1) in found or \ - ((p[0]+1, p[1]+1, p[2]+1),1) in found or \ - ((p[0]-1, p[1]+1, p[2]+1),1) in found or \ - ((p[0]+1, p[1]-1, p[2]+1),1) in found or \ - ((p[0]-1, p[1]-1, p[2]+1),1) in found \ + ((p[0], p[1]+1, p[2]+1), 1) in found or \ + ((p[0], p[1]-1, p[2]+1), 1) in found or \ + ((p[0]+1, p[1], p[2]+1), 1) in found or \ + ((p[0]-1, p[1], p[2]+1), 1) in found or \ + ((p[0]+1, p[1]+1, p[2]+1), 1) in found or \ + ((p[0]-1, p[1]+1, p[2]+1), 1) in found or \ + ((p[0]+1, p[1]-1, p[2]+1), 1) in found or \ + ((p[0]-1, p[1]-1, p[2]+1), 1) in found \ ): #: Delete nearly circle verify = -1 if ( - ((p[0], p[1]+1, p[2]-1),1) in found or \ - ((p[0], p[1]-1, p[2]-1),1) in found or \ - ((p[0]+1, p[1],p[2]-1),1) in found or \ - ((p[0]-1, p[1],p[2]-1),1) in found or \ - ((p[0]+1, p[1]+1, p[2]-1),1) in found or \ - ((p[0]-1, p[1]+1, p[2]-1),1) in found or \ - ((p[0]+1, p[1]-1, p[2]-1),1) in found or \ - ((p[0]-1, p[1]-1, p[2]-1),1) in found \ + ((p[0], p[1]+1, p[2]-1), 1) in found or \ + ((p[0], p[1]-1, p[2]-1), 1) in found or \ + ((p[0]+1, p[1], p[2]-1), 1) in found or \ + ((p[0]-1, p[1], p[2]-1), 1) in found or \ + ((p[0]+1, p[1]+1, p[2]-1), 1) in found or \ + ((p[0]-1, p[1]+1, p[2]-1), 1) in found or \ + ((p[0]+1, p[1]-1, p[2]-1), 1) in found or \ + ((p[0]-1, p[1]-1, p[2]-1), 1) in found \ ): #: Delete nearly circle verify = -1 # if verify == 0: - # if self._DEBUG == True: - # pix[c[0][0],c[0][1]] = 90 #(255, 255, 0) + # if self.pyload.debug: + # pix[c[0][0], c[0][1]] = 90 #(255, 255, 0) # im.save("output.png", "png") - # return c[0][0],c[0][1] + # return c[0][0], c[0][1] # elif verify == 1: - # if self._DEBUG == True: - # pix[c[0][0],c[0][1]] = 40 #(255, 0, 0) + # if self.pyload.debug: + # pix[c[0][0], c[0][1]] = 40 #(255, 0, 0) # im.save("output.png", "png") # else: - # if self._DEBUG == True: - # pix[c[0][0],c[0][1]] = 180 #(0, 0, 255) + # if self.pyload.debug: + # pix[c[0][0], c[0][1]] = 180 #(0, 0, 255) # im.save("output.png", "png") - if self._DEBUG == True: + if self.pyload.debug: im.save("output.png", "png") @@ -764,13 +771,13 @@ class CircleCaptcha(OCR): file = cStringIO.StringIO(urllib.urlopen(url).read()) img = Image.open(file) coords = self.decrypt(img) - print "Coords: " + str(coords) + self.log_info(_("Coords: %s") % coords) #: Return coordinates of opened circle (eg (x, y)) def decrypt_from_file(self, filename): coords = self.decrypt(Image.open(filename)) #: Can be many different formats. - print "Coords: " + str(coords) + self.log_info(_("Coords: %s") % coords) ##DEBUG @@ -780,4 +787,4 @@ class CircleCaptcha(OCR): # coords = x.decrypt_from_file("decripter/captx.html2.gif") # coords = x.decrypt_from_web("http://ncrypt.in/classes/captcha/circlecaptcha.php") # b = datetime.datetime.now() -# print 'Elapsed time: ' + str((b-a).seconds) + ' seconds' +# self.log_debug("Elapsed time: %s seconds" % (b-a).seconds) -- 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/captcha/AdYouLike.py | 92 +++++++++++++++ module/plugins/captcha/AdsCaptcha.py | 64 ++++++++++ module/plugins/captcha/GigasizeCom.py | 2 +- module/plugins/captcha/LinksaveIn.py | 2 +- module/plugins/captcha/NetloadIn.py | 2 +- module/plugins/captcha/ReCaptcha.py | 197 +++++++++++++++++++++++++++++++ module/plugins/captcha/ShareonlineBiz.py | 2 +- module/plugins/captcha/SolveMedia.py | 105 ++++++++++++++++ 8 files changed, 462 insertions(+), 4 deletions(-) create mode 100644 module/plugins/captcha/AdYouLike.py create mode 100644 module/plugins/captcha/AdsCaptcha.py create mode 100644 module/plugins/captcha/ReCaptcha.py create mode 100644 module/plugins/captcha/SolveMedia.py (limited to 'module/plugins/captcha') diff --git a/module/plugins/captcha/AdYouLike.py b/module/plugins/captcha/AdYouLike.py new file mode 100644 index 000000000..d14babb51 --- /dev/null +++ b/module/plugins/captcha/AdYouLike.py @@ -0,0 +1,92 @@ +# -*- coding: utf-8 -*- + +import re + +from module.common.json_layer import json_loads +from module.plugins.internal.CaptchaService import CaptchaService + + +class AdYouLike(CaptchaService): + __name__ = "AdYouLike" + __type__ = "captcha" + __version__ = "0.07" + __status__ = "stable" + + __description__ = """AdYouLike captcha service plugin""" + __license__ = "GPLv3" + __authors__ = [("Walter Purcaro", "vuolter@gmail.com")] + + + AYL_PATTERN = r'Adyoulike\.create\s*\((.+?)\)' + CALLBACK_PATTERN = r'(Adyoulike\.g\._jsonp_\d+)' + + + def detect_key(self, data=None): + html = data or self.retrieve_data() + + m = re.search(self.AYL_PATTERN, html) + n = re.search(self.CALLBACK_PATTERN, html) + if m and n: + self.key = (m.group(1).strip(), n.group(1).strip()) + self.log_debug("Ayl: %s | Callback: %s" % self.key) + return self.key #: Key is the tuple(ayl, callback) + else: + self.log_warning(_("Ayl or callback pattern not found")) + return None + + + def challenge(self, key=None, data=None): + ayl, callback = key or self.retrieve_key(data) + + #: {'adyoulike':{'key':"P~zQ~O0zV0WTiAzC-iw0navWQpCLoYEP"}, + #: 'all':{'element_id':"ayl_private_cap_92300",'lang':"fr",'env':"prod"}} + ayl = json_loads(ayl) + + html = self.plugin.load("http://api-ayl.appspot.com/challenge", + get={'key' : ayl['adyoulike']['key'], + 'env' : ayl['all']['env'], + 'callback': callback}) + try: + challenge = json_loads(re.search(callback + r'\s*\((.+?)\)', html).group(1)) + + except AttributeError: + self.fail(_("AdYouLike challenge pattern not found")) + + self.log_debug("Challenge: %s" % challenge) + + return self.result(ayl, challenge), challenge + + + def result(self, server, challenge): + #: Adyoulike.g._jsonp_5579316662423138 + #: ({'translations':{'fr':{'instructions_visual':"Recopiez « Soonnight » ci-dessous :"}}, + #: 'site_under':true,'clickable':true,'pixels':{'VIDEO_050':[],'DISPLAY':[],'VIDEO_000':[],'VIDEO_100':[], + #: 'VIDEO_025':[],'VIDEO_075':[]},'medium_type':"image/adyoulike", + #: 'iframes':{'big':""},'shares':{},'id':256, + #: 'token':"e6QuI4aRSnbIZJg02IsV6cp4JQ9~MjA1",'formats':{'small':{'y':300,'x':0,'w':300,'h':60}, + #: 'big':{'y':0,'x':0,'w':300,'h':250},'hover':{'y':440,'x':0,'w':300,'h':60}}, + #: 'tid':"SqwuAdxT1EZoi4B5q0T63LN2AkiCJBg5"}) + + if isinstance(server, basestring): + server = json_loads(server) + + if isinstance(challenge, basestring): + challenge = json_loads(challenge) + + try: + instructions_visual = challenge['translations'][server['all']['lang']]['instructions_visual'] + result = re.search(u'«(.+?)»', instructions_visual).group(1).strip() + + except AttributeError: + self.fail(_("AdYouLike result not found")) + + result = {'_ayl_captcha_engine' : "adyoulike", + '_ayl_env' : server['all']['env'], + '_ayl_tid' : challenge['tid'], + '_ayl_token_challenge': challenge['token'], + '_ayl_response' : response} + + self.log_debug("Result: %s" % result) + + return result diff --git a/module/plugins/captcha/AdsCaptcha.py b/module/plugins/captcha/AdsCaptcha.py new file mode 100644 index 000000000..da0c531be --- /dev/null +++ b/module/plugins/captcha/AdsCaptcha.py @@ -0,0 +1,64 @@ +# -*- coding: utf-8 -*- + +import random +import re + +from module.plugins.internal.CaptchaService import CaptchaService + + +class AdsCaptcha(CaptchaService): + __name__ = "AdsCaptcha" + __type__ = "captcha" + __version__ = "0.10" + __status__ = "stable" + + __description__ = """AdsCaptcha captcha service plugin""" + __license__ = "GPLv3" + __authors__ = [("pyLoad Team", "admin@pyload.org")] + + + CAPTCHAID_PATTERN = r'api\.adscaptcha\.com/Get\.aspx\?.*?CaptchaId=(\d+)' + PUBLICKEY_PATTERN = r'api\.adscaptcha\.com/Get\.aspx\?.*?PublicKey=([\w-]+)' + + + def detect_key(self, data=None): + html = data or self.retrieve_data() + + m = re.search(self.PUBLICKEY_PATTERN, html) + n = re.search(self.CAPTCHAID_PATTERN, html) + if m and n: + self.key = (m.group(1).strip(), n.group(1).strip()) #: Key is the tuple(PublicKey, CaptchaId) + self.log_debug("Key: %s | ID: %s" % self.key) + return self.key + else: + self.log_warning(_("Key or id pattern not found")) + return None + + + def challenge(self, key=None, data=None): + PublicKey, CaptchaId = key or self.retrieve_key(data) + + html = self.plugin.load("http://api.adscaptcha.com/Get.aspx", + get={'CaptchaId': CaptchaId, + 'PublicKey': PublicKey}) + try: + challenge = re.search("challenge: '(.+?)',", html).group(1) + server = re.search("server: '(.+?)',", html).group(1) + + except AttributeError: + self.fail(_("AdsCaptcha challenge pattern not found")) + + self.log_debug("Challenge: %s" % challenge) + + return self.result(server, challenge), challenge + + + def result(self, server, challenge): + result = self.decrypt("%sChallenge.aspx" % server, + get={'cid': challenge, 'dummy': random.random()}, + cookies=True, + input_type="jpg") + + self.log_debug("Result: %s" % result) + + return result diff --git a/module/plugins/captcha/GigasizeCom.py b/module/plugins/captcha/GigasizeCom.py index 19ad9d680..f71266b23 100644 --- a/module/plugins/captcha/GigasizeCom.py +++ b/module/plugins/captcha/GigasizeCom.py @@ -14,7 +14,7 @@ class GigasizeCom(OCR): __authors__ = [("pyLoad Team", "admin@pyload.org")] - def get_captcha(self, image): + def recognize(self, image): self.load_image(image) self.threshold(2.8) self.run_tesser(True, False, False, True) diff --git a/module/plugins/captcha/LinksaveIn.py b/module/plugins/captcha/LinksaveIn.py index 68704f21d..0a4731375 100644 --- a/module/plugins/captcha/LinksaveIn.py +++ b/module/plugins/captcha/LinksaveIn.py @@ -137,7 +137,7 @@ class LinksaveIn(OCR): self.pixels = self.image.load() - def get_captcha(self, image): + def recognize(self, image): self.load_image(image) bg = self.get_bg() self.substract_bg(bg) diff --git a/module/plugins/captcha/NetloadIn.py b/module/plugins/captcha/NetloadIn.py index b6ba2b6e9..56b7c9196 100644 --- a/module/plugins/captcha/NetloadIn.py +++ b/module/plugins/captcha/NetloadIn.py @@ -14,7 +14,7 @@ class NetloadIn(OCR): __authors__ = [("pyLoad Team", "admin@pyload.org")] - def get_captcha(self, image): + def recognize(self, image): self.load_image(image) self.to_greyscale() self.clean(3) diff --git a/module/plugins/captcha/ReCaptcha.py b/module/plugins/captcha/ReCaptcha.py new file mode 100644 index 000000000..8f9755961 --- /dev/null +++ b/module/plugins/captcha/ReCaptcha.py @@ -0,0 +1,197 @@ +# -*- coding: utf-8 -*- + +import random +import re +import time +import urlparse + +from base64 import b64encode + +from module.plugins.internal.CaptchaService import CaptchaService + + +class ReCaptcha(CaptchaService): + __name__ = "ReCaptcha" + __type__ = "captcha" + __version__ = "0.18" + __status__ = "stable" + + __description__ = """ReCaptcha captcha service plugin""" + __license__ = "GPLv3" + __authors__ = [("pyLoad Team", "admin@pyload.org"), + ("Walter Purcaro", "vuolter@gmail.com"), + ("zapp-brannigan", "fuerst.reinje@web.de")] + + + KEY_V1_PATTERN = r'(?:recaptcha(?:/api|\.net)/(?:challenge|noscript)\?k=|Recaptcha\.create\s*\(\s*["\'])([\w-]+)' + KEY_V2_PATTERN = r'(?:data-sitekey=["\']|["\']sitekey["\']:\s*["\'])([\w-]+)' + + + def detect_key(self, data=None): + html = data or self.retrieve_data() + + m = re.search(self.KEY_V2_PATTERN, html) or re.search(self.KEY_V1_PATTERN, html) + if m: + self.key = m.group(1).strip() + self.log_debug("Key: %s" % self.key) + return self.key + else: + self.log_warning(_("Key pattern not found")) + return None + + + def challenge(self, key=None, data=None, version=None): + key = key or self.retrieve_key(data) + + if version in (1, 2): + return getattr(self, "_challenge_v%s" % version)(key) + + else: + return self.challenge(key, + version=2 if re.search(self.KEY_V2_PATTERN, html or self.retrieve_data()) else 1) + + + def _challenge_v1(self, key): + html = self.plugin.load("http://www.google.com/recaptcha/api/challenge", + get={'k': key}) + try: + challenge = re.search("challenge : '(.+?)',", html).group(1) + server = re.search("server : '(.+?)',", html).group(1) + + except AttributeError: + self.fail(_("ReCaptcha challenge pattern not found")) + + self.log_debug("Challenge: %s" % challenge) + + return self.result(server, challenge, key) + + + def result(self, server, challenge, key): + self.plugin.load("http://www.google.com/recaptcha/api/js/recaptcha.js") + html = self.plugin.load("http://www.google.com/recaptcha/api/reload", + get={'c' : challenge, + 'k' : key, + 'reason': "i", + 'type' : "image"}) + + try: + challenge = re.search('\(\'(.+?)\',',html).group(1) + + except AttributeError: + self.fail(_("ReCaptcha second challenge pattern not found")) + + self.log_debug("Second challenge: %s" % challenge) + result = self.decrypt("%simage" % server, + get={'c': challenge}, + cookies=True, + input_type="jpg", + ocr=False) + + self.log_debug("Result: %s" % result) + + return result, challenge + + + def _collect_api_info(self): + html = self.plugin.load("http://www.google.com/recaptcha/api.js") + a = re.search(r'po.src = \'(.*?)\';', html).group(1) + vers = a.split("/")[5] + + self.log_debug("API version: %s" % vers) + + language = a.split("__")[1].split(".")[0] + + self.log_debug("API language: %s" % language) + + html = self.plugin.load("https://apis.google.com/js/api.js") + b = re.search(r'"h":"(.*?)","', html).group(1) + jsh = b.decode('unicode-escape') + + self.log_debug("API jsh-string: %s" % jsh) + + return vers, language, jsh + + + def _prepare_time_and_rpc(self): + self.plugin.load("http://www.google.com/recaptcha/api2/demo") + + millis = int(round(time.time() * 1000)) + + self.log_debug("Time: %s" % millis) + + rand = random.randint(1, 99999999) + a = "0.%s" % str(rand * 2147483647) + rpc = int(100000000 * float(a)) + + self.log_debug("Rpc-token: %s" % rpc) + + return millis, rpc + + + def _challenge_v2(self, key, parent=None): + if parent is None: + try: + parent = urlparse.urljoin("http://", urlparse.urlparse(self.plugin.pyfile.url).netloc) + + except Exception: + parent = "" + + botguardstring = "!A" + vers, language, jsh = self._collect_api_info() + millis, rpc = self._prepare_time_and_rpc() + + html = self.plugin.load("https://www.google.com/recaptcha/api2/anchor", + get={'k' : key, + 'hl' : language, + 'v' : vers, + 'usegapi' : "1", + 'jsh' : "%s#id=IO_%s" % (jsh, millis), + 'parent' : parent, + 'pfname' : "", + 'rpctoken': rpc}) + + token1 = re.search(r'id="recaptcha-token" value="(.*?)">', html) + self.log_debug("Token #1: %s" % token1.group(1)) + + html = self.plugin.load("https://www.google.com/recaptcha/api2/frame", + get={'c' : token1.group(1), + 'hl' : language, + 'v' : vers, + 'bg' : botguardstring, + 'k' : key, + 'usegapi': "1", + 'jsh' : jsh}, + decode="unicode-escape") + + token2 = re.search(r'"finput","(.*?)",', html) + self.log_debug("Token #2: %s" % token2.group(1)) + + token3 = re.search(r'"rresp","(.*?)",', html) + self.log_debug("Token #3: %s" % token3.group(1)) + + millis_captcha_loading = int(round(time.time() * 1000)) + captcha_response = self.decrypt("https://www.google.com/recaptcha/api2/payload", + get={'c':token3.group(1), 'k':key}, + cookies=True, + ocr=False) + response = b64encode('{"response":"%s"}' % captcha_response) + + self.log_debug("Result: %s" % response) + + timeToSolve = int(round(time.time() * 1000)) - millis_captcha_loading + timeToSolveMore = timeToSolve + int(float("0." + str(random.randint(1, 99999999))) * 500) + + html = self.plugin.load("https://www.google.com/recaptcha/api2/userverify", + post={'k' : key, + 'c' : token3.group(1), + 'response': response, + 't' : timeToSolve, + 'ct' : timeToSolveMore, + 'bg' : botguardstring}) + + token4 = re.search(r'"uvresp","(.*?)",', html) + self.log_debug("Token #4: %s" % token4.group(1)) + + result = token4.group(1) + + return result, None diff --git a/module/plugins/captcha/ShareonlineBiz.py b/module/plugins/captcha/ShareonlineBiz.py index 7f25f164d..98994b121 100644 --- a/module/plugins/captcha/ShareonlineBiz.py +++ b/module/plugins/captcha/ShareonlineBiz.py @@ -14,7 +14,7 @@ class ShareonlineBiz(OCR): __authors__ = [("RaNaN", "RaNaN@pyload.org")] - def get_captcha(self, image): + def recognize(self, image): self.load_image(image) self.to_greyscale() self.image = self.image.resize((160, 50)) diff --git a/module/plugins/captcha/SolveMedia.py b/module/plugins/captcha/SolveMedia.py new file mode 100644 index 000000000..cbac2dec2 --- /dev/null +++ b/module/plugins/captcha/SolveMedia.py @@ -0,0 +1,105 @@ +# -*- coding: utf-8 -*- + +import re + +from module.plugins.internal.Plugin import Fail +from module.plugins.internal.CaptchaService import CaptchaService + + +class SolveMedia(CaptchaService): + __name__ = "SolveMedia" + __type__ = "captcha" + __version__ = "0.15" + __status__ = "stable" + + __description__ = """SolveMedia captcha service plugin""" + __license__ = "GPLv3" + __authors__ = [("pyLoad Team", "admin@pyload.org")] + + + KEY_PATTERN = r'api\.solvemedia\.com/papi/challenge\.(?:no)?script\?k=(.+?)["\']' + + + def detect_key(self, data=None): + html = data or self.retrieve_data() + + m = re.search(self.KEY_PATTERN, html) + if m: + self.key = m.group(1).strip() + self.log_debug("Key: %s" % self.key) + return self.key + else: + self.log_warning(_("Key pattern not found") + return None + + + def challenge(self, key=None, data=None): + key = key or self.retrieve_key(data) + + html = self.plugin.load("http://api.solvemedia.com/papi/challenge.noscript", + get={'k': key}) + + for i in xrange(1, 11): + try: + magic = re.search(r'name="magic" value="(.+?)"', html).group(1) + + except AttributeError: + self.log_warning(_("Magic pattern not found") + magic = None + + try: + challenge = re.search(r'', + html).group(1) + + except AttributeError: + self.fail(_("SolveMedia challenge pattern not found")) + + else: + self.log_debug("Challenge: %s" % challenge) + + try: + result = self.result("http://api.solvemedia.com/papi/media", challenge) + + except Fail, e: + self.log_warning(e) + self.plugin.invalidCaptcha() + result = None + + html = self.plugin.load("http://api.solvemedia.com/papi/verify.noscript", + post={'adcopy_response' : result, + 'k' : key, + 'l' : "en", + 't' : "img", + 's' : "standard", + 'magic' : magic, + 'adcopy_challenge': challenge, + 'ref' : self.plugin.pyfile.url}) + try: + redirect = re.search(r'URL=(.+?)">', html).group(1) + + except AttributeError: + self.fail(_("SolveMedia verify pattern not found")) + + else: + if "error" in html: + self.log_warning(_("Captcha code was invalid")) + self.log_debug("Retry #%d" % i) + html = self.plugin.load(redirect) + else: + break + + else: + self.fail(_("SolveMedia max retries exceeded")) + + return result, challenge + + + def result(self, server, challenge): + result = self.decrypt(server, + get={'c': challenge}, + cookies=True, + input_type="gif") + + self.log_debug("Result: %s" % result) + + 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/captcha/AdYouLike.py | 2 +- module/plugins/captcha/AdsCaptcha.py | 2 +- module/plugins/captcha/CircleCaptcha.py | 2 +- module/plugins/captcha/GigasizeCom.py | 2 +- module/plugins/captcha/LinksaveIn.py | 2 +- module/plugins/captcha/NetloadIn.py | 2 +- module/plugins/captcha/ReCaptcha.py | 2 +- module/plugins/captcha/ShareonlineBiz.py | 2 +- module/plugins/captcha/SolveMedia.py | 2 +- 9 files changed, 9 insertions(+), 9 deletions(-) (limited to 'module/plugins/captcha') diff --git a/module/plugins/captcha/AdYouLike.py b/module/plugins/captcha/AdYouLike.py index d14babb51..f91b5805c 100644 --- a/module/plugins/captcha/AdYouLike.py +++ b/module/plugins/captcha/AdYouLike.py @@ -10,7 +10,7 @@ class AdYouLike(CaptchaService): __name__ = "AdYouLike" __type__ = "captcha" __version__ = "0.07" - __status__ = "stable" + __status__ = "testing" __description__ = """AdYouLike captcha service plugin""" __license__ = "GPLv3" diff --git a/module/plugins/captcha/AdsCaptcha.py b/module/plugins/captcha/AdsCaptcha.py index da0c531be..613283e53 100644 --- a/module/plugins/captcha/AdsCaptcha.py +++ b/module/plugins/captcha/AdsCaptcha.py @@ -10,7 +10,7 @@ class AdsCaptcha(CaptchaService): __name__ = "AdsCaptcha" __type__ = "captcha" __version__ = "0.10" - __status__ = "stable" + __status__ = "testing" __description__ = """AdsCaptcha captcha service plugin""" __license__ = "GPLv3" diff --git a/module/plugins/captcha/CircleCaptcha.py b/module/plugins/captcha/CircleCaptcha.py index a93defb13..8ff488a2d 100644 --- a/module/plugins/captcha/CircleCaptcha.py +++ b/module/plugins/captcha/CircleCaptcha.py @@ -32,7 +32,7 @@ class CircleCaptcha(OCR): __name__ = "CircleCaptcha" __type__ = "ocr" __version__ = "1.02" - __status__ = "stable" + __status__ = "testing" __description__ = """Circle captcha ocr plugin""" __license__ = "GPLv3" diff --git a/module/plugins/captcha/GigasizeCom.py b/module/plugins/captcha/GigasizeCom.py index f71266b23..12f123c41 100644 --- a/module/plugins/captcha/GigasizeCom.py +++ b/module/plugins/captcha/GigasizeCom.py @@ -7,7 +7,7 @@ class GigasizeCom(OCR): __name__ = "GigasizeCom" __type__ = "ocr" __version__ = "0.14" - __status__ = "stable" + __status__ = "testing" __description__ = """Gigasize.com ocr plugin""" __license__ = "GPLv3" diff --git a/module/plugins/captcha/LinksaveIn.py b/module/plugins/captcha/LinksaveIn.py index 0a4731375..de51a09f3 100644 --- a/module/plugins/captcha/LinksaveIn.py +++ b/module/plugins/captcha/LinksaveIn.py @@ -16,7 +16,7 @@ class LinksaveIn(OCR): __name__ = "LinksaveIn" __type__ = "ocr" __version__ = "0.14" - __status__ = "stable" + __status__ = "testing" __description__ = """Linksave.in ocr plugin""" __license__ = "GPLv3" diff --git a/module/plugins/captcha/NetloadIn.py b/module/plugins/captcha/NetloadIn.py index 56b7c9196..50174684d 100644 --- a/module/plugins/captcha/NetloadIn.py +++ b/module/plugins/captcha/NetloadIn.py @@ -7,7 +7,7 @@ class NetloadIn(OCR): __name__ = "NetloadIn" __type__ = "ocr" __version__ = "0.14" - __status__ = "stable" + __status__ = "testing" __description__ = """Netload.in ocr plugin""" __license__ = "GPLv3" diff --git a/module/plugins/captcha/ReCaptcha.py b/module/plugins/captcha/ReCaptcha.py index 8f9755961..8eea606a8 100644 --- a/module/plugins/captcha/ReCaptcha.py +++ b/module/plugins/captcha/ReCaptcha.py @@ -14,7 +14,7 @@ class ReCaptcha(CaptchaService): __name__ = "ReCaptcha" __type__ = "captcha" __version__ = "0.18" - __status__ = "stable" + __status__ = "testing" __description__ = """ReCaptcha captcha service plugin""" __license__ = "GPLv3" diff --git a/module/plugins/captcha/ShareonlineBiz.py b/module/plugins/captcha/ShareonlineBiz.py index 98994b121..edf14df87 100644 --- a/module/plugins/captcha/ShareonlineBiz.py +++ b/module/plugins/captcha/ShareonlineBiz.py @@ -7,7 +7,7 @@ class ShareonlineBiz(OCR): __name__ = "ShareonlineBiz" __type__ = "ocr" __version__ = "0.14" - __status__ = "stable" + __status__ = "testing" __description__ = """Shareonline.biz ocr plugin""" __license__ = "GPLv3" diff --git a/module/plugins/captcha/SolveMedia.py b/module/plugins/captcha/SolveMedia.py index cbac2dec2..ae6751a70 100644 --- a/module/plugins/captcha/SolveMedia.py +++ b/module/plugins/captcha/SolveMedia.py @@ -10,7 +10,7 @@ class SolveMedia(CaptchaService): __name__ = "SolveMedia" __type__ = "captcha" __version__ = "0.15" - __status__ = "stable" + __status__ = "testing" __description__ = """SolveMedia captcha service plugin""" __license__ = "GPLv3" -- cgit v1.2.3 From 761ca5c66e07559925ebbdbc6531f9ca658b12ce Mon Sep 17 00:00:00 2001 From: Walter Purcaro Date: Fri, 24 Jul 2015 16:11:58 +0200 Subject: Code cosmetics --- module/plugins/captcha/CircleCaptcha.py | 124 +++++++++++++++----------------- module/plugins/captcha/LinksaveIn.py | 4 +- 2 files changed, 61 insertions(+), 67 deletions(-) (limited to 'module/plugins/captcha') diff --git a/module/plugins/captcha/CircleCaptcha.py b/module/plugins/captcha/CircleCaptcha.py index 8ff488a2d..2b34f073c 100644 --- a/module/plugins/captcha/CircleCaptcha.py +++ b/module/plugins/captcha/CircleCaptcha.py @@ -89,7 +89,7 @@ class CircleCaptcha(OCR): howmany = 0 for y in imageheight: curpix = pix[x, y] - # if jump == True: + # if jump is True: if curpix > self.BACKGROUND: if howmany <= cleandeep and howmany > 0: #: Clean pixel @@ -128,7 +128,7 @@ class CircleCaptcha(OCR): if curpix < self.BLACKCOLOR: blackfound = blackfound + 1 - if ExitWithBlack == True and blackfound >= 3: + if ExitWithBlack is True and blackfound >= 3: break #: Exit if found black else: continue @@ -138,8 +138,8 @@ class CircleCaptcha(OCR): jump = False continue - if (curpix < self.BACKGROUND and color == -1) or (curpix == color and color > -1): - if jump == False: + if (curpix < self.BACKGROUND and color == -1) or (curpix is color and color > -1): + if jump is False: #: Found pixel curcolor = curpix newx = x, curcolor @@ -158,7 +158,7 @@ class CircleCaptcha(OCR): if curpix < self.BLACKCOLOR: blackfound = blackfound + 1 - if ExitWithBlack == True and blackfound >= 3: + if ExitWithBlack is True and blackfound >= 3: break #: Exit if found black else: continue @@ -168,7 +168,7 @@ class CircleCaptcha(OCR): #: Found last pixel and the first white break - if (curpix < self.BACKGROUND and color == -1) or (curpix == color and color > -1): + if (curpix < self.BACKGROUND and color == -1) or (curpix is color and color > -1): #: Found pixel curcolor = curpix newx = x, curcolor @@ -177,7 +177,7 @@ class CircleCaptcha(OCR): def find_last_pixel_y(self, im, pix, curx, cury, DownToUp, color = -1, ExitWithBlack = False): - if DownToUp == False: + if DownToUp is False: imageheight = xrange(int(cury)+1, int(im.size[1])-1) else: imageheight = xrange(int(cury)-1, 1, -1) @@ -189,7 +189,7 @@ class CircleCaptcha(OCR): if curpix < self.BLACKCOLOR: blackfound = blackfound + 1 - if ExitWithBlack == True and blackfound >= 3: + if ExitWithBlack is True and blackfound >= 3: break #: Exit if found black else: continue @@ -199,7 +199,7 @@ class CircleCaptcha(OCR): #: Found last pixel and the first white break - if (curpix < self.BACKGROUND and color == -1) or (curpix == color and color > -1): + if (curpix < self.BACKGROUND and color == -1) or (curpix is color and color > -1): #: Found pixel curcolor = curpix newy = y, color @@ -422,30 +422,30 @@ class CircleCaptcha(OCR): for p in missinglist: #: Left and bottom - if (self.verify_point(im, pix, p[0]-1, p[1], exactfind) == 1 and \ - self.verify_point(im, pix, p[0], p[1]+1, exactfind) == 1): + if (self.verify_point(im, pix, p[0]-1, p[1], exactfind) == 1 + and self.verify_point(im, pix, p[0], p[1]+1, exactfind) == 1): missing = missing - 1 - elif (self.verify_point(im, pix, p[0]-1, p[1], exactfind) == 1 and \ - self.verify_point(im, pix, p[0], p[1]-1, exactfind) == 1): + elif (self.verify_point(im, pix, p[0]-1, p[1], exactfind) == 1 + and self.verify_point(im, pix, p[0], p[1]-1, exactfind) == 1): missing = missing - 1 #: Right and bottom - elif (self.verify_point(im, pix, p[0]+1, p[1], exactfind) == 1 and \ - self.verify_point(im, pix, p[0], p[1]+1, exactfind) == 1): + elif (self.verify_point(im, pix, p[0]+1, p[1], exactfind) == 1 + and self.verify_point(im, pix, p[0], p[1]+1, exactfind) == 1): missing = missing - 1 #: Right and up - elif (self.verify_point(im, pix, p[0]+1, p[1], exactfind) == 1 and \ - self.verify_point(im, pix, p[0], p[1]-1, exactfind) == 1): + elif (self.verify_point(im, pix, p[0]+1, p[1], exactfind) == 1 + and self.verify_point(im, pix, p[0], p[1]-1, exactfind) == 1): missing = missing - 1 - if (p[0], p[1]+1) in missinglist or \ - (p[0], p[1]-1) in missinglist or \ - (p[0]+1, p[1]) in missinglist or \ - (p[0]-1, p[1]) in missinglist or \ - (p[0]+1, p[1]+1) in missinglist or \ - (p[0]-1, p[1]+1) in missinglist or \ - (p[0]+1, p[1]-1) in missinglist or \ - (p[0]-1, p[1]-1) in missinglist or \ - self.verify_point(im, pix, p[0], p[1], False) == 1: + if ((p[0], p[1]+1) in missinglist + or (p[0], p[1]-1) in missinglist + or (p[0]+1, p[1]) in missinglist + or (p[0]-1, p[1]) in missinglist + or (p[0]+1, p[1]+1) in missinglist + or (p[0]-1, p[1]+1) in missinglist + or (p[0]+1, p[1]-1) in missinglist + or (p[0]-1, p[1]-1) in missinglist + or self.verify_point(im, pix, p[0], p[1], False) == 1): missingconsecutive = missingconsecutive + 1 # else: # pix[p[0], p[1]] = 0 @@ -511,17 +511,17 @@ class CircleCaptcha(OCR): return result curpix = pix[x, y] - if (curpix == color and color > -1) or (curpix < self.BACKGROUND and color == -1): + if (curpix is color and color > -1) or (curpix < self.BACKGROUND and color == -1): if curpix > self.BLACKCOLOR: result = 1 else: result = -1 #: Verify around - if (exact == False): + if exact is False: if x + 1 < im.size[0]: curpix = pix[x+1, y] - if (curpix == color and color > -1) or (curpix < self.BACKGROUND and color == -1): + if (curpix is color and color > -1) or (curpix < self.BACKGROUND and color == -1): if curpix > self.BLACKCOLOR: result = 1 if curpix <= self.BLACKCOLOR: @@ -529,7 +529,7 @@ class CircleCaptcha(OCR): if x > 0: curpix = pix[x-1, y] - if (curpix == color and color > -1) or (curpix < self.BACKGROUND and color == -1): + if (curpix is color and color > -1) or (curpix < self.BACKGROUND and color == -1): if curpix > self.BLACKCOLOR: result = 1 if curpix <= self.BLACKCOLOR: @@ -543,7 +543,7 @@ class CircleCaptcha(OCR): mypalette = None for im in ImageSequence(img): im.save("orig.png", "png") - if mypalette != None: + if mypalette not is None: im.putpalette(mypalette) mypalette = im.getpalette() im = im.convert('L') @@ -690,14 +690,14 @@ class CircleCaptcha(OCR): if _pause != "": valore = raw_input('Found ' + _pause + ' CIRCLE circle press [Enter] = continue / [q] for Quit: ' + str(verified)) - if valore == 'q': + if valore == "q": sys.exit() - if findnewcircle == True: + if findnewcircle is True: break - if findnewcircle == True: + if findnewcircle is True: break - if findnewcircle == True: + if findnewcircle is True: break if self.pyload.debug: @@ -708,42 +708,36 @@ class CircleCaptcha(OCR): verify = c[1] if verify == 0: p = c[0] - if ( - ((p[0], p[1]+1, p[2]), 1) in found or \ - ((p[0], p[1]-1, p[2]), 1) in found or \ - ((p[0]+1, p[1], p[2]), 1) in found or \ - ((p[0]-1, p[1], p[2]), 1) in found or \ - ((p[0]+1, p[1]+1, p[2]), 1) in found or \ - ((p[0]-1, p[1]+1, p[2]), 1) in found or \ - ((p[0]+1, p[1]-1, p[2]), 1) in found or \ - ((p[0]-1, p[1]-1, p[2]), 1) in found \ - ): + if (((p[0], p[1]+1, p[2]), 1) in found + or ((p[0], p[1]-1, p[2]), 1) in found + or ((p[0]+1, p[1], p[2]), 1) in found + or ((p[0]-1, p[1], p[2]), 1) in found + or ((p[0]+1, p[1]+1, p[2]), 1) in found + or ((p[0]-1, p[1]+1, p[2]), 1) in found + or ((p[0]+1, p[1]-1, p[2]), 1) in found + or ((p[0]-1, p[1]-1, p[2]), 1) in found): #: Delete nearly circle verify = -1 - if ( - ((p[0], p[1]+1, p[2]+1), 1) in found or \ - ((p[0], p[1]-1, p[2]+1), 1) in found or \ - ((p[0]+1, p[1], p[2]+1), 1) in found or \ - ((p[0]-1, p[1], p[2]+1), 1) in found or \ - ((p[0]+1, p[1]+1, p[2]+1), 1) in found or \ - ((p[0]-1, p[1]+1, p[2]+1), 1) in found or \ - ((p[0]+1, p[1]-1, p[2]+1), 1) in found or \ - ((p[0]-1, p[1]-1, p[2]+1), 1) in found \ - ): + if (((p[0], p[1]+1, p[2]+1), 1) in found + or ((p[0], p[1]-1, p[2]+1), 1) in found + or ((p[0]+1, p[1], p[2]+1), 1) in found + or ((p[0]-1, p[1], p[2]+1), 1) in found + or ((p[0]+1, p[1]+1, p[2]+1), 1) in found + or ((p[0]-1, p[1]+1, p[2]+1), 1) in found + or ((p[0]+1, p[1]-1, p[2]+1), 1) in found + or ((p[0]-1, p[1]-1, p[2]+1), 1) in found): #: Delete nearly circle verify = -1 - if ( - ((p[0], p[1]+1, p[2]-1), 1) in found or \ - ((p[0], p[1]-1, p[2]-1), 1) in found or \ - ((p[0]+1, p[1], p[2]-1), 1) in found or \ - ((p[0]-1, p[1], p[2]-1), 1) in found or \ - ((p[0]+1, p[1]+1, p[2]-1), 1) in found or \ - ((p[0]-1, p[1]+1, p[2]-1), 1) in found or \ - ((p[0]+1, p[1]-1, p[2]-1), 1) in found or \ - ((p[0]-1, p[1]-1, p[2]-1), 1) in found \ - ): + if (((p[0], p[1]+1, p[2]-1), 1) in found + or ((p[0], p[1]-1, p[2]-1), 1) in found + or ((p[0]+1, p[1], p[2]-1), 1) in found + or ((p[0]-1, p[1], p[2]-1), 1) in found + or ((p[0]+1, p[1]+1, p[2]-1), 1) in found + or ((p[0]-1, p[1]+1, p[2]-1), 1) in found + or ((p[0]+1, p[1]-1, p[2]-1), 1) in found + or ((p[0]-1, p[1]-1, p[2]-1), 1) in found): #: Delete nearly circle verify = -1 diff --git a/module/plugins/captcha/LinksaveIn.py b/module/plugins/captcha/LinksaveIn.py index de51a09f3..ab9f54068 100644 --- a/module/plugins/captcha/LinksaveIn.py +++ b/module/plugins/captcha/LinksaveIn.py @@ -81,7 +81,7 @@ class LinksaveIn(OCR): cstat[rgb_c] += 1 except Exception: cstat[rgb_c] = 1 - if rgb_bg == rgb_c: + if rgb_bg is rgb_c: stat[bgpath] += 1 max_p = 0 bg = "" @@ -111,7 +111,7 @@ class LinksaveIn(OCR): for y in xrange(bg.size[1]): rgb_bg = bglut[bgpix[x, y]] rgb_c = lut[pix[x, y]] - if rgb_c == rgb_bg: + if rgb_c is rgb_bg: orgpix[x, y] = (255, 255, 255) -- cgit v1.2.3 From dd13825fbd3df9e441200638cd2a92e3924dfff6 Mon Sep 17 00:00:00 2001 From: Walter Purcaro Date: Fri, 24 Jul 2015 23:57:04 +0200 Subject: Fix typo --- module/plugins/captcha/CircleCaptcha.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'module/plugins/captcha') diff --git a/module/plugins/captcha/CircleCaptcha.py b/module/plugins/captcha/CircleCaptcha.py index 2b34f073c..7728b4ac9 100644 --- a/module/plugins/captcha/CircleCaptcha.py +++ b/module/plugins/captcha/CircleCaptcha.py @@ -543,7 +543,7 @@ class CircleCaptcha(OCR): mypalette = None for im in ImageSequence(img): im.save("orig.png", "png") - if mypalette not is None: + if mypalette is not None: im.putpalette(mypalette) mypalette = im.getpalette() im = im.convert('L') -- 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/captcha/ReCaptcha.py | 2 +- module/plugins/captcha/SolveMedia.py | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) (limited to 'module/plugins/captcha') diff --git a/module/plugins/captcha/ReCaptcha.py b/module/plugins/captcha/ReCaptcha.py index 8eea606a8..6ec5e89c8 100644 --- a/module/plugins/captcha/ReCaptcha.py +++ b/module/plugins/captcha/ReCaptcha.py @@ -48,7 +48,7 @@ class ReCaptcha(CaptchaService): else: return self.challenge(key, - version=2 if re.search(self.KEY_V2_PATTERN, html or self.retrieve_data()) else 1) + version=2 if re.search(self.KEY_V2_PATTERN, data or self.retrieve_data()) else 1) def _challenge_v1(self, key): diff --git a/module/plugins/captcha/SolveMedia.py b/module/plugins/captcha/SolveMedia.py index ae6751a70..870b5fc10 100644 --- a/module/plugins/captcha/SolveMedia.py +++ b/module/plugins/captcha/SolveMedia.py @@ -29,7 +29,7 @@ class SolveMedia(CaptchaService): self.log_debug("Key: %s" % self.key) return self.key else: - self.log_warning(_("Key pattern not found") + self.log_warning(_("Key pattern not found")) return None @@ -44,7 +44,7 @@ class SolveMedia(CaptchaService): magic = re.search(r'name="magic" value="(.+?)"', html).group(1) except AttributeError: - self.log_warning(_("Magic pattern not found") + self.log_warning(_("Magic pattern not found")) magic = None try: -- cgit v1.2.3 From 952001324e1faf584b1adcb01c4a0406a3722932 Mon Sep 17 00:00:00 2001 From: Walter Purcaro Date: Sat, 25 Jul 2015 09:42:49 +0200 Subject: =?UTF-8?q?Don't=20user=20dictionary=E2=80=99s=20iterator=20method?= =?UTF-8?q?s?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- module/plugins/captcha/LinksaveIn.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'module/plugins/captcha') diff --git a/module/plugins/captcha/LinksaveIn.py b/module/plugins/captcha/LinksaveIn.py index ab9f54068..4d2e2bc34 100644 --- a/module/plugins/captcha/LinksaveIn.py +++ b/module/plugins/captcha/LinksaveIn.py @@ -85,7 +85,7 @@ class LinksaveIn(OCR): stat[bgpath] += 1 max_p = 0 bg = "" - for bgpath, value in stat.iteritems(): + for bgpath, value in stat.items(): if max_p < value: bg = bgpath max_p = value -- cgit v1.2.3 From 5ceb174cb7eb6a3cf706a1ed861ddd778069d7b6 Mon Sep 17 00:00:00 2001 From: Walter Purcaro Date: Mon, 27 Jul 2015 10:29:06 +0200 Subject: Then update others --- module/plugins/captcha/ReCaptcha.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'module/plugins/captcha') diff --git a/module/plugins/captcha/ReCaptcha.py b/module/plugins/captcha/ReCaptcha.py index 6ec5e89c8..a5aa356e2 100644 --- a/module/plugins/captcha/ReCaptcha.py +++ b/module/plugins/captcha/ReCaptcha.py @@ -81,7 +81,7 @@ class ReCaptcha(CaptchaService): self.fail(_("ReCaptcha second challenge pattern not found")) self.log_debug("Second challenge: %s" % challenge) - result = self.decrypt("%simage" % server, + result = self.decrypt(urlparse.urljoin(server, "image"), get={'c': challenge}, cookies=True, input_type="jpg", -- cgit v1.2.3 From 5745baca2dd9c8831631489781ef950af5184081 Mon Sep 17 00:00:00 2001 From: Walter Purcaro Date: Tue, 28 Jul 2015 22:06:31 +0200 Subject: Fix https://github.com/pyload/pyload/issues/1520 --- module/plugins/captcha/CircleCaptcha.py | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) (limited to 'module/plugins/captcha') diff --git a/module/plugins/captcha/CircleCaptcha.py b/module/plugins/captcha/CircleCaptcha.py index 7728b4ac9..457d20a35 100644 --- a/module/plugins/captcha/CircleCaptcha.py +++ b/module/plugins/captcha/CircleCaptcha.py @@ -31,7 +31,7 @@ class ImageSequence: class CircleCaptcha(OCR): __name__ = "CircleCaptcha" __type__ = "ocr" - __version__ = "1.02" + __version__ = "1.03" __status__ = "testing" __description__ = """Circle captcha ocr plugin""" @@ -255,7 +255,12 @@ class CircleCaptcha(OCR): missing = 0 missingconsecutive = 0 missinglist = [] - minX = 0 maxX = 0 minY = 0 maxY = 0 + + minX = 0 + maxX = 0 + minY = 0 + maxY = 0 + pointsofcircle = [] if (c[2] < min_ray) or (c[2] > max_ray): -- cgit v1.2.3 From 6f5062a7ac02c8d583c7f9d480be69e3ee83c05c Mon Sep 17 00:00:00 2001 From: Walter Purcaro Date: Wed, 29 Jul 2015 08:41:47 +0200 Subject: Fix https://github.com/pyload/pyload/issues/1520 (3) --- module/plugins/captcha/CircleCaptcha.py | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) (limited to 'module/plugins/captcha') diff --git a/module/plugins/captcha/CircleCaptcha.py b/module/plugins/captcha/CircleCaptcha.py index 457d20a35..dc04a04c8 100644 --- a/module/plugins/captcha/CircleCaptcha.py +++ b/module/plugins/captcha/CircleCaptcha.py @@ -31,7 +31,7 @@ class ImageSequence: class CircleCaptcha(OCR): __name__ = "CircleCaptcha" __type__ = "ocr" - __version__ = "1.03" + __version__ = "1.04" __status__ = "testing" __description__ = """Circle captcha ocr plugin""" @@ -341,7 +341,12 @@ class CircleCaptcha(OCR): missing = 0 missingconsecutive = 0 missinglist = [] - minX = 0 maxX = 0 minY = 0 maxY = 0 + + minX = 0 + maxX = 0 + minY = 0 + maxY = 0 + pointsofcircle = [] if (c[2] < min_ray) or (c[2] > max_ray): -- 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/captcha/ReCaptcha.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'module/plugins/captcha') diff --git a/module/plugins/captcha/ReCaptcha.py b/module/plugins/captcha/ReCaptcha.py index a5aa356e2..5931159c5 100644 --- a/module/plugins/captcha/ReCaptcha.py +++ b/module/plugins/captcha/ReCaptcha.py @@ -84,8 +84,7 @@ class ReCaptcha(CaptchaService): result = self.decrypt(urlparse.urljoin(server, "image"), get={'c': challenge}, cookies=True, - input_type="jpg", - ocr=False) + input_type="jpg") self.log_debug("Result: %s" % result) @@ -173,7 +172,8 @@ class ReCaptcha(CaptchaService): captcha_response = self.decrypt("https://www.google.com/recaptcha/api2/payload", get={'c':token3.group(1), 'k':key}, cookies=True, - ocr=False) + ocr=False, + timeout=30) response = b64encode('{"response":"%s"}' % captcha_response) self.log_debug("Result: %s" % response) -- cgit v1.2.3