diff options
Diffstat (limited to 'module')
| -rw-r--r-- | module/plugins/hooks/CaptchaBrotherhood.py | 161 | ||||
| -rw-r--r-- | module/plugins/hoster/CrockoCom.py | 4 | ||||
| -rw-r--r-- | module/plugins/hoster/UlozTo.py | 6 | 
3 files changed, 166 insertions, 5 deletions
| diff --git a/module/plugins/hooks/CaptchaBrotherhood.py b/module/plugins/hooks/CaptchaBrotherhood.py new file mode 100644 index 000000000..d03387527 --- /dev/null +++ b/module/plugins/hooks/CaptchaBrotherhood.py @@ -0,0 +1,161 @@ +# -*- 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 __future__ import with_statement + +from thread import start_new_thread + +import pycurl +import StringIO +from urllib import urlencode +from time import sleep +import Image + +from module.network.RequestFactory import getURL, getRequest +from module.network.HTTPRequest import BadHeader +from module.plugins.Hook import Hook + +class CaptchaBrotherhoodException(Exception): +    def __init__(self, err): +        self.err = err + +    def getCode(self): +        return self.err + +    def __str__(self): +        return "<CaptchaBrotherhoodException %s>" % self.err + +    def __repr__(self): +        return "<CaptchaBrotherhoodException %s>" % self.err + +class CaptchaBrotherhood(Hook): +    __name__ = "CaptchaBrotherhood" +    __version__ = "0.01" +    __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") +     +    API_URL = "http://ocrhood.gazcad.com/" + +    def setup(self): +        self.info = {} + +    def getCredits(self): +        response = getURL(self.API_URL + "askCredits.aspx", +                          get = {"username": self.getConfig("username"), +                                 "password": self.getConfig("passkey")}) +        if not response.startswith("OK"): +            raise CaptchaBrotherhoodException(response) +        else: +            credits = int(response[3:]) +            self.logInfo(_("%d credits left") % credits) +            self.info["credits"] = credits +            return credits + +    def submit(self, captcha, captchaType="file", match=None):                +        try: +            img = Image.open(captcha) +            self.logDebug("CAPTCHA IMAGE", img, img.format) +            output = StringIO.StringIO() +            img.save(output, "JPEG") +            data = output.getvalue() +            output.close() +        except Exception, e: +            raise CaptchaBrotherhoodException("Reading or converting captcha image failed: %s" % e) +         +        req = getRequest() + +        url = "%ssendNewCaptcha.aspx?%s" % (self.API_URL,  +                   urlencode({"username": self.getConfig("username"), +                              "password": self.getConfig("passkey"), +                              "captchaSource": "jdPlugin", +                              "timeout": "80"}) +                   ) + +        req.c.setopt(pycurl.URL, url) +        req.c.setopt(pycurl.POST, 1) +        req.c.setopt(pycurl.POSTFIELDS, data) +        req.c.setopt(pycurl.HTTPHEADER, [ "Content-Type: text/html" ])         + +        try: +            req.c.perform() +            response = req.getResponse() +        except Exception, e: +            raise CaptchaBrotherhoodException("Submit captcha image failed") +             +        req.close() + +        if not response.startswith("OK"): +            raise CaptchaBrotherhoodException(response[1]) +        +        ticket = response[3:] +         +        for i in range(15): +            sleep(5) +            response = self.get_api("askCaptchaResult", ticket) +            if response.startswith("OK-answered"): +                return ticket, response[12:]  + +        raise CaptchaBrotherhoodException("No solution received in time") + +    def get_api(self, api, ticket): +        response = getURL("%s%s.aspx" % (self.API_URL, api),  +                          get={"username": self.getConfig("username"), +                               "password": self.getConfig("passkey"), +                               "captchaID": ticket} +                          ) +        if not response.startswith("OK"): +            raise CaptchaBrotherhoodException("Unknown response: %s" % response) +         +        return response + +    def newCaptchaTask(self, task): +        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 + +        print self.getCredits() +        if self.getCredits() > 10: +            task.handler.append(self) +            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: +            response = self.get_api("complainCaptcha", ticket) + +    def processCaptcha(self, task): +        c = task.captchaFile +        try: +            ticket, result = self.submit(c) +        except CaptchaBrotherhoodException, e: +            task.error = e.getCode() +            return + +        task.data["ticket"] = ticket +        task.setResult(result)
\ No newline at end of file diff --git a/module/plugins/hoster/CrockoCom.py b/module/plugins/hoster/CrockoCom.py index bf058b613..27ab52436 100644 --- a/module/plugins/hoster/CrockoCom.py +++ b/module/plugins/hoster/CrockoCom.py @@ -9,13 +9,13 @@ class CrockoCom(SimpleHoster):      __name__ = "CrockoCom"      __type__ = "hoster"      __pattern__ = r"http://(www\.)?(crocko|easy-share).com/.*" -    __version__ = "0.12" +    __version__ = "0.13"      __description__ = """Crocko Download Hoster"""      __author_name__ = ("zoidberg")      __author_mail__ = ("zoidberg@mujmail.cz")      FILE_NAME_PATTERN = r'<span class="fz24">Download:\s*<strong>(?P<N>.*)' -    FILE_NAME_PATTERN = r'<span class="tip1"><span class="inner">(?P<S>[^<]+)</span></span>' +    FILE_SIZE_PATTERN = r'<span class="tip1"><span class="inner">(?P<S>[^<]+)</span></span>'      FILE_OFFLINE_PATTERN = r"<h1>Sorry,<br />the page you're looking for <br />isn't here.</h1>"      DOWNLOAD_URL_PATTERN = r"window.location ='([^']+)';"      CAPTCHA_URL_PATTERN = re.compile(r"u='(/file_contents/captcha/\w+)';\s*w='(\d+)';") diff --git a/module/plugins/hoster/UlozTo.py b/module/plugins/hoster/UlozTo.py index 5344ee09c..cf2f09311 100644 --- a/module/plugins/hoster/UlozTo.py +++ b/module/plugins/hoster/UlozTo.py @@ -132,7 +132,7 @@ class UlozTo(SimpleHoster):              "wrong_captcha": re.compile(r'<ul class="error">\s*<li>Error rewriting the text.</li>'),              "offline": re.compile(self.FILE_OFFLINE_PATTERN),              "passwd": self.PASSWD_PATTERN, -            "server_error": "<title>Ulo[zž].to - ([^<]+)</title>", #paralell dl, server overload etc. +            "server_error": 'src="http://img.ulozto.cz/error403/vykricnik.jpg"', #paralell dl, server overload etc.              "not_found": "<title>Ulož.to</title>"          }) @@ -146,9 +146,9 @@ class UlozTo(SimpleHoster):          elif check == "passwd":              self.fail("Wrong password")          elif check == "server_error": -            self.logError("Server error: %s" % self.lastCheck.group(1)) +            self.logError("Server error, try downloading later")              self.multiDL = False -            self.setWait(300, True) +            self.setWait(3600, True)              self.wait()              self.retry()          elif check == "not_found": | 
