summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGravatar RaNaN <Mast3rRaNaN@hotmail.de> 2009-06-17 23:18:27 +0200
committerGravatar RaNaN <Mast3rRaNaN@hotmail.de> 2009-06-17 23:18:27 +0200
commitc5234a8b3d223f9860de161894ae8a4623e1ae05 (patch)
treed98aa17e3c0e738940e8957b390cd32e4b0955ee
parentadded a error message if gui cant connect to server (diff)
downloadpyload-c5234a8b3d223f9860de161894ae8a4623e1ae05.tar.xz
plugins can import captcha method, see #6
-rw-r--r--Plugins/Plugin.py8
-rw-r--r--Plugins/YoutubeCom.py2
-rw-r--r--captcha/GigasizeCom.py15
-rw-r--r--captcha/NetloadIn.py15
-rw-r--r--captcha/captcha.py14
-rw-r--r--captcha/gigasize-com.py14
6 files changed, 41 insertions, 27 deletions
diff --git a/Plugins/Plugin.py b/Plugins/Plugin.py
index a253ffb74..adcaa7678 100644
--- a/Plugins/Plugin.py
+++ b/Plugins/Plugin.py
@@ -26,6 +26,7 @@ class Plugin():
self.time_plus_wait = 0 #time() + wait in seconds
self.want_reconnect = False
self.multi_dl = True
+ self.ocr = None #captcha reader instance
def set_parent_status(self):
""" sets all available Statusinfos about a File in self.parent.status
@@ -74,5 +75,10 @@ class Plugin():
self.config[option] = self.parser.get(self.props['name'], option, raw=True)
self.config[option] = False if self.config[option].lower() == 'false' else self.config[option]
+ def init_ocr(self):
+ modul = __import__("captcha."+ self.props['name'])
+ captchaClass = getattr(modul, self.props['name'])
+ self.ocr = captchaClass()
+
def __call__(self):
- return self.props['name'] \ No newline at end of file
+ return self.props['name']
diff --git a/Plugins/YoutubeCom.py b/Plugins/YoutubeCom.py
index 57025791c..c780345ee 100644
--- a/Plugins/YoutubeCom.py
+++ b/Plugins/YoutubeCom.py
@@ -57,4 +57,4 @@ class YoutubeCom(Plugin):
if re.search(r"(.*eine fehlerhafte Video-ID\.)", self.html) != None:
return False
else:
- return True \ No newline at end of file
+ return True
diff --git a/captcha/GigasizeCom.py b/captcha/GigasizeCom.py
new file mode 100644
index 000000000..136092181
--- /dev/null
+++ b/captcha/GigasizeCom.py
@@ -0,0 +1,15 @@
+from captcha import OCR
+
+class GigasizeCom(OCR):
+ def __init__(self):
+ OCR.__init__(self)
+
+ def get_captcha(self, image):
+ self.load_image(image)
+ self.threshold(2.8)
+ self.run_gocr()
+ return self.result_captcha
+
+if __name__ == '__main__':
+ ocr = GigasizeCom()
+ print ocr.get_captcha('gigasize-com/7.jpg')
diff --git a/captcha/NetloadIn.py b/captcha/NetloadIn.py
index a8fc38757..94103f78b 100644
--- a/captcha/NetloadIn.py
+++ b/captcha/NetloadIn.py
@@ -1,10 +1,11 @@
-from captcha import Ocr
+from captcha import OCR
-class NetloadIn(Ocr):
- def __init__(self, image):
- Ocr.__init__(self, image)
+class NetloadIn(OCR):
+ def __init__(self):
+ OCR.__init__(self)
- def get_captcha(self):
+ def get_captcha(self, image):
+ self.load_image(image)
self.to_greyscale()
self.clean(3)
self.clean(3)
@@ -12,5 +13,5 @@ class NetloadIn(Ocr):
return self.result_captcha
if __name__ == '__main__':
- ocr = NetloadIn('captchas/netload/captcha.php10.png')
- print ocr.get_captcha()
+ ocr = NetloadIn()
+ print ocr.get_captcha('captchas/netload/captcha.php10.png')
diff --git a/captcha/captcha.py b/captcha/captcha.py
index 361893fa3..de3e61cf0 100644
--- a/captcha/captcha.py
+++ b/captcha/captcha.py
@@ -2,13 +2,19 @@ import Image
import ImageOps
import subprocess
-class Ocr(object):
- def __init__(self, image):
+class OCR(object):
+ def __init__(self):
+ pass
+
+ def load_image(self, image):
self.image = Image.open(image)
self.pixels = self.image.load()
self.image_name = 'captcha_clean.png'
self.result_captcha = ''
+ def unload():
+ """delete all tmp images"""
+ pass
def threshold(self, value):
self.image = self.image.point(lambda a: a * value +10)
@@ -27,7 +33,7 @@ class Ocr(object):
self.result_captcha = subprocess.Popen(cmd, stdout=subprocess.PIPE).communicate()[0].replace('\n','')
def get_captcha(self):
- pass
+ raise NotImplementedError
def to_greyscale(self):
if self.image.mode != 'L':
@@ -74,5 +80,5 @@ class Ocr(object):
if __name__ == '__main__':
- ocr = Ocr('gigasize-com/7.jpg')
+ ocr = OCR('gigasize-com/7.jpg')
print ocr.get_captcha()
diff --git a/captcha/gigasize-com.py b/captcha/gigasize-com.py
deleted file mode 100644
index b48e20da4..000000000
--- a/captcha/gigasize-com.py
+++ /dev/null
@@ -1,14 +0,0 @@
-from captcha import Ocr
-
-class Gigasize(Ocr):
- def __init__(self, image):
- Ocr.__init__(self, image)
-
- def get_captcha(self):
- self.threshold(2.8)
- self.run_gocr()
- return self.result_captcha
-
-if __name__ == '__main__':
- ocr = Gigasize('gigasize-com/7.jpg')
- print ocr.get_captcha()