diff options
author | zoidberg10 <zoidberg@mujmail.cz> | 2012-08-06 23:35:22 +0200 |
---|---|---|
committer | zoidberg10 <zoidberg@mujmail.cz> | 2012-08-06 23:35:22 +0200 |
commit | 463616f77924b7cad96165c18e4e6f4fce1ca6da (patch) | |
tree | dd80a1c54246cca9d06cb77374ecdc82b89afa09 /module/plugins/hooks | |
parent | updated Serienjunkies, Shareonline - closed #571, #409 (diff) | |
download | pyload-463616f77924b7cad96165c18e4e6f4fce1ca6da.tar.xz |
fix bypasscaptcha, add imagetyperz
Diffstat (limited to 'module/plugins/hooks')
-rw-r--r-- | module/plugins/hooks/BypassCaptcha.py | 118 | ||||
-rw-r--r-- | module/plugins/hooks/CaptchaBrotherhood.py | 15 | ||||
-rw-r--r-- | module/plugins/hooks/ImageTyperz.py | 142 |
3 files changed, 198 insertions, 77 deletions
diff --git a/module/plugins/hooks/BypassCaptcha.py b/module/plugins/hooks/BypassCaptcha.py index c68f8a66b..24ad17dd8 100644 --- a/module/plugins/hooks/BypassCaptcha.py +++ b/module/plugins/hooks/BypassCaptcha.py @@ -13,23 +13,18 @@ You should have received a copy of the GNU General Public License along with this program; if not, see <http://www.gnu.org/licenses/>. - @author: RaNaN + @author: RaNaN, Godofdream, zoidberg """ -import base64 - -try: - from json import loads -except ImportError: - from simplejson import loads - from thread import start_new_thread from pycurl import FORM_FILE, LOW_SPEED_TIME from module.network.RequestFactory import getURL, getRequest from module.network.HTTPRequest import BadHeader -from module.plugins.Addon import Addon +from module.plugins.Hook import Hook + +PYLOAD_KEY = "4f771155b640970d5607f919a615bdefc67e7d32" class BypassCaptchaException(Exception): def __init__(self, err): @@ -44,15 +39,15 @@ class BypassCaptchaException(Exception): def __repr__(self): return "<BypassCaptchaException %s>" % self.err -class BypassCaptcha(Addon): +class BypassCaptcha(Hook): __name__ = "BypassCaptcha" - __version__ = "0.02" - __description__ = """send captchas to bypasscaptcha.com""" + __version__ = "0.03" + __description__ = """send captchas to BypassCaptcha.com""" __config__ = [("activated", "bool", "Activated", True), - ("key", "str", "Key", ""), - ("force", "bool", "Force CT even if client is connected", False),] - __author_name__ = ("Godofdream") - __author_mail__ = ("soilfcition@gmail.com") + ("force", "bool", "Force BC even if client is connected", False), + ("passkey", "password", "Passkey", "")] + __author_name__ = ("RaNaN", "Godofdream", "zoidberg") + __author_mail__ = ("RaNaN@pyload.org", "soilfcition@gmail.com", "zoidberg@mujmail.cz") SUBMIT_URL = "http://bypasscaptcha.com/upload.php" RESPOND_URL = "http://bypasscaptcha.com/check_value.php" @@ -62,76 +57,58 @@ class BypassCaptcha(Addon): self.info = {} def getCredits(self): - json = getURL(BypassCaptcha.GETCREDITS_URL % {"key": self.getConfig("key")}) - response = loads(json) - if response[0] < 0: - raise BypassCaptchaException(response[1]) - else: - self.logInfo(_("%s credits left") % response['Left']) - self.info["credits"] = response['Left'] - return response['Left'] + response = getURL(self.GETCREDITS_URL, + post = {"key": self.getConfig("passkey")} + ) + + data = dict([x.split(' ',1) for x in response.splitlines()]) + return int(data['Left']) + def submit(self, captcha, captchaType="file", match=None): - #if type(captcha) == str and captchaType == "file": - # raise BypassCaptchaException("Invalid Type") - assert captchaType in ("file", "url-jpg", "url-jpeg", "url-png", "url-bmp") - - self.logInfo(_("submitting %s, type %s") % (captcha, captchaType)) - req = getRequest() #raise timeout threshold req.c.setopt(LOW_SPEED_TIME, 80) - try: - img = Image.open(captcha) - self.logDebug("CAPTCHA IMAGE", img, img.format) - output = StringIO.StringIO() - img.save(output, "JPEG") - data = base64.b64encode(output.getvalue()) - output.close() - except Exception, e: - raise BypassCaptchaException("Reading or converting captcha image failed: %s" % e) - try: - json = req.load(BypassCaptcha.SUBMIT_URL, post={"key": self.getConfig("key"), - "password": self.getConfig("passkey"), - "file": data, - "submit": "Submit", - "gen_task_id": 1, - "base64_code": 1}) + response = req.load(self.SUBMIT_URL, + post={"vendor_key": PYLOAD_KEY, + "key": self.getConfig("passkey"), + "gen_task_id": "1", + "file": (FORM_FILE, captcha)}, + multipart=True) finally: req.close() - response = loads(json) - if response[0] < 0: - raise BypassCaptchaException(response[1]) - - ticket = response['TaskId'] - result = response['Value'] + data = dict([x.split(' ',1) for x in response.splitlines()]) + if not data or "Value" not in data: + raise BypassCaptchaException(response) + + result = data['Value'] + ticket = data['TaskId'] self.logDebug("result %s : %s" % (ticket,result)) return ticket, result def respond(self, ticket, success): try: - json = getURL(BypassCaptcha.RESPOND_URL, post={ "key": self.getConfig("key"), - "task_id": ticket, - "cv": 1 if success else 0, - "submit": "Submit" }) - - response = loads(json) - if response[0] < 0: - raise BypassCaptchaException(response[1]) - + response = getURL(self.RESPOND_URL, + post={"task_id": ticket, + "key": self.getConfig("passkey"), + "cv": 1 if success else 0} + ) except BadHeader, e: - self.logError(_("Could not send response."), str(e)) + self.logError("Could not send response.", str(e)) def newCaptchaTask(self, task): + if "service" in task.data: + return False + if not task.isTextual(): return False - if not self.getConfig("key"): + if not self.getConfig("passkey"): return False if self.core.isClientConnected() and not self.getConfig("force"): @@ -139,21 +116,20 @@ class BypassCaptcha(Addon): if self.getCredits() > 0: task.handler.append(self) + task.data['service'] = self.__name__ task.setWaiting(100) start_new_thread(self.processCaptcha, (task,)) else: - self.logInfo(_("Your BypassCaptcha Account has not enough credits")) + self.logInfo("Your %s account has not enough credits" % self.__name__) def captchaCorrect(self, task): - if "TaskId" in task.data: - ticket = task.data["TaskId"] - self.respond(ticket, True) + if task.data['service'] == self.__name__ and "ticket" in task.data: + self.respond(task.data["ticket"], True) def captchaInvalid(self, task): - if "TaskId" in task.data: - ticket = task.data["TaskId"] - self.respond(ticket, False) + if task.data['service'] == self.__name__ and "ticket" in task.data: + self.respond(task.data["ticket"], False) def processCaptcha(self, task): c = task.captchaFile @@ -164,4 +140,4 @@ class BypassCaptcha(Addon): return task.data["ticket"] = ticket - task.setResult(result) + task.setResult(result)
\ No newline at end of file diff --git a/module/plugins/hooks/CaptchaBrotherhood.py b/module/plugins/hooks/CaptchaBrotherhood.py index d03387527..d3c1dd043 100644 --- a/module/plugins/hooks/CaptchaBrotherhood.py +++ b/module/plugins/hooks/CaptchaBrotherhood.py @@ -44,14 +44,14 @@ class CaptchaBrotherhoodException(Exception): class CaptchaBrotherhood(Hook): __name__ = "CaptchaBrotherhood" - __version__ = "0.01" + __version__ = "0.02" __description__ = """send captchas to CaptchaBrotherhood.com""" __config__ = [("activated", "bool", "Activated", False), ("username", "str", "Username", ""), ("force", "bool", "Force CT even if client is connected", False), ("passkey", "password", "Password", ""),] - __author_name__ = ("RaNaN") - __author_mail__ = ("RaNaN@pyload.org") + __author_name__ = ("RaNaN", "zoidberg") + __author_mail__ = ("RaNaN@pyload.org", "zoidberg@mujmail.cz") API_URL = "http://ocrhood.gazcad.com/" @@ -86,7 +86,7 @@ class CaptchaBrotherhood(Hook): url = "%ssendNewCaptcha.aspx?%s" % (self.API_URL, urlencode({"username": self.getConfig("username"), "password": self.getConfig("passkey"), - "captchaSource": "jdPlugin", + "captchaSource": "pyLoad", "timeout": "80"}) ) @@ -128,6 +128,9 @@ class CaptchaBrotherhood(Hook): return response def newCaptchaTask(self, task): + if "service" in task.data: + return False + if not task.isTextual(): return False @@ -137,16 +140,16 @@ class CaptchaBrotherhood(Hook): if self.core.isClientConnected() and not self.getConfig("force"): return False - print self.getCredits() if self.getCredits() > 10: task.handler.append(self) + task.data['service'] = self.__name__ task.setWaiting(100) start_new_thread(self.processCaptcha, (task,)) else: self.logInfo("Your CaptchaBrotherhood Account has not enough credits") def captchaInvalid(self, task): - if "ticket" in task.data: + if task.data['service'] == self.__name__ and "ticket" in task.data: response = self.get_api("complainCaptcha", ticket) def processCaptcha(self, task): diff --git a/module/plugins/hooks/ImageTyperz.py b/module/plugins/hooks/ImageTyperz.py new file mode 100644 index 000000000..5edde0a8a --- /dev/null +++ b/module/plugins/hooks/ImageTyperz.py @@ -0,0 +1,142 @@ +# -*- coding: utf-8 -*- +""" + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 3 of the License, + or (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. + See the GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, see <http://www.gnu.org/licenses/>. + + @author: mkaay, RaNaN, zoidberg +""" + +from thread import start_new_thread +from pycurl import FORM_FILE, LOW_SPEED_TIME + +from module.network.RequestFactory import getURL, getRequest +from module.network.HTTPRequest import BadHeader + +from module.plugins.Hook import Hook + +class ImageTyperzException(Exception): + def __init__(self, err): + self.err = err + + def getCode(self): + return self.err + + def __str__(self): + return "<ImageTyperzException %s>" % self.err + + def __repr__(self): + return "<ImageTyperzException %s>" % self.err + +class ImageTyperz(Hook): + __name__ = "ImageTyperz" + __version__ = "0.01" + __description__ = """send captchas to ImageTyperz.com""" + __config__ = [("activated", "bool", "Activated", True), + ("username", "str", "Username", ""), + ("passkey", "password", "Password", ""), + ("force", "bool", "Force IT even if client is connected", False)] + __author_name__ = ("RaNaN", "zoidberg") + __author_mail__ = ("RaNaN@pyload.org", "zoidberg@mujmail.cz") + + SUBMIT_URL = "http://captchatypers.com/Forms/UploadFileAndGetTextNEW.ashx" + RESPOND_URL = "http://captchatypers.com/Forms/SetBadImage.ashx" + GETCREDITS_URL = "http://captchatypers.com/Forms/RequestBalance.ashx" + + def setup(self): + self.info = {} + + def getCredits(self): + response = getURL(self.GETCREDITS_URL, + post = {"action": "REQUESTBALANCE", + "username": self.getConfig("username"), + "password": self.getConfig("passkey")} + ) + + if response.startswith('ERROR'): + raise ImageTyperzException(response) + + try: + return float(response) + except: + raise ImageTyperzException("invalid response") + + def submit(self, captcha, captchaType="file", match=None): + req = getRequest() + #raise timeout threshold + req.c.setopt(LOW_SPEED_TIME, 80) + + try: + response = req.load(self.SUBMIT_URL, + post={ "action": "UPLOADCAPTCHA", + "username": self.getConfig("username"), + "password": self.getConfig("passkey"), + "file": (FORM_FILE, captcha)}, + multipart=True) + finally: + req.close() + + if response.startswith("ERROR"): + raise ImageTyperzException(response) + else: + data = response.split('|') + if len(data) == 2: + ticket, result = data + else: + raise ImageTyperzException("Unknown response %s" % response) + + return ticket, result + + def newCaptchaTask(self, task): + if "service" in task.data: + return False + + if not task.isTextual(): + return False + + if not self.getConfig("username") or not self.getConfig("passkey"): + return False + + if self.core.isClientConnected() and not self.getConfig("force"): + return False + + if self.getCredits() > 0: + task.handler.append(self) + task.data['service'] = self.__name__ + task.setWaiting(100) + start_new_thread(self.processCaptcha, (task,)) + + else: + self.logInfo("Your %s account has not enough credits" % self.__name__) + + def captchaInvalid(self, task): + if task.data['service'] == self.__name__ and "ticket" in task.data: + response = self.getURL(self.RESPOND_URL, + post={"action": "SETBADIMAGE", + "username": self.getConfig("username"), + "password": self.getConfig("passkey"), + "imageid": task.data["ticket"]} + ) + + if not response == "SUCCESS": + self.logError(("Refund request failed"), response) + + def processCaptcha(self, task): + c = task.captchaFile + try: + ticket, result = self.submit(c) + except ImageTyperzException, e: + task.error = e.getCode() + return + + task.data["ticket"] = ticket + task.setResult(result)
\ No newline at end of file |