diff options
Diffstat (limited to 'module/plugins/internal/SimpleCrypter.py')
-rw-r--r-- | module/plugins/internal/SimpleCrypter.py | 88 |
1 files changed, 50 insertions, 38 deletions
diff --git a/module/plugins/internal/SimpleCrypter.py b/module/plugins/internal/SimpleCrypter.py index 43b1347fd..be0d5e9d5 100644 --- a/module/plugins/internal/SimpleCrypter.py +++ b/module/plugins/internal/SimpleCrypter.py @@ -1,29 +1,25 @@ # -*- coding: utf-8 -*- import re +import urlparse -from urlparse import urlparse - -from module.plugins.Crypter import Crypter +from module.plugins.internal.Crypter import Crypter from module.plugins.internal.SimpleHoster import SimpleHoster, create_getInfo, replace_patterns, set_cookies -from module.utils import fixup +from module.utils import fixup, html_unescape class SimpleCrypter(Crypter, SimpleHoster): __name__ = "SimpleCrypter" __type__ = "crypter" - __version__ = "0.38" + __version__ = "0.53" __pattern__ = r'^unmatchable$' - __config__ = [("use_subfolder", "bool", "Save package to subfolder", True), #: Overrides core.config['general']['folder_per_package'] - ("subfolder_per_package", "bool", "Create a subfolder for each package", True)] + __config__ = [("use_subfolder" , "bool", "Save package to subfolder" , True), #: Overrides core.config['general']['folder_per_package'] + ("subfolder_per_pack", "bool", "Create a subfolder for each package", True)] __description__ = """Simple decrypter plugin""" __license__ = "GPLv3" - __authors__ = [("stickell", "l.stickell@yahoo.it"), - ("zoidberg", "zoidberg@mujmail.cz"), - ("Walter Purcaro", "vuolter@gmail.com")] - + __authors__ = [("Walter Purcaro", "vuolter@gmail.com")] """ Following patterns should be defined by each crypter: @@ -56,27 +52,15 @@ class SimpleCrypter(Crypter, SimpleHoster): return the html of the page number page_n """ - LINK_PATTERN = None - - NAME_REPLACEMENTS = [("&#?\w+;", fixup)] - URL_REPLACEMENTS = [] - - TEXT_ENCODING = False #: Set to True or encoding name if encoding in http header is not correct - COOKIES = True #: or False or list of tuples [(domain, name, value)] - - LOGIN_ACCOUNT = False - LOGIN_PREMIUM = False - - #@TODO: Remove in 0.4.10 def init(self): account_name = (self.__name__ + ".py").replace("Folder.py", "").replace(".py", "") - account = self.core.accountManager.getAccountPlugin(account_name) + account = self.pyfile.m.core.accountManager.getAccountPlugin(account_name) if account and account.canUse(): self.user, data = account.selectAccount() - self.req = account.getAccountRequest(self.user) - self.premium = account.isPremium(self.user) + self.req = account.getAccountRequest(self.user) + self.premium = account.isPremium(self.user) self.account = account @@ -85,7 +69,9 @@ class SimpleCrypter(Crypter, SimpleHoster): self.pyfile.error = "" #@TODO: Remove in 0.4.10 self.info = {} - self.links = [] #@TODO: Move to hoster class in 0.4.10 + self.html = "" + self.link = "" #@TODO: Move to Hoster in 0.4.10 + self.links = [] #@TODO: Move to Hoster in 0.4.10 if self.LOGIN_PREMIUM and not self.premium: self.fail(_("Required premium account not found")) @@ -101,24 +87,46 @@ class SimpleCrypter(Crypter, SimpleHoster): self.pyfile.url = replace_patterns(self.pyfile.url, self.URL_REPLACEMENTS) + def handleDirect(self, pyfile): + for i in xrange(10): #@TODO: Use `pycurl.MAXREDIRS` value in 0.4.10 + redirect = self.link or pyfile.url + self.logDebug("Redirect #%d to: %s" % (i, redirect)) + + header = self.load(redirect, just_header=True, decode=True) + if 'location' in header and header['location']: + self.link = header['location'] + else: + break + else: + self.logError(_("Too many redirects")) + + def decrypt(self, pyfile): self.prepare() - self.preload() - self.checkInfo() + self.logDebug("Looking for link redirect...") + self.handleDirect(pyfile) + + if self.link: + self.urls = [self.link] - self.links = self.getLinks() + else: + self.preload() + self.checkInfo() - if hasattr(self, 'PAGES_PATTERN') and hasattr(self, 'loadPage'): - self.handlePages(pyfile) + self.links = self.getLinks() - self.logDebug("Package has %d links" % len(self.links)) + if hasattr(self, 'PAGES_PATTERN') and hasattr(self, 'loadPage'): + self.handlePages(pyfile) + + self.logDebug("Package has %d links" % len(self.links)) if self.links: + self.links = [html_unescape(l.decode('unicode-escape').strip()) for l in self.links] #@TODO: Move to Crypter in 0.4.10 self.packages = [(self.info['name'], self.links, self.info['folder'])] elif not self.urls and not self.packages: #@TODO: Remove in 0.4.10 - self.fail("No link grabbed") + self.fail(_("No link grabbed")) def checkNameSize(self, getinfo=True): @@ -128,8 +136,8 @@ class SimpleCrypter(Crypter, SimpleHoster): self.logDebug("File info (AFTER): %s" % self.info) try: - url = self.info['url'] - name = self.info['name'] + url = self.info['url'].strip() + name = self.info['name'].strip() if name and name != url: self.pyfile.name = name @@ -151,13 +159,17 @@ class SimpleCrypter(Crypter, SimpleHoster): 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) + url_p = urlparse.urlparse(self.pyfile.url) + baseurl = "%s://%s" % (url_p.scheme, url_p.netloc) + + return [urlparse.urljoin(baseurl, link) if not urlparse.urlparse(link).scheme else link \ + for link in re.findall(self.LINK_PATTERN, self.html)] def handlePages(self, pyfile): try: pages = int(re.search(self.PAGES_PATTERN, self.html).group(1)) - except: + except Exception: pages = 1 for p in xrange(2, pages + 1): |