Example #1
0
def parse_file_info(self, url='', html=''):
    info = {'name': url, 'size': 0, 'status': 3}

    if hasattr(self, "pyfile"):
        url = self.pyfile.url

    if hasattr(self, "req") and self.req.http.code == '404':
        info['status'] = 1
    else:
        if not html and hasattr(self, "html"):
            html = self.html
        if isinstance(self.SH_BROKEN_ENCODING, str):
            html = str(html, self.SH_BROKEN_ENCODING)
            if hasattr(self, "html"):
                self.html = html

        if hasattr(self, "FILE_OFFLINE_PATTERN") and re.search(
                self.FILE_OFFLINE_PATTERN, html):
            # File offline
            info['status'] = 1
        else:
            online = False
            try:
                info.update(re.match(self.__pattern__, url).groupdict())
            except Exception:
                pass

            for pattern in ("FILE_INFO_PATTERN", "FILE_NAME_PATTERN",
                            "FILE_SIZE_PATTERN"):
                try:
                    info.update(
                        re.search(getattr(self, pattern), html).groupdict())
                    online = True
                except AttributeError:
                    continue

            if online:
                # File online, return name and size
                info['status'] = 2
                if 'N' in info:
                    info['name'] = replace_patterns(
                        info['N'], self.FILE_NAME_REPLACEMENTS)
                if 'S' in info:
                    size = replace_patterns(
                        info['S'] + info['U'] if 'U' in info else info['S'],
                        self.FILE_SIZE_REPLACEMENTS)
                    info['size'] = parse.size(size)
                elif isinstance(info['size'], str):
                    if 'units' in info:
                        info['size'] += info['units']
                    info['size'] = parse.size(info['size'])

    if hasattr(self, "file_info"):
        self.file_info = info

    return info['name'], info['size'], info['status'], url
Example #2
0
def parse_file_info(self, url='', html=''):
    info = {'name': url, 'size': 0, 'status': 3}

    if hasattr(self, "pyfile"):
        url = self.pyfile.url

    if hasattr(self, "req") and self.req.http.code == '404':
        info['status'] = 1
    else:
        if not html and hasattr(self, "html"):
            html = self.html
        if isinstance(self.SH_BROKEN_ENCODING, str):
            html = str(html, self.SH_BROKEN_ENCODING)
            if hasattr(self, "html"):
                self.html = html

        if hasattr(self, "FILE_OFFLINE_PATTERN") and re.search(
                self.FILE_OFFLINE_PATTERN, html):
            # File offline
            info['status'] = 1
        else:
            online = False
            try:
                info.update(re.match(self.__pattern__, url).groupdict())
            except Exception:
                pass

            for pattern in ("FILE_INFO_PATTERN",
                            "FILE_NAME_PATTERN", "FILE_SIZE_PATTERN"):
                try:
                    info.update(
                        re.search(getattr(self, pattern), html).groupdict())
                    online = True
                except AttributeError:
                    continue

            if online:
                # File online, return name and size
                info['status'] = 2
                if 'N' in info:
                    info['name'] = replace_patterns(
                        info['N'], self.FILE_NAME_REPLACEMENTS)
                if 'S' in info:
                    size = replace_patterns(info['S'] + info['U'] if 'U' in info else info['S'],
                                            self.FILE_SIZE_REPLACEMENTS)
                    info['size'] = parse.size(size)
                elif isinstance(info['size'], str):
                    if 'units' in info:
                        info['size'] += info['units']
                    info['size'] = parse.size(info['size'])

    if hasattr(self, "file_info"):
        self.file_info = info

    return info['name'], info['size'], info['status'], url
Example #3
0
    def load_account_info(self, user, req):
        html = req.load(self.MAIN_PAGE + "?op=my_account", decode=True)

        validuntil = trafficleft = None
        premium = True if '>Renew premium<' in html else False

        found = re.search(self.VALID_UNTIL_PATTERN, html)
        if found:
            premium = True
            trafficleft = -1
            try:
                self.log_debug(found.group(1))
                validuntil = mktime(strptime(found.group(1), "%d %B %Y"))
            except Exception as e:
                self.log_error(str(e))
        else:
            found = re.search(self.TRAFFIC_LEFT_PATTERN, html)
            if found:
                trafficleft = found.group(1)
                if "Unlimited" in trafficleft:
                    premium = True
                else:
                    trafficleft = parse.size(trafficleft) >> 10

        return ({
            'validuntil': validuntil,
            'trafficleft': trafficleft,
            'premium': premium
        })
Example #4
0
    def load_account_info(self, user, req):
        html = req.load(self.MAIN_PAGE + "?op=my_account", decode=True)

        validuntil = trafficleft = None
        premium = True if '>Renew premium<' in html else False

        found = re.search(self.VALID_UNTIL_PATTERN, html)
        if found:
            premium = True
            trafficleft = -1
            try:
                self.log_debug(found.group(1))
                validuntil = mktime(strptime(found.group(1), "%d %B %Y"))
            except Exception as e:
                self.log_error(e.message)
        else:
            found = re.search(self.TRAFFIC_LEFT_PATTERN, html)
            if found:
                trafficleft = found.group(1)
                if "Unlimited" in trafficleft:
                    premium = True
                else:
                    trafficleft = parse.size(trafficleft) >> 10

        return ({'validuntil': validuntil,
                 'trafficleft': trafficleft,
                 'premium': premium})
Example #5
0
 def parse_traffic(self, string):  #: returns kbyte
     return parse.size(string) >> 10
Example #6
0
 def parse_traffic(self, string):  #: returns kbyte
     return parse.size(string) >> 10