Example #1
0
def getInfo(urls):
    result = []
    
    for url in urls:
        
        # Get file info html
        req = getRequest()
        req.cj.setCookie(BitshareCom.HOSTER_DOMAIN, "language_selection", "EN")
        html = req.load(url)
        req.close()
        
        # Check online        
        if re.search(BitshareCom.FILE_OFFLINE_PATTERN, html):
            result.append((url, 0, 1, url))
            continue

        # Name
        name1 = re.search(BitshareCom.__pattern__, url).group('name')
        m = re.search(BitshareCom.FILE_INFO_PATTERN, html)
        name2 = m.group('name')
        name = max(name1, name2)
        
        # Size
        value = float(m.group('size'))
        units = m.group('units')
        pow = {'KB' : 1, 'MB' : 2, 'GB' : 3}[units] 
        size = int(value*1024**pow)
    
        # Return info
        result.append((name, size, 2, url))
        
    yield result
Example #2
0
    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={"vendor_key": PYLOAD_KEY,
                                      "key": self.getConfig("passkey"),
                                      "gen_task_id": "1",
                                      "file": (FORM_FILE, captcha)},
                                multipart=True)
        finally:
            req.close()

        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
Example #3
0
    def api_response(self, api="captcha", post=False, multipart=False):
        req = getRequest()
        req.c.setopt(HTTPHEADER, ["Accept: application/json", "User-Agent: pyLoad %s" % self.core.version])

        if post:
            if not isinstance(post, dict):
                post = {}
            post.update({"username": self.getConfig("username"),
                         "password": self.getConfig("passkey")})

        res = None
        try:
            json = req.load("%s%s" % (self.API_URL, api),
                            post=post,
                            multipart=multipart)
            self.logDebug(json)
            res = json_loads(json)

            if "error" in res:
                raise DeathByCaptchaException(res['error'])
            elif "status" not in res:
                raise DeathByCaptchaException(str(res))

        except BadHeader, e:
            if 403 == e.code:
                raise DeathByCaptchaException('not-logged-in')
            elif 413 == e.code:
                raise DeathByCaptchaException('invalid-captcha')
            elif 503 == e.code:
                raise DeathByCaptchaException('service-overload')
            elif e.code in (400, 405):
                raise DeathByCaptchaException('invalid-request')
            else:
                raise
Example #4
0
    def processCaptcha(self, task):        
        task.data["ticket"] = ticket = uuid4()
        result = None
        
        with open(task.captchaFile, 'rb') as f:
            data = f.read()        
        data = b64encode(data)         
        #self.logDebug("%s: %s : %s" % (ticket, task.captchaFile, data))

        req = getRequest()
        #raise timeout threshold
        req.c.setopt(LOW_SPEED_TIME, 80)
        
        try:
            result = req.load(self.API_URL, 
                              post={ "action": "upload",
                                     "key": self.getConfig("passkey"),
                                     "file": data, 
                            		   	 "gen_task_id": ticket }
                              )
        finally:
            req.close()

        self.logDebug("result %s : %s" % (ticket, result))
        task.setResult(result)
Example #5
0
    def submit(self, captcha, captchaType="file", match=None):
        req = getRequest()
        #raise timeout threshold
        req.c.setopt(LOW_SPEED_TIME, 80)
        
        try:
            #workaround multipart-post bug in HTTPRequest.py 
            if re.match("^[A-Za-z0-9]*$", self.getConfig("passkey")):
                multipart = True
                data = (FORM_FILE, captcha)
            else:
                multipart = False
                with open(captcha, 'rb') as f:
                    data = f.read()
                data = b64encode(data)
                
            response = req.load(self.SUBMIT_URL,
                                post={ "action": "UPLOADCAPTCHA",
                                       "username": self.getConfig("username"),
                                       "password": self.getConfig("passkey"),
                                       "file": data},
                                multipart = multipart)
        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
Example #6
0
    def submit(self, captcha, captchaType="file", match=None):
        if not PYLOAD_KEY:
            raise CaptchaTraderException("No API Key Specified!")

        #if type(captcha) == str and captchaType == "file":
        #    raise CaptchaTraderException("Invalid Type")
        assert captchaType in ("file", "url-jpg", "url-jpeg", "url-png", "url-bmp")

        req = getRequest()

        #raise timeout threshold
        req.c.setopt(LOW_SPEED_TIME, 80)

        try:
            json = req.load(CaptchaTrader.SUBMIT_URL, post={"api_key": PYLOAD_KEY,
                                                            "username": self.getConfig("username"),
                                                            "password": self.getConfig("passkey"),
                                                            "value": (FORM_FILE, captcha),
                                                            "type": captchaType}, multipart=True)
        finally:
            req.close()

        response = json_loads(json)
        if response[0] < 0:
            raise CaptchaTraderException(response[1])

        ticket = response[0]
        result = response[1]
        self.logDebug("result %s : %s" % (ticket, result))

        return ticket, result
Example #7
0
def getInfo(urls):
    h = getRequest()
    h.c.setopt(HTTPHEADER,
               ["Accept: text/html",
                "User-Agent: Mozilla/5.0 (Windows NT 6.1; Win64; x64; rv:25.0) Gecko/20100101 Firefox/25.0"])
    for url in urls:
        html = h.load(url, decode=True)
        file_info = parseFileInfo(ShareRapidCom, replace_patterns(url, ShareRapidCom.FILE_URL_REPLACEMENTS), html)
        yield file_info
Example #8
0
def getInfo(urls):
    h = getRequest()
    h.c.setopt(HTTPHEADER,
               ["Accept: text/html",
                "User-Agent: Mozilla/5.0 (Windows NT 6.1; Win64; x64; rv:25.0) Gecko/20100101 Firefox/25.0"])

    for url in urls:
        html = h.load(url, decode=True)
        yield parseFileInfo(MegaRapidCz, url, html)
Example #9
0
def getInfo(urls):
    h = getRequest()
    for url in urls:
        h.load(url)
        fid = re.search(WebshareCz.__pattern__, url).group("ID")
        api_data = h.load("https://webshare.cz/api/file_info/", post={"ident": fid})
        if "File not found" in api_data:
            file_info = (url, 0, 1, url)
        else:
            name = re.search("<name>(.+)</name>", api_data).group(1)
            size = re.search("<size>(.+)</size>", api_data).group(1)
            file_info = (name, size, 2, url)
        yield file_info
Example #10
0
def getInfo(urls):
    for url in urls:
        info = checkFile(url)
        if "filename" in info:
            yield info['name'], info['size'], info['status'], url
        else:        
            file_info = (url, 0, 3, url)
            h = getRequest()
            try:
                h.c.setopt(HTTPHEADER, ["Accept: text/html"])
                html = h.load(url, cookies = True, decode = True)
                file_info = parseFileInfo(ShareRapidCom, url, html) 
            finally:
                h.close()
                yield file_info
Example #11
0
def decryptCaptcha(self, url, get={}, post={}, cookies=False, forceUser=False, imgtype='jpg',
                   result_type='textual'):
    img = self.load(url, get=get, post=post, cookies=cookies)

    id = ("%.2f" % time())[-6:].replace(".", "")
    temp_file = open(join("tmp", "tmpCaptcha_%s_%s.%s" % (self.__name__, id, imgtype)), "wb")
    temp_file.write(img)
    temp_file.close()

    Ocr = self.core.pluginManager.loadClass("captcha", self.__name__)

    if Ocr:
        log(DEBUG, "Using tesseract for captcha")
        sleep(randint(3000, 5000) / 1000.0)
        if self.pyfile.abort: raise Abort

        ocr = Ocr()
        result = ocr.get_captcha(temp_file.name)
    else:
        log(DEBUG, "Using ct for captcha")
        # put username and passkey into two lines in ct.conf
        conf = join(expanduser("~"), "ct.conf")
        if not exists(conf): raise Exception("CaptchaTrader config %s not found." % conf)
        f = open(conf, "rb")
        req = getRequest()

        #raise timeout threshold
        req.c.setopt(LOW_SPEED_TIME, 80)

        try:
            json = req.load("http://captchatrader.com/api/submit",
                post={"api_key": "9f65e7f381c3af2b076ea680ae96b0b7",
                      "username": f.readline().strip(),
                      "password": f.readline().strip(),
                      "value": (FORM_FILE, temp_file.name),
                      "type": "file"}, multipart=True)
        finally:
            f.close()
            req.close()

        response = loads(json)
        log(DEBUG, str(response))
        result = response[1]

        self.cTask = response[0]

    return result
Example #12
0
    def call_api(self, api="captcha", post=False, multipart=False):
        req = getRequest()
        req.c.setopt(HTTPHEADER, [
            "Accept: application/json",
            "User-Agent: pyLoad %s" % self.core.version
        ])

        if post:
            if not isinstance(post, dict):
                post = {}
            post.update({
                "username": self.getConfig("username"),
                "password": self.getConfig("passkey")
            })

        response = None
        try:
            json = req.load("%s%s" % (self.API_URL, api),
                            post=post,
                            multipart=multipart)
            self.logDebug(json)
            response = json_loads(json)

            if "error" in response:
                raise DeathByCaptchaException(response['error'])
            elif "status" not in response:
                raise DeathByCaptchaException(str(response))

        except BadHeader, e:
            if 403 == e.code:
                raise DeathByCaptchaException('not-logged-in')
            elif 413 == e.code:
                raise DeathByCaptchaException('invalid-captcha')
            elif 503 == e.code:
                raise DeathByCaptchaException('service-overload')
            elif e.code in (400, 405):
                raise DeathByCaptchaException('invalid-request')
            else:
                raise
Example #13
0
    def submit(self, captcha, captchaType="file", match=None):
        req = getRequest()
        #raise timeout threshold
        req.c.setopt(LOW_SPEED_TIME, 80)

        try:
            #workaround multipart-post bug in HTTPRequest.py
            if re.match("^[A-Za-z0-9]*$", self.getConfig("passkey")):
                multipart = True
                data = (FORM_FILE, captcha)
            else:
                multipart = False
                with open(captcha, 'rb') as f:
                    data = f.read()
                data = b64encode(data)

            response = req.load(self.SUBMIT_URL,
                                post={
                                    "action": "UPLOADCAPTCHA",
                                    "username": self.getConfig("username"),
                                    "password": self.getConfig("passkey"),
                                    "file": data
                                },
                                multipart=multipart)
        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
Example #14
0
    def submit(self, captcha, captchaType="file", match=None):
        req = getRequest()
        #raise timeout threshold
        req.c.setopt(pycurl.LOW_SPEED_TIME, 80)

        try:
            #@NOTE: Workaround multipart-post bug in HTTPRequest.py
            if re.match("^\w*$", self.getConfig('passkey')):
                multipart = True
                data = (pycurl.FORM_FILE, captcha)
            else:
                multipart = False
                with open(captcha, 'rb') as f:
                    data = f.read()
                data = b64encode(data)

            res = req.load(self.SUBMIT_URL,
                           post={
                               'action': "UPLOADCAPTCHA",
                               'username': self.getConfig('username'),
                               'password': self.getConfig('passkey'),
                               "file": data
                           },
                           multipart=multipart)
        finally:
            req.close()

        if res.startswith("ERROR"):
            raise ImageTyperzException(res)
        else:
            data = res.split('|')
            if len(data) == 2:
                ticket, result = data
            else:
                raise ImageTyperzException("Unknown response: %s" % res)

        return ticket, result
Example #15
0
    def _processCaptcha(self, task):
        task.data['ticket'] = ticket = uuid.uuid4()
        result = None

        with open(task.captchaFile, 'rb') as f:
            data = f.read()

        req = getRequest()
        #raise timeout threshold
        req.c.setopt(pycurl.LOW_SPEED_TIME, 80)

        try:
            result = req.load(self.API_URL,
                              post={
                                  'action': "upload",
                                  'key': self.getConfig('passkey'),
                                  'file': b64encode(data),
                                  'gen_task_id': ticket
                              })
        finally:
            req.close()

        self.logDebug("Result %s : %s" % (ticket, result))
        task.setResult(result)
Example #16
0
    def submit(self, captcha, captchaType="file", match=None):
        if not PYLOAD_KEY:
            raise CaptchaTraderException("No API Key Specified!")

        #if type(captcha) == str and captchaType == "file":
        #    raise CaptchaTraderException("Invalid Type")
        assert captchaType in ("file", "url-jpg", "url-jpeg", "url-png",
                               "url-bmp")

        req = getRequest()

        #raise timeout threshold
        req.c.setopt(LOW_SPEED_TIME, 80)

        try:
            json = req.load(CaptchaTrader.SUBMIT_URL,
                            post={
                                "api_key": PYLOAD_KEY,
                                "username": self.getConfig("username"),
                                "password": self.getConfig("passkey"),
                                "value": (FORM_FILE, captcha),
                                "type": captchaType
                            },
                            multipart=True)
        finally:
            req.close()

        response = json_loads(json)
        if response[0] < 0:
            raise CaptchaTraderException(response[1])

        ticket = response[0]
        result = response[1]
        self.logDebug("result %s : %s" % (ticket, result))

        return ticket, result
class CaptchaBrotherhood(Hook):
    __name__ = "CaptchaBrotherhood"
    __type__ = "hook"
    __version__ = "0.09"

    __config__ = [("username", "str", "Username", ""),
                  ("force", "bool", "Force CT even if client is connected",
                   False), ("passkey", "password", "Password", "")]

    __description__ = """Send captchas to CaptchaBrotherhood.com"""
    __license__ = "GPLv3"
    __authors__ = [("RaNaN", "*****@*****.**"),
                   ("zoidberg", "*****@*****.**")]

    interval = 0  #@TODO: Remove in 0.4.10

    API_URL = "http://www.captchabrotherhood.com/"

    def setup(self):
        self.info = {}  #@TODO: Remove in 0.4.10

    def getCredits(self):
        res = getURL(self.API_URL + "askCredits.aspx",
                     get={
                         "username": self.getConfig('username'),
                         "password": self.getConfig('passkey')
                     })
        if not res.startswith("OK"):
            raise CaptchaBrotherhoodException(res)
        else:
            credits = int(res[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)
            output = StringIO.StringIO()
            self.logDebug("CAPTCHA IMAGE", img, img.format, img.mode)
            if img.format in ("GIF", "JPEG"):
                img.save(output, img.format)
            else:
                if img.mode != "RGB":
                    img = img.convert("RGB")
                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,
            urllib.urlencode({
                'username': self.getConfig('username'),
                'password': self.getConfig('passkey'),
                'captchaSource': "pyLoad",
                '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()
            res = req.getResponse()
        except Exception, e:
            raise CaptchaBrotherhoodException("Submit captcha image failed")