From 4ec11afb741149ea86e6ba647862b461d54c747c Mon Sep 17 00:00:00 2001 From: Walter Purcaro Date: Sun, 2 Nov 2014 22:37:19 +0100 Subject: Update internal Simple plugins --- module/plugins/internal/SimpleHoster.py | 67 +++++++++++++++++++-------------- 1 file changed, 39 insertions(+), 28 deletions(-) (limited to 'module/plugins/internal/SimpleHoster.py') diff --git a/module/plugins/internal/SimpleHoster.py b/module/plugins/internal/SimpleHoster.py index 1d85dc01b..749cdf557 100644 --- a/module/plugins/internal/SimpleHoster.py +++ b/module/plugins/internal/SimpleHoster.py @@ -90,19 +90,20 @@ def parseHtmlForm(attr_str, html, input_names=None): def parseFileInfo(self, url="", html=""): + info = {'name': url, 'size': 0, 'status': 3} + if not url and hasattr(self, "pyfile"): url = self.pyfile.url - info = {"name": url, "size": 0, "status": 3} - if not html: if url: - return tuple(create_getInfo(self)([url])) + return next(create_getInfo(self)([url])) + + elif hasattr(self, "req") and self.req.http.code == '404': + info['status'] = 1 + elif hasattr(self, "html"): - if hasattr(self, "req") and self.req.http.code == '404': - info['status'] = 1 - else: - html = self.html + html = self.html if html: if hasattr(self, "OFFLINE_PATTERN") and re.search(self.OFFLINE_PATTERN, html): @@ -121,7 +122,8 @@ def parseFileInfo(self, url="", html=""): except: pass - for pattern in ("FILE_INFO_PATTERN", "FILE_NAME_PATTERN", "FILE_SIZE_PATTERN"): + for pattern in ("INFO_PATTERN", "NAME_PATTERN", "SIZE_PATTERN", + "FILE_INFO_PATTERN", "FILE_NAME_PATTERN", "FILE_SIZE_PATTERN"): #@TODO: Remove in 0.4.10 try: info.update(re.search(getattr(self, pattern), html).groupdict()) online = True @@ -133,17 +135,21 @@ def parseFileInfo(self, url="", html=""): info['status'] = 2 if 'N' in info: - info['name'] = replace_patterns(info['N'].strip(), self.FILE_NAME_REPLACEMENTS) + info['name'] = replace_patterns(info['N'].strip(), + self.FILE_NAME_REPLACEMENTS if hasattr(self, "FILE_NAME_REPLACEMENTS") else self.NAME_REPLACEMENTS) #@TODO: Remove FILE_NAME_REPLACEMENTS check in 0.4.10 if 'S' in info: size = replace_patterns(info['S'] + info['U'] if 'U' in info else info['S'], - self.FILE_SIZE_REPLACEMENTS) + self.FILE_SIZE_REPLACEMENTS if hasattr(self, "FILE_SIZE_REPLACEMENTS") else self.SIZE_REPLACEMENTS) #@TODO: Remove FILE_SIZE_REPLACEMENTS check in 0.4.10 info['size'] = parseFileSize(size) elif isinstance(info['size'], basestring): unit = info['units'] if 'units' in info else None info['size'] = parseFileSize(info['size'], unit) + if not hasattr(self, "html") or self.html is None: + self.html = html + if not hasattr(self, "file_info"): self.file_info = {} @@ -162,7 +168,10 @@ def create_getInfo(plugin): else: cj = None - if hasattr(plugin, "FILE_URL_REPLACEMENTS"): + if hasattr(plugin, "URL_REPLACEMENTS"): + url = replace_patterns(url, plugin.URL_REPLACEMENTS) + + elif hasattr(plugin, "FILE_URL_REPLACEMENTS"): #@TODO: Remove in 0.4.10 url = replace_patterns(url, plugin.FILE_URL_REPLACEMENTS) if hasattr(plugin, "TEXT_ENCODING"): @@ -198,13 +207,13 @@ class SimpleHoster(Hoster): """ Following patterns should be defined by each hoster: - FILE_INFO_PATTERN: (optional) Name and Size of the file - example: FILE_INFO_PATTERN = r'(?Pfile_name) (?Pfile_size) (?Psize_unit)' + INFO_PATTERN: (optional) Name and Size of the file + example: INFO_PATTERN = r'(?Pfile_name) (?Pfile_size) (?Psize_unit)' or - FILE_NAME_PATTERN: (optional) Name that will be set for the file - example: FILE_NAME_PATTERN = r'(?Pfile_name)' - FILE_SIZE_PATTERN: (optional) Size that will be checked for the file - example: FILE_SIZE_PATTERN = r'(?Pfile_size) (?Psize_unit)' + NAME_PATTERN: (optional) Name that will be set for the file + example: NAME_PATTERN = r'(?Pfile_name)' + SIZE_PATTERN: (optional) Size that will be checked for the file + example: SIZE_PATTERN = r'(?Pfile_size) (?Psize_unit)' OFFLINE_PATTERN: (optional) Checks if the file is yet available online example: OFFLINE_PATTERN = r'File (deleted|not found)' @@ -225,9 +234,9 @@ class SimpleHoster(Hoster): example: LINK_PREMIUM_PATTERN = r'