diff options
author | zoidberg10 <zoidberg@mujmail.cz> | 2012-01-16 20:44:19 +0100 |
---|---|---|
committer | zoidberg10 <zoidberg@mujmail.cz> | 2012-01-16 20:44:19 +0100 |
commit | a72688b208ed4ba3e98234e995f7bc1eb4afec42 (patch) | |
tree | d9b800af34a521db755f5303ca44662b1cbb544a /module/plugins/internal/SimpleHoster.py | |
parent | reverted sloccount (diff) | |
download | pyload-a72688b208ed4ba3e98234e995f7bc1eb4afec42.tar.xz |
merge in plugin updates
Diffstat (limited to 'module/plugins/internal/SimpleHoster.py')
-rw-r--r-- | module/plugins/internal/SimpleHoster.py | 43 |
1 files changed, 33 insertions, 10 deletions
diff --git a/module/plugins/internal/SimpleHoster.py b/module/plugins/internal/SimpleHoster.py index aae76e781..12b629a81 100644 --- a/module/plugins/internal/SimpleHoster.py +++ b/module/plugins/internal/SimpleHoster.py @@ -17,30 +17,35 @@ @author: zoidberg """ from urlparse import urlparse -from re import search, sub +import re from module.plugins.Hoster import Hoster -from module.utils import html_unescape, parseFileSize +from module.utils import html_unescape, fixup, parseFileSize from module.network.RequestFactory import getURL def reSub(string, ruleslist): for r in ruleslist: rf, rt = r - string = sub(rf, rt, string) + string = re.sub(rf, rt, string) + #self.logDebug(rf, rt, string) return string + +def parseHtmlTagAttrValue(attr_name, tag): + m = re.search(r"%s\s*=\s*([\"']?)((?<=\")[^\"]+|(?<=')[^']+|[^\s\"'][^>\s]+)\1" % attr_name, tag) + return m.group(2) if m else '' def parseFileInfo(self, url = '', html = '', infomode = False): if not html and hasattr(self, "html"): html = self.html info = {"name" : url, "size" : 0, "status" : 3} online = False - if hasattr(self, "FILE_OFFLINE_PATTERN") and search(self.FILE_OFFLINE_PATTERN, html): + if hasattr(self, "FILE_OFFLINE_PATTERN") and re.search(self.FILE_OFFLINE_PATTERN, html): # File offline info['status'] = 1 else: for pattern in ("FILE_INFO_PATTERN", "FILE_NAME_PATTERN", "FILE_SIZE_PATTERN"): try: - info = dict(info, **search(getattr(self, pattern), html).groupdict()) + info = dict(info, **re.search(getattr(self, pattern), html).groupdict()) online = True except AttributeError: continue @@ -77,7 +82,7 @@ class PluginParseError(Exception): class SimpleHoster(Hoster): __name__ = "SimpleHoster" - __version__ = "0.14" + __version__ = "0.16" __pattern__ = None __type__ = "hoster" __description__ = """Base hoster plugin""" @@ -93,7 +98,7 @@ class SimpleHoster(Hoster): """ FILE_SIZE_REPLACEMENTS = [] - FILE_NAME_REPLACEMENTS = [] + FILE_NAME_REPLACEMENTS = [("&#?\w+;", fixup)] FILE_URL_REPLACEMENTS = [] def setup(self): @@ -103,14 +108,14 @@ class SimpleHoster(Hoster): pyfile.url = reSub(pyfile.url, self.FILE_URL_REPLACEMENTS) self.html = self.load(pyfile.url, decode = True) self.file_info = self.getFileInfo() - if self.account: + if self.premium: self.handlePremium() else: self.handleFree() def getFileInfo(self): self.logDebug("URL: %s" % self.pyfile.url) - if hasattr(self, "TEMP_OFFLINE_PATTERN") and search(self.TEMP_OFFLINE_PATTERN, self.html): + if hasattr(self, "TEMP_OFFLINE_PATTERN") and re.search(self.TEMP_OFFLINE_PATTERN, self.html): self.tempOffline() file_info = parseFileInfo(self, infomode = True) @@ -140,4 +145,22 @@ class SimpleHoster(Hoster): self.fail("Premium download not implemented") def parseError(self, msg): - raise PluginParseError(msg)
\ No newline at end of file + raise PluginParseError(msg) + + def parseHtmlForm(self, attr_str): + inputs = {} + action = None + form = re.search(r"(?P<tag><form[^>]*%s[^>]*>)(?P<content>.*?)</form[^>]*>" % attr_str, self.html, re.S) + if form: + action = parseHtmlTagAttrValue("action", form.group('tag')) + for input in re.finditer(r'(<(?:input|textarea)[^>]*>)', form.group('content')): + name = parseHtmlTagAttrValue("name", input.group(1)) + if name: + inputs[name] = parseHtmlTagAttrValue("value", input.group(1)) + return action, inputs + + def checkTrafficLeft(self): + traffic = self.account.getAccountInfo(self.user, True)["trafficleft"] + size = self.pyfile.size / 1024 + self.logInfo("Filesize: %i KiB, Traffic left for user %s: %i KiB" % (size, self.user, traffic)) + return size <= traffic
\ No newline at end of file |