summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGravatar Walter Purcaro <vuolter@gmail.com> 2014-10-05 03:31:42 +0200
committerGravatar Walter Purcaro <vuolter@gmail.com> 2014-10-05 03:31:42 +0200
commitd7af6a49593e557ed59355d81dcc03423eaaa9c7 (patch)
tree5fd0900bdc25b3de18bf5f83f4227ba9c891b87d
parentUpdate plugins to work with XFSPHoster (diff)
downloadpyload-d7af6a49593e557ed59355d81dcc03423eaaa9c7.tar.xz
Split CaptchaService to captcha directory
-rw-r--r--pyload/plugins/base/Captcha.py110
-rw-r--r--pyload/plugins/captcha/AdsCaptcha.py69
-rw-r--r--pyload/plugins/captcha/ReCaptcha.py66
-rw-r--r--pyload/plugins/captcha/SolveMedia.py43
-rw-r--r--pyload/plugins/internal/CaptchaService.py210
5 files changed, 288 insertions, 210 deletions
diff --git a/pyload/plugins/base/Captcha.py b/pyload/plugins/base/Captcha.py
new file mode 100644
index 000000000..4aafedd5f
--- /dev/null
+++ b/pyload/plugins/base/Captcha.py
@@ -0,0 +1,110 @@
+# -*- coding: utf-8 -*-
+
+import re
+
+from pyload.plugins.Plugin import Plugin
+
+
+class Captcha(Plugin):
+ __name__ = "Captcha"
+ __version__ = "0.09"
+
+ __description__ = """Base captcha service plugin"""
+ __author_name__ = "pyLoad Team"
+ __author_mail__ = "admin@pyload.org"
+
+ KEY_PATTERN = None
+
+ key = None
+
+
+ def __init__(self, plugin):
+ self.plugin = plugin
+
+
+ def detect_key(self, html=None):
+ if not html:
+ if hasattr(self.plugin, "html") and self.plugin.html:
+ html = self.plugin.html
+ else:
+ errmsg = "%s html missing" % self.__name__
+ self.plugin.fail(errmsg)
+ raise TypeError(errmsg)
+
+ m = re.search(self.KEY_PATTERN, html)
+ if m:
+ self.key = m.group("KEY")
+ self.plugin.logDebug("%s key: %s" % (self.__name__, self.key))
+ return self.key
+ else:
+ self.plugin.logDebug("%s key not found" % self.__name__)
+ return None
+
+
+ def challenge(self, key=None):
+ raise NotImplementedError
+
+
+ def result(self, server, challenge):
+ raise NotImplementedError
+
+
+class ReCaptcha(CaptchaService):
+ __name__ = "ReCaptcha"
+ __version__ = "0.02"
+
+ __description__ = """ReCaptcha captcha service plugin"""
+ __author_name__ = "pyLoad Team"
+ __author_mail__ = "admin@pyload.org"
+
+
+ KEY_PATTERN = r"https?://(?:www\.)?google\.com/recaptcha/api/challenge\?k=(?P<KEY>\w+?)"
+ KEY_AJAX_PATTERN = r"Recaptcha\.create\s*\(\s*[\"'](?P<KEY>\w+)[\"']\s*,"
+
+
+ def detect_key(self, html=None):
+ if not html:
+ if hasattr(self.plugin, "html") and self.plugin.html:
+ html = self.plugin.html
+ else:
+ errmsg = "ReCaptcha html missing"
+ self.plugin.fail(errmsg)
+ raise TypeError(errmsg)
+
+ m = re.search(self.KEY_PATTERN, html)
+ if m is None:
+ m = re.search(self.KEY_AJAX_PATTERN, html)
+ if m:
+ self.key = m.group("KEY")
+ self.plugin.logDebug("ReCaptcha key: %s" % self.key)
+ return self.key
+ else:
+ self.plugin.logDebug("ReCaptcha key not found")
+ return None
+
+
+ def challenge(self, key=None):
+ if not key:
+ if self.key:
+ key = self.key
+ else:
+ errmsg = "ReCaptcha key missing"
+ self.plugin.fail(errmsg)
+ raise TypeError(errmsg)
+
+ js = self.plugin.req.load("http://www.google.com/recaptcha/api/challenge", get={'k': key}, cookies=True)
+
+ try:
+ challenge = re.search("challenge : '(.+?)',", js).group(1)
+ server = re.search("server : '(.+?)',", js).group(1)
+ except:
+ self.plugin.parseError("ReCaptcha challenge pattern not found")
+
+ result = self.result(server, challenge)
+
+ return challenge, result
+
+
+ def result(self, server, challenge):
+ return self.plugin.decryptCaptcha("%simage" % server, get={'c': challenge},
+ cookies=True, forceUser=True, imgtype="jpg")
diff --git a/pyload/plugins/captcha/AdsCaptcha.py b/pyload/plugins/captcha/AdsCaptcha.py
new file mode 100644
index 000000000..277adf3cf
--- /dev/null
+++ b/pyload/plugins/captcha/AdsCaptcha.py
@@ -0,0 +1,69 @@
+# -*- coding: utf-8 -*-
+
+import re
+
+from random import random
+
+from pyload.plugins.base.Captcha import Captcha
+
+
+class AdsCaptcha(Captcha):
+ __name__ = "AdsCaptcha"
+ __version__ = "0.02"
+
+ __description__ = """AdsCaptcha captcha service plugin"""
+ __author_name__ = "pyLoad Team"
+ __author_mail__ = "admin@pyload.org"
+
+
+ ID_PATTERN = r'http://api\.adscaptcha\.com/Get\.aspx\?[^"\']*CaptchaId=(?P<ID>\d+)'
+ KEY_PATTERN = r'http://api\.adscaptcha\.com/Get\.aspx\?[^"\']*PublicKey=(?P<KEY>[\w-]+)'
+
+
+ def detect_key(self, html=None):
+ if not html:
+ if hasattr(self.plugin, "html") and self.plugin.html:
+ html = self.plugin.html
+ else:
+ errmsg = "AdsCaptcha html missing"
+ self.plugin.fail(errmsg)
+ raise TypeError(errmsg)
+
+ m = re.search(self.ID_PATTERN, html)
+ n = re.search(self.KEY_PATTERN, html)
+ if m and n:
+ self.key = (m.group("ID"), m.group("KEY"))
+ self.plugin.logDebug("AdsCaptcha id|key: %s | %s" % self.key)
+ return self.key
+ else:
+ self.plugin.logDebug("AdsCaptcha id or key not found")
+ return None
+
+
+ def challenge(self, key=None): #: key is tuple(CaptchaId, PublicKey)
+ if not key:
+ if self.key:
+ key = self.key
+ else:
+ errmsg = "AdsCaptcha key missing"
+ self.plugin.fail(errmsg)
+ raise TypeError(errmsg)
+
+ CaptchaId, PublicKey = key
+
+ js = self.plugin.req.load("http://api.adscaptcha.com/Get.aspx", get={'CaptchaId': CaptchaId, 'PublicKey': PublicKey}, cookies=True)
+
+ try:
+ challenge = re.search("challenge: '(.+?)',", js).group(1)
+ server = re.search("server: '(.+?)',", js).group(1)
+ except:
+ self.plugin.parseError("AdsCaptcha challenge pattern not found")
+
+ result = self.result(server, challenge)
+
+ return challenge, result
+
+
+ def result(self, server, challenge):
+ return self.plugin.decryptCaptcha("%sChallenge.aspx" % server, get={'cid': challenge, 'dummy': random()},
+ cookies=True, imgtype="jpg")
diff --git a/pyload/plugins/captcha/ReCaptcha.py b/pyload/plugins/captcha/ReCaptcha.py
new file mode 100644
index 000000000..841629e9d
--- /dev/null
+++ b/pyload/plugins/captcha/ReCaptcha.py
@@ -0,0 +1,66 @@
+# -*- coding: utf-8 -*-
+
+import re
+
+from pyload.plugins.base.Captcha import Captcha
+
+
+class ReCaptcha(Captcha):
+ __name__ = "ReCaptcha"
+ __version__ = "0.02"
+
+ __description__ = """ReCaptcha captcha service plugin"""
+ __author_name__ = "pyLoad Team"
+ __author_mail__ = "admin@pyload.org"
+
+
+ KEY_PATTERN = r"https?://(?:www\.)?google\.com/recaptcha/api/challenge\?k=(?P<KEY>\w+?)"
+ KEY_AJAX_PATTERN = r"Recaptcha\.create\s*\(\s*[\"'](?P<KEY>\w+)[\"']\s*,"
+
+
+ def detect_key(self, html=None):
+ if not html:
+ if hasattr(self.plugin, "html") and self.plugin.html:
+ html = self.plugin.html
+ else:
+ errmsg = "ReCaptcha html missing"
+ self.plugin.fail(errmsg)
+ raise TypeError(errmsg)
+
+ m = re.search(self.KEY_PATTERN, html)
+ if m is None:
+ m = re.search(self.KEY_AJAX_PATTERN, html)
+ if m:
+ self.key = m.group("KEY")
+ self.plugin.logDebug("ReCaptcha key: %s" % self.key)
+ return self.key
+ else:
+ self.plugin.logDebug("ReCaptcha key not found")
+ return None
+
+
+ def challenge(self, key=None):
+ if not key:
+ if self.key:
+ key = self.key
+ else:
+ errmsg = "ReCaptcha key missing"
+ self.plugin.fail(errmsg)
+ raise TypeError(errmsg)
+
+ js = self.plugin.req.load("http://www.google.com/recaptcha/api/challenge", get={'k': key}, cookies=True)
+
+ try:
+ challenge = re.search("challenge : '(.+?)',", js).group(1)
+ server = re.search("server : '(.+?)',", js).group(1)
+ except:
+ self.plugin.parseError("ReCaptcha challenge pattern not found")
+
+ result = self.result(server, challenge)
+
+ return challenge, result
+
+
+ def result(self, server, challenge):
+ return self.plugin.decryptCaptcha("%simage" % server, get={'c': challenge},
+ cookies=True, forceUser=True, imgtype="jpg")
diff --git a/pyload/plugins/captcha/SolveMedia.py b/pyload/plugins/captcha/SolveMedia.py
new file mode 100644
index 000000000..c1855cdfe
--- /dev/null
+++ b/pyload/plugins/captcha/SolveMedia.py
@@ -0,0 +1,43 @@
+# -*- coding: utf-8 -*-
+
+import re
+
+from pyload.plugins.base.Captcha import Captcha
+
+
+class SolveMedia(Captcha):
+ __name__ = "SolveMedia"
+ __version__ = "0.02"
+
+ __description__ = """SolveMedia captcha service plugin"""
+ __author_name__ = "pyLoad Team"
+ __author_mail__ = "admin@pyload.org"
+
+
+ KEY_PATTERN = r'http://api\.solvemedia\.com/papi/challenge\.(no)?script\?k=(?P<KEY>.+?)"'
+
+
+ def challenge(self, key=None):
+ if not key:
+ if self.key:
+ key = self.key
+ else:
+ errmsg = "SolveMedia key missing"
+ self.plugin.fail(errmsg)
+ raise TypeError(errmsg)
+
+ html = self.plugin.req.load("http://api.solvemedia.com/papi/challenge.noscript", get={'k': key}, cookies=True)
+ try:
+ challenge = re.search(r'<input type=hidden name="adcopy_challenge" id="adcopy_challenge" value="([^"]+)">',
+ html).group(1)
+ server = "http://api.solvemedia.com/papi/media"
+ except:
+ self.plugin.parseError("SolveMedia challenge pattern not found")
+
+ result = self.result(server, challenge)
+
+ return challenge, result
+
+
+ def result(self, server, challenge):
+ return self.plugin.decryptCaptcha(server, get={'c': challenge}, imgtype="gif")
diff --git a/pyload/plugins/internal/CaptchaService.py b/pyload/plugins/internal/CaptchaService.py
deleted file mode 100644
index b2fba0652..000000000
--- a/pyload/plugins/internal/CaptchaService.py
+++ /dev/null
@@ -1,210 +0,0 @@
-# -*- coding: utf-8 -*-
-
-import re
-
-from random import random
-
-
-class CaptchaService:
- __name__ = "CaptchaService"
- __version__ = "0.09"
-
- __description__ = """Base captcha service plugin"""
- __author_name__ = "pyLoad Team"
- __author_mail__ = "admin@pyload.org"
-
- KEY_PATTERN = None
-
- key = None
-
-
- def __init__(self, plugin):
- self.plugin = plugin
-
-
- def detect_key(self, html=None):
- if not html:
- if hasattr(self.plugin, "html") and self.plugin.html:
- html = self.plugin.html
- else:
- errmsg = "%s html missing" % self.__name__
- self.plugin.fail(errmsg)
- raise TypeError(errmsg)
-
- m = re.search(self.KEY_PATTERN, html)
- if m:
- self.key = m.group("KEY")
- self.plugin.logDebug("%s key: %s" % (self.__name__, self.key))
- return self.key
- else:
- self.plugin.logDebug("%s key not found" % self.__name__)
- return None
-
-
- def challenge(self, key=None):
- raise NotImplementedError
-
-
- def result(self, server, challenge):
- raise NotImplementedError
-
-
-class ReCaptcha(CaptchaService):
- __name__ = "ReCaptcha"
- __version__ = "0.02"
-
- __description__ = """ReCaptcha captcha service plugin"""
- __author_name__ = "pyLoad Team"
- __author_mail__ = "admin@pyload.org"
-
-
- KEY_PATTERN = r"https?://(?:www\.)?google\.com/recaptcha/api/challenge\?k=(?P<KEY>\w+?)"
- KEY_AJAX_PATTERN = r"Recaptcha\.create\s*\(\s*[\"'](?P<KEY>\w+)[\"']\s*,"
-
-
- def detect_key(self, html=None):
- if not html:
- if hasattr(self.plugin, "html") and self.plugin.html:
- html = self.plugin.html
- else:
- errmsg = "ReCaptcha html missing"
- self.plugin.fail(errmsg)
- raise TypeError(errmsg)
-
- m = re.search(self.KEY_PATTERN, html)
- if m is None:
- m = re.search(self.KEY_AJAX_PATTERN, html)
- if m:
- self.key = m.group("KEY")
- self.plugin.logDebug("ReCaptcha key: %s" % self.key)
- return self.key
- else:
- self.plugin.logDebug("ReCaptcha key not found")
- return None
-
-
- def challenge(self, key=None):
- if not key:
- if self.key:
- key = self.key
- else:
- errmsg = "ReCaptcha key missing"
- self.plugin.fail(errmsg)
- raise TypeError(errmsg)
-
- js = self.plugin.req.load("http://www.google.com/recaptcha/api/challenge", get={'k': key}, cookies=True)
-
- try:
- challenge = re.search("challenge : '(.+?)',", js).group(1)
- server = re.search("server : '(.+?)',", js).group(1)
- except:
- self.plugin.parseError("ReCaptcha challenge pattern not found")
-
- result = self.result(server, challenge)
-
- return challenge, result
-
-
- def result(self, server, challenge):
- return self.plugin.decryptCaptcha("%simage" % server, get={'c': challenge},
- cookies=True, forceUser=True, imgtype="jpg")
-
-
-class AdsCaptcha(CaptchaService):
- __name__ = "AdsCaptcha"
- __version__ = "0.02"
-
- __description__ = """AdsCaptcha captcha service plugin"""
- __author_name__ = "pyLoad Team"
- __author_mail__ = "admin@pyload.org"
-
-
- ID_PATTERN = r'http://api\.adscaptcha\.com/Get\.aspx\?[^"\']*CaptchaId=(?P<ID>\d+)'
- KEY_PATTERN = r'http://api\.adscaptcha\.com/Get\.aspx\?[^"\']*PublicKey=(?P<KEY>[\w-]+)'
-
-
- def detect_key(self, html=None):
- if not html:
- if hasattr(self.plugin, "html") and self.plugin.html:
- html = self.plugin.html
- else:
- errmsg = "AdsCaptcha html missing"
- self.plugin.fail(errmsg)
- raise TypeError(errmsg)
-
- m = re.search(self.ID_PATTERN, html)
- n = re.search(self.KEY_PATTERN, html)
- if m and n:
- self.key = (m.group("ID"), m.group("KEY"))
- self.plugin.logDebug("AdsCaptcha id|key: %s | %s" % self.key)
- return self.key
- else:
- self.plugin.logDebug("AdsCaptcha id or key not found")
- return None
-
-
- def challenge(self, key=None): #: key is tuple(CaptchaId, PublicKey)
- if not key:
- if self.key:
- key = self.key
- else:
- errmsg = "AdsCaptcha key missing"
- self.plugin.fail(errmsg)
- raise TypeError(errmsg)
-
- CaptchaId, PublicKey = key
-
- js = self.plugin.req.load("http://api.adscaptcha.com/Get.aspx", get={'CaptchaId': CaptchaId, 'PublicKey': PublicKey}, cookies=True)
-
- try:
- challenge = re.search("challenge: '(.+?)',", js).group(1)
- server = re.search("server: '(.+?)',", js).group(1)
- except:
- self.plugin.parseError("AdsCaptcha challenge pattern not found")
-
- result = self.result(server, challenge)
-
- return challenge, result
-
-
- def result(self, server, challenge):
- return self.plugin.decryptCaptcha("%sChallenge.aspx" % server, get={'cid': challenge, 'dummy': random()},
- cookies=True, imgtype="jpg")
-
-
-class SolveMedia(CaptchaService):
- __name__ = "SolveMedia"
- __version__ = "0.02"
-
- __description__ = """SolveMedia captcha service plugin"""
- __author_name__ = "pyLoad Team"
- __author_mail__ = "admin@pyload.org"
-
-
- KEY_PATTERN = r'http://api\.solvemedia\.com/papi/challenge\.(no)?script\?k=(?P<KEY>.+?)"'
-
-
- def challenge(self, key=None):
- if not key:
- if self.key:
- key = self.key
- else:
- errmsg = "SolveMedia key missing"
- self.plugin.fail(errmsg)
- raise TypeError(errmsg)
-
- html = self.plugin.req.load("http://api.solvemedia.com/papi/challenge.noscript", get={'k': key}, cookies=True)
- try:
- challenge = re.search(r'<input type=hidden name="adcopy_challenge" id="adcopy_challenge" value="([^"]+)">',
- html).group(1)
- server = "http://api.solvemedia.com/papi/media"
- except:
- self.plugin.parseError("SolveMedia challenge pattern not found")
-
- result = self.result(server, challenge)
-
- return challenge, result
-
-
- def result(self, server, challenge):
- return self.plugin.decryptCaptcha(server, get={'c': challenge}, imgtype="gif")