diff options
Diffstat (limited to 'module/plugins/internal')
-rw-r--r-- | module/plugins/internal/SimpleHoster.py | 35 |
1 files changed, 22 insertions, 13 deletions
diff --git a/module/plugins/internal/SimpleHoster.py b/module/plugins/internal/SimpleHoster.py index e0963fd91..05ef03d58 100644 --- a/module/plugins/internal/SimpleHoster.py +++ b/module/plugins/internal/SimpleHoster.py @@ -16,12 +16,12 @@ @author: zoidberg """ +from urlparse import urlparse +from re import search, sub from module.plugins.Hoster import Hoster from module.utils import html_unescape from module.network.RequestFactory import getURL -from re import search - def parseFileInfo(self, url = '', html = ''): if not html and hasattr(self, "html"): html = self.html @@ -33,17 +33,17 @@ def parseFileInfo(self, url = '', html = ''): elif hasattr(self, "FILE_INFO_PATTERN"): found = search(self.FILE_INFO_PATTERN, html) if found: - name, size, units = found.groups() + name, size, units = found.group('N'), found.group('S'), found.group('U') else: if hasattr(self, "FILE_NAME_PATTERN"): found = search(self.FILE_NAME_PATTERN, html) if found: - name = found.group(1) + name = found.group('N') if hasattr(self, "FILE_SIZE_PATTERN"): found = search(self.FILE_SIZE_PATTERN, html) if found: - size, units = found.groups() + size, units = found.group('S'), found.group('U') if size: # File online, return name and size @@ -52,7 +52,12 @@ def parseFileInfo(self, url = '', html = ''): size = float(size) * 1024 ** self.SIZE_UNITS[units] status = 2 - if not name: name = url + if name: + for r in self.NAME_REPLACEMENTS: + rf, rt = r + name = sub(rf, rt, name) + else: + name = url return name, size, status, url @@ -66,33 +71,37 @@ def create_getInfo(plugin): class PluginParseError(Exception): def __init__(self, msg): + Exception.__init__ self.value = 'Parse error (%s) - plugin may be out of date' % msg def __str__(self): return repr(self.value) class SimpleHoster(Hoster): __name__ = "SimpleHoster" - __version__ = "0.1" + __version__ = "0.12" __pattern__ = None __type__ = "hoster" __description__ = """Base hoster plugin""" __author_name__ = ("zoidberg") __author_mail__ = ("zoidberg@mujmail.cz") - - SIZE_UNITS = {'kB': 1, 'KB': 1, 'KiB': 1, 'MB': 2, 'MiB': 2, 'GB': 3, 'GiB': 3} + + #TODO: could be replaced when using utils.parseFileSize ? + #some plugins need to override these + SIZE_UNITS = {'k': 1, 'K': 1, 'M': 2, 'G': 3} SIZE_REPLACEMENTS = {',': '', ' ': ''} - + NAME_REPLACEMENTS = [] + def setup(self): self.resumeDownload = self.multiDL = True if self.account else False def process(self, pyfile): - self.html = self.load(pyfile.url, decode = True) + self.html = self.load(pyfile.url, decode = True, cookies = True) self.getFileInfo() if self.account: self.handlePremium() else: self.handleFree() - + def getFileInfo(self): self.logDebug("URL: %s" % self.pyfile.url) name, size, status, url = parseFileInfo(self) @@ -102,7 +111,7 @@ class SimpleHoster(Hoster): self.parseError('File info') if not name: - name = html_unescape(urlparse(pyfile.url).path.split("/")[-1]) + name = html_unescape(urlparse(self.pyfile.url).path.split("/")[-1]) self.logDebug("FILE NAME: %s FILE SIZE: %s" % (name, size)) self.pyfile.name, self.pyfile.size = name, size |