summaryrefslogtreecommitdiffstats
path: root/module/plugins/hooks/BypassCaptcha.py
diff options
context:
space:
mode:
authorGravatar lazlev <lazlev@yopmail.com> 2015-08-09 00:50:54 +0200
committerGravatar lazlev <lazlev@yopmail.com> 2015-08-09 00:50:54 +0200
commitb0ef3f1673e1930916604bb1264ca3a38414bc8d (patch)
treec97936e4d2a4cd6eb1072c65c8a08a7d18816b18 /module/plugins/hooks/BypassCaptcha.py
parent[XFileSharingPro][XFileSharingProFolder] Added default __pattern__ (diff)
parentFix https://github.com/pyload/pyload/issues/1707 (diff)
downloadpyload-b0ef3f1673e1930916604bb1264ca3a38414bc8d.tar.xz
Merge pull request #1 from pyload/stable
sync with stable
Diffstat (limited to 'module/plugins/hooks/BypassCaptcha.py')
-rw-r--r--module/plugins/hooks/BypassCaptcha.py71
1 files changed, 33 insertions, 38 deletions
diff --git a/module/plugins/hooks/BypassCaptcha.py b/module/plugins/hooks/BypassCaptcha.py
index 9e01edfa2..4b155a67e 100644
--- a/module/plugins/hooks/BypassCaptcha.py
+++ b/module/plugins/hooks/BypassCaptcha.py
@@ -3,8 +3,8 @@
import pycurl
from module.network.HTTPRequest import BadHeader
-from module.network.RequestFactory import getURL, getRequest
-from module.plugins.Hook import Hook, threaded
+from module.network.RequestFactory import getRequest as get_request
+from module.plugins.internal.Hook import Hook, threaded
class BypassCaptchaException(Exception):
@@ -13,7 +13,7 @@ class BypassCaptchaException(Exception):
self.err = err
- def getCode(self):
+ def get_code(self):
return self.err
@@ -28,10 +28,11 @@ class BypassCaptchaException(Exception):
class BypassCaptcha(Hook):
__name__ = "BypassCaptcha"
__type__ = "hook"
- __version__ = "0.06"
+ __version__ = "0.08"
+ __status__ = "testing"
- __config__ = [("force", "bool", "Force BC even if client is connected", False),
- ("passkey", "password", "Passkey", "")]
+ __config__ = [("passkey" , "password", "Access key" , "" ),
+ ("check_client", "bool" , "Don't use if client is connected", True)]
__description__ = """Send captchas to BypassCaptcha.com"""
__license__ = "GPLv3"
@@ -40,8 +41,6 @@ class BypassCaptcha(Hook):
("zoidberg" , "zoidberg@mujmail.cz" )]
- interval = 0 #@TODO: Remove in 0.4.10
-
PYLOAD_KEY = "4f771155b640970d5607f919a615bdefc67e7d32"
SUBMIT_URL = "http://bypasscaptcha.com/upload.php"
@@ -49,30 +48,26 @@ class BypassCaptcha(Hook):
GETCREDITS_URL = "http://bypasscaptcha.com/ex_left.php"
- def setup(self):
- self.info = {} #@TODO: Remove in 0.4.10
-
-
- def getCredits(self):
- res = getURL(self.GETCREDITS_URL, post={"key": self.getConfig('passkey')})
+ def get_credits(self):
+ res = self.load(self.GETCREDITS_URL, post={'key': self.get_config('passkey')})
data = dict(x.split(' ', 1) for x in res.splitlines())
return int(data['Left'])
def submit(self, captcha, captchaType="file", match=None):
- req = getRequest()
+ req = get_request()
- #raise timeout threshold
+ #: Raise timeout threshold
req.c.setopt(pycurl.LOW_SPEED_TIME, 80)
try:
- res = req.load(self.SUBMIT_URL,
- post={'vendor_key': self.PYLOAD_KEY,
- 'key': self.getConfig('passkey'),
- 'gen_task_id': "1",
- 'file': (pycurl.FORM_FILE, captcha)},
- multipart=True)
+ res = self.load(self.SUBMIT_URL,
+ post={'vendor_key': self.PYLOAD_KEY,
+ 'key': self.get_config('passkey'),
+ 'gen_task_id': "1",
+ 'file': (pycurl.FORM_FILE, captcha)},
+ req=req)
finally:
req.close()
@@ -82,59 +77,59 @@ class BypassCaptcha(Hook):
result = data['Value']
ticket = data['TaskId']
- self.logDebug("Result %s : %s" % (ticket, result))
+ self.log_debug("Result %s : %s" % (ticket, result))
return ticket, result
def respond(self, ticket, success):
try:
- res = getURL(self.RESPOND_URL, post={"task_id": ticket, "key": self.getConfig('passkey'),
- "cv": 1 if success else 0})
+ res = self.load(self.RESPOND_URL, post={'task_id': ticket, 'key': self.get_config('passkey'),
+ 'cv': 1 if success else 0})
except BadHeader, e:
- self.logError(_("Could not send response"), e)
+ self.log_error(_("Could not send response"), e)
- def newCaptchaTask(self, task):
+ def captcha_task(self, task):
if "service" in task.data:
return False
if not task.isTextual():
return False
- if not self.getConfig('passkey'):
+ if not self.get_config('passkey'):
return False
- if self.core.isClientConnected() and not self.getConfig('force'):
+ if self.pyload.isClientConnected() and self.get_config('check_client'):
return False
- if self.getCredits() > 0:
+ if self.get_credits() > 0:
task.handler.append(self)
task.data['service'] = self.__name__
task.setWaiting(100)
- self._processCaptcha(task)
+ self._process_captcha(task)
else:
- self.logInfo(_("Your %s account has not enough credits") % self.__name__)
+ self.log_info(_("Your %s account has not enough credits") % self.__name__)
- def captchaCorrect(self, task):
- if task.data['service'] == self.__name__ and "ticket" in task.data:
+ def captcha_correct(self, task):
+ if task.data['service'] is self.__name__ and "ticket" in task.data:
self.respond(task.data['ticket'], True)
- def captchaInvalid(self, task):
- if task.data['service'] == self.__name__ and "ticket" in task.data:
+ def captcha_invalid(self, task):
+ if task.data['service'] is self.__name__ and "ticket" in task.data:
self.respond(task.data['ticket'], False)
@threaded
- def _processCaptcha(self, task):
+ def _process_captcha(self, task):
c = task.captchaFile
try:
ticket, result = self.submit(c)
except BypassCaptchaException, e:
- task.error = e.getCode()
+ task.error = e.get_code()
return
task.data['ticket'] = ticket