summaryrefslogtreecommitdiffstats
path: root/pyload/plugins/captcha
diff options
context:
space:
mode:
Diffstat (limited to 'pyload/plugins/captcha')
-rw-r--r--pyload/plugins/captcha/AdsCaptcha.py70
-rw-r--r--pyload/plugins/captcha/ReCaptcha.py65
-rw-r--r--pyload/plugins/captcha/SolveMedia.py44
-rw-r--r--pyload/plugins/captcha/__init__.py0
4 files changed, 179 insertions, 0 deletions
diff --git a/pyload/plugins/captcha/AdsCaptcha.py b/pyload/plugins/captcha/AdsCaptcha.py
new file mode 100644
index 000000000..845205e4c
--- /dev/null
+++ b/pyload/plugins/captcha/AdsCaptcha.py
@@ -0,0 +1,70 @@
+# -*- coding: utf-8 -*-
+
+import re
+
+from random import random
+
+from pyload.plugins.internal.Captcha import Captcha
+
+
+class AdsCaptcha(Captcha):
+ __name__ = "AdsCaptcha"
+ __type__ = "captcha"
+ __version__ = "0.04"
+
+ __description__ = """AdsCaptcha captcha service plugin"""
+ __license__ = "GPLv3"
+ __authors__ = [("pyLoad Team", "admin@pyload.org")]
+
+
+ ID_PATTERN = r'api\.adscaptcha\.com/Get\.aspx\?[^"\']*CaptchaId=(?P<ID>\d+)'
+ KEY_PATTERN = r'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 not found")
+ self.plugin.error(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 a tuple(CaptchaId, PublicKey)
+ if not key:
+ if self.detect_key():
+ key = self.key
+ else:
+ errmsg = _("AdsCaptcha key not found")
+ self.plugin.error(errmsg)
+ raise TypeError(errmsg)
+
+ CaptchaId, PublicKey = key
+
+ js = self.plugin.req.load("http://api.adscaptcha.com/Get.aspx", get={'CaptchaId': CaptchaId, 'PublicKey': PublicKey})
+
+ try:
+ challenge = re.search("challenge: '(.+?)',", js).group(1)
+ server = re.search("server: '(.+?)',", js).group(1)
+ except:
+ self.plugin.error("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..4516b76de
--- /dev/null
+++ b/pyload/plugins/captcha/ReCaptcha.py
@@ -0,0 +1,65 @@
+# -*- coding: utf-8 -*-
+
+import re
+
+from pyload.plugins.internal.Captcha import Captcha
+
+
+class ReCaptcha(Captcha):
+ __name__ = "ReCaptcha"
+ __type__ = "captcha"
+ __version__ = "0.07"
+
+ __description__ = """ReCaptcha captcha service plugin"""
+ __license__ = "GPLv3"
+ __authors__ = [("pyLoad Team", "admin@pyload.org")]
+
+
+ KEY_PATTERN = r'recaptcha(/api|\.net)/(challenge|noscript)\?k=(?P<KEY>[\w-]+)'
+ KEY_AJAX_PATTERN = r'Recaptcha\.create\s*\(\s*["\'](?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 = _("ReCaptcha html not found")
+ self.plugin.error(errmsg)
+ raise TypeError(errmsg)
+
+ m = re.search(self.KEY_PATTERN, html) or 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.detect_key():
+ key = self.key
+ else:
+ errmsg = _("ReCaptcha key not found")
+ self.plugin.error(errmsg)
+ raise TypeError(errmsg)
+
+ js = self.plugin.req.load("http://www.google.com/recaptcha/api/challenge", get={'k': key})
+
+ try:
+ challenge = re.search("challenge : '(.+?)',", js).group(1)
+ server = re.search("server : '(.+?)',", js).group(1)
+ except:
+ self.plugin.error("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..82f1c4722
--- /dev/null
+++ b/pyload/plugins/captcha/SolveMedia.py
@@ -0,0 +1,44 @@
+# -*- coding: utf-8 -*-
+
+import re
+
+from pyload.plugins.internal.Captcha import Captcha
+
+
+class SolveMedia(Captcha):
+ __name__ = "SolveMedia"
+ __type__ = "captcha"
+ __version__ = "0.05"
+
+ __description__ = """SolveMedia captcha service plugin"""
+ __license__ = "GPLv3"
+ __authors__ = [("pyLoad Team", "admin@pyload.org")]
+
+
+ KEY_PATTERN = r'api\.solvemedia\.com/papi/challenge\.(no)?script\?k=(?P<KEY>.+?)["\']'
+
+
+ def challenge(self, key=None):
+ if not key:
+ if self.detect_key():
+ key = self.key
+ else:
+ errmsg = _("SolveMedia key not found")
+ self.plugin.error(errmsg)
+ raise TypeError(errmsg)
+
+ html = self.plugin.req.load("http://api.solvemedia.com/papi/challenge.noscript", get={'k': key})
+ 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.error("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/captcha/__init__.py b/pyload/plugins/captcha/__init__.py
new file mode 100644
index 000000000..e69de29bb
--- /dev/null
+++ b/pyload/plugins/captcha/__init__.py