summaryrefslogtreecommitdiffstats
path: root/module/plugins/hooks/Captcha9kw.py
diff options
context:
space:
mode:
authorGravatar Walter Purcaro <vuolter@gmail.com> 2014-11-12 01:29:53 +0100
committerGravatar Walter Purcaro <vuolter@gmail.com> 2014-11-12 01:29:53 +0100
commited52ca7df9dbd4d8b9538219bd76d2cc603e8bf1 (patch)
tree9de0d190a51b8c14c1f505077e27b585893f5bb1 /module/plugins/hooks/Captcha9kw.py
parent[PluginManager] Fix typo (diff)
downloadpyload-ed52ca7df9dbd4d8b9538219bd76d2cc603e8bf1.tar.xz
[Captcha9kw] Code improvements
Diffstat (limited to 'module/plugins/hooks/Captcha9kw.py')
-rwxr-xr-xmodule/plugins/hooks/Captcha9kw.py119
1 files changed, 56 insertions, 63 deletions
diff --git a/module/plugins/hooks/Captcha9kw.py b/module/plugins/hooks/Captcha9kw.py
index cc56ad4a2..bdccf2f76 100755
--- a/module/plugins/hooks/Captcha9kw.py
+++ b/module/plugins/hooks/Captcha9kw.py
@@ -17,14 +17,14 @@ from module.plugins.Hook import Hook
class Captcha9kw(Hook):
__name__ = "Captcha9kw"
__type__ = "hook"
- __version__ = "0.18"
+ __version__ = "0.19"
__config__ = [("activated", "bool", "Activated", True),
("force", "bool", "Force captcha resolving even if client is connected", True),
("confirm", "bool", "Confirm Captcha (cost +6 credits)", False),
("captchaperhour", "int", "Captcha per hour", "9999"),
- ("prio", "int", "Priority (max 20)(cost +0 -> +20 credits)", "0"),
- ("queue", "int", "Max. Queue (max 999)", "0"),
+ ("prio", "int", "Priority (max 10)(cost +0 -> +10 credits)", "0"),
+ ("queue", "int", "Max. Queue (max 999)", "50"),
("hoster_options", "string", "Hoster options (format: pluginname:prio=1:selfsolfe=1:confirm=1:timeout=900|...)", "ShareonlineBiz:prio=0:timeout=999 | UploadedTo:prio=0:timeout=999"),
("selfsolve", "bool", "Selfsolve (manually solve your captcha in your 9kw client if active)", "0"),
("passkey", "password", "API key", ""),
@@ -63,6 +63,7 @@ class Captcha9kw(Hook):
try:
with open(task.captchaFile, 'rb') as f:
data = f.read()
+
except IOError, e:
self.logError(e)
return
@@ -79,7 +80,7 @@ class Captcha9kw(Hook):
'numeric' : 0,
'case_sensitive': 0,
'math' : 0,
- 'prio' : self.getConfig("prio"),
+ 'prio' : min(max(self.getConfig("prio"), 0), 10),
'confirm' : self.getConfig("confirm"),
'timeout' : min(max(self.getConfig("timeout") * 60, 300), 3999),
'selfsolve' : self.getConfig("selfsolve"),
@@ -95,41 +96,44 @@ class Captcha9kw(Hook):
for d in details:
hosteroption = d.split("=")
- if len(hosteroption) <= 1 or not hosteroption[1].isdigit():
+ if len(hosteroption) < 2 or not hosteroption[1].isdigit():
continue
o = hosteroption[0].lower()
if o in option:
option[o] = hosteroption[1]
+ break
+
+ post_data = {'apikey' : self.getConfig("passkey"),
+ 'prio' : option['prio'],
+ 'confirm' : option['confirm'],
+ 'maxtimeout' : option['timeout'],
+ 'selfsolve' : option['selfsolve'],
+ 'captchaperhour': option['cph'],
+ 'case-sensitive': option['case_sensitive'],
+ 'min_len' : option['min'],
+ 'max_len' : option['max'],
+ 'phrase' : option['phrase'],
+ 'numeric' : option['numeric'],
+ 'math' : option['math'],
+ 'oldsource' : pluginname,
+ 'pyload' : "1",
+ 'source' : "pyload",
+ 'base64' : "1",
+ 'mouse' : mouse,
+ 'file-upload-01': data,
+ 'action' : "usercaptchaupload"}
+
for _ in xrange(5):
- post_data = {'apikey' : self.getConfig("passkey"),
- 'prio' : option['prio'],
- 'confirm' : option['confirm'],
- 'maxtimeout' : option['timeout'],
- 'selfsolve' : option['selfsolve'],
- 'captchaperhour': option['cph'],
- 'case-sensitive': option['case_sensitive'],
- 'min_len' : option['min'],
- 'max_len' : option['max'],
- 'phrase' : option['phrase'],
- 'numeric' : option['numeric'],
- 'math' : option['math'],
- 'oldsource' : pluginname,
- 'pyload' : "1",
- 'source' : "pyload",
- 'base64' : "1",
- 'mouse' : mouse,
- 'file-upload-01': data,
- 'action' : "usercaptchaupload"}
try:
res = getURL(self.API_URL, post=post_data)
- if res:
- break
except BadHeader, e:
sleep(3)
-
- if not res.isdigit():
+ else:
+ if res and res.isdigit():
+ break
+ else:
self.logError(_("Bad upload: %s") % res)
return
@@ -138,55 +142,39 @@ class Captcha9kw(Hook):
task.data["ticket"] = res
self.logInfo("result %s : %s" % (res, result))
- for _ in xrange(int(self.getConfig("timeout") / 5)):
- res2 = getURL(self.API_URL,
- get={'apikey': self.getConfig("passkey"),
- 'id' : res,
- 'pyload': "1",
- 'info' : "1",
- 'source': "pyload",
- 'action': "usercaptchacorrectdata"})
-
- if not res2 or res2 == "NO DATA":
- sleep(5)
- else:
- break
-
- task.setResult(res2 or None)
+ task.setResult(self._captchaResponse(task))
def newCaptchaTask(self, task):
if not task.isTextual() and not task.isPositional():
return
- elif not self.getConfig("passkey"):
+ if not self.getConfig("passkey"):
return
- elif self.core.isClientConnected() and not self.getConfig("force"):
+ if self.core.isClientConnected() and not self.getConfig("force"):
return
credits = self.getCredits()
if not credits:
- self.logError(_("Your Captcha 9kw.eu Account has not enough credits"))
+ self.logError(_("Your captcha 9kw.eu account has not enough credits"))
return
- queue = self.getConfig("queue")
+ queue = min(self.getConfig("queue"), 999)
timeout = min(max(self.getConfig("timeout") * 60, 300), 3999)
pluginname = re.search(r'_([^_]*)_\d+.\w+', task.captchaFile).group(1)
- if 1000 > queue > 10:
+ for _ in xrange(5):
servercheck = getURL("http://www.9kw.eu/grafik/servercheck.txt")
- regex = re.compile("queue=(\d+)")
-
- for _ in xrange(3):
- if queue < regex.search(servercheck).group(1):
- break
+ if queue < re.search(r'queue=(\d+)', servercheck).group(1):
+ break
- sleep(10)
+ sleep(10)
+ else:
+ self.fail(_("Too many captchas in queue"))
for opt in self.getConfig("hoster_options").split('|'):
-
details = map(strip(), opt.split(':'))
if not details or details[0].lower() != pluginname.lower():
@@ -200,16 +188,18 @@ class Captcha9kw(Hook):
and hosteroption[1].isdigit()):
timeout = int(hosteroption[1])
+ break
+
task.handler.append(self)
task.setWaiting(timeout)
- start_new_thread(self._processCaptcha, (task,))
+ self._processCaptcha(task)
- def _captchaResponse(self, task, correct):
+ def _captchaResponse(self, task, correct=True):
if "ticket" not in task.data:
- self.logDebug(_("No CaptchaID for %s request (task: %s)" % type) % task)
+ self.logDebug("No CaptchaID for %s request (task: %s)" % type % task)
return
type = "correct" if correct else "refund"
@@ -225,12 +215,15 @@ class Captcha9kw(Hook):
'source' : "pyload",
'id' : task.data["ticket"]})
- if res is "OK":
- self.logInfo(_("Request %s: %s" % type) % res)
- return
+ self.logDebug("Request %s: %s" % type % res)
+
+ if not res or res is "NO DATA":
+ self.logDebug("Could not send %s request: %s" % type % res)
+ sleep(5)
else:
- self.logDebug(_("Could not send %s request: %s" % type) % res)
- sleep(1)
+ return res
+ else:
+ return None
def captchaCorrect(self, task):