diff options
Diffstat (limited to 'module')
-rw-r--r-- | module/plugins/internal/SimpleCrypter.py | 67 |
1 files changed, 29 insertions, 38 deletions
diff --git a/module/plugins/internal/SimpleCrypter.py b/module/plugins/internal/SimpleCrypter.py index 1690b50c2..9856ae2e5 100644 --- a/module/plugins/internal/SimpleCrypter.py +++ b/module/plugins/internal/SimpleCrypter.py @@ -6,14 +6,14 @@ from traceback import print_exc from module.plugins.Crypter import Crypter from module.plugins.Plugin import Fail -from module.plugins.internal.SimpleHoster import _error, _wait, replace_patterns, set_cookies +from module.plugins.internal.SimpleHoster import _error, _wait, parseFileInfo, replace_patterns, set_cookies from module.utils import fixup, html_unescape class SimpleCrypter(Crypter): __name__ = "SimpleCrypter" __type__ = "crypter" - __version__ = "0.24" + __version__ = "0.25" __pattern__ = None __config__ = [("use_subfolder", "bool", "Save package to subfolder", True), #: Overrides core.config['general']['folder_per_package'] @@ -32,8 +32,8 @@ class SimpleCrypter(Crypter): LINK_PATTERN: group(1) must be a download link or a regex to catch more links example: LINK_PATTERN = r'<div class="link"><a href="(.+?)"' - NAME_PATTERN: (optional) group(1) should be the folder name or the webpage title - example: NAME_PATTERN = r'<title>Files of: ([^<]+) folder</title>' + NAME_PATTERN: (optional) folder name or webpage title + example: NAME_PATTERN = r'<title>Files of: (?P<N>[^<]+) folder</title>' OFFLINE_PATTERN: (optional) Checks if the file is yet available online example: OFFLINE_PATTERN = r'File (deleted|not found)' @@ -84,10 +84,10 @@ class SimpleCrypter(Crypter): def prepare(self): if self.LOGIN_ACCOUNT and not self.account: - self.fail(_("Required account not found!")) + self.fail(_("Required account not found")) if self.LOGIN_PREMIUM and not self.premium: - self.fail(_("Required premium account not found!")) + self.fail(_("Required premium account not found")) if isinstance(self.COOKIES, list): set_cookies(self.req.cj, self.COOKIES) @@ -107,53 +107,44 @@ class SimpleCrypter(Crypter): if self.html is None: self.fail(_("No html retrieved")) - self.checkOnline() + info = self.getFileInfo() - package_name, folder_name = self.getPackageNameAndFolder() - - self.package_links = self.getLinks() + self.links = self.getLinks() if hasattr(self, 'PAGES_PATTERN') and hasattr(self, 'loadPage'): self.handleMultiPages() - self.logDebug("Package has %d links" % len(self.package_links)) + self.logDebug("Package has %d links" % len(self.links)) - if self.package_links: - self.packages = [(package_name, self.package_links, folder_name)] + if self.links: + self.packages = [(info['name'], self.links, info['folder'])] - def getLinks(self): - """ - Returns the links extracted from self.html - You should override this only if it's impossible to extract links using only the LINK_PATTERN. - """ - return re.findall(self.LINK_PATTERN, self.html) + def getFileInfo(self): + name, size, status, url = parseFileInfo(self) + if name and name != url: + self.pyfile.name = name + else: + self.pyfile.name = self.file_info['name'] = html_unescape(urlparse(url).path.split("/")[-1]) - def checkOnline(self): - if hasattr(self, "OFFLINE_PATTERN") and re.search(self.OFFLINE_PATTERN, self.html): + if status == 1: self.offline() - elif hasattr(self, "TEMP_OFFLINE_PATTERN") and re.search(self.TEMP_OFFLINE_PATTERN, self.html): + elif status == 6: self.tempOffline() + self.file_info['folder'] = self.pyfile.name - def getPackageNameAndFolder(self): - if hasattr(self, 'NAME_PATTERN'): - try: - m = re.search(self.NAME_PATTERN, self.html) - name = replace_patterns(m.group(1).strip(), self.NAME_REPLACEMENTS) - folder = html_unescape(name) - except: - pass - else: - self.logDebug("Found name [%s] and folder [%s] in package info" % (name, folder)) - return name, folder + self.logDebug("FILE NAME: %s" % self.pyfile.name) + return self.file_info - name = self.pyfile.package().name - folder = self.pyfile.package().folder - self.logDebug("Package info not found, defaulting to pyfile name [%s] and folder [%s]" % (name, folder)) - return name, folder + def getLinks(self): + """ + Returns the links extracted from self.html + You should override this only if it's impossible to extract links using only the LINK_PATTERN. + """ + return re.findall(self.LINK_PATTERN, self.html) def handleMultiPages(self): @@ -165,7 +156,7 @@ class SimpleCrypter(Crypter): for p in xrange(2, pages + 1): self.html = self.loadPage(p) - self.package_links += self.getLinks() + self.links += self.getLinks() #@TODO: Remove in 0.4.10 |