diff options
Diffstat (limited to 'pyload/plugins/internal')
-rw-r--r-- | pyload/plugins/internal/BasePlugin.py | 108 | ||||
-rw-r--r-- | pyload/plugins/internal/Captcha.py | 2 | ||||
-rw-r--r-- | pyload/plugins/internal/DeadCrypter.py | 3 | ||||
-rw-r--r-- | pyload/plugins/internal/DeadHoster.py | 3 | ||||
-rw-r--r-- | pyload/plugins/internal/SimpleCrypter.py | 22 | ||||
-rw-r--r-- | pyload/plugins/internal/SimpleHoster.py | 46 | ||||
-rw-r--r-- | pyload/plugins/internal/UpdateManager.py | 8 | ||||
-rw-r--r-- | pyload/plugins/internal/XFSAccount.py | 5 | ||||
-rw-r--r-- | pyload/plugins/internal/XFSHoster.py | 4 |
9 files changed, 121 insertions, 80 deletions
diff --git a/pyload/plugins/internal/BasePlugin.py b/pyload/plugins/internal/BasePlugin.py new file mode 100644 index 000000000..dd8540578 --- /dev/null +++ b/pyload/plugins/internal/BasePlugin.py @@ -0,0 +1,108 @@ +# -*- coding: utf-8 -*- + +import re + +from urllib import unquote +from urlparse import urlparse + +from pyload.network.HTTPRequest import BadHeader +from pyload.plugins.internal.Hoster import Hoster +from pyload.utils import html_unescape, remove_chars + + +class BasePlugin(Hoster): + __name__ = "BasePlugin" + __type__ = "hoster" + __version__ = "0.20" + + __pattern__ = r'^unmatchable$' + + __description__ = """Base Plugin when any other didnt fit""" + __license__ = "GPLv3" + __authors__ = [("RaNaN", "RaNaN@pyload.org")] + + + def setup(self): + self.chunkLimit = -1 + self.resumeDownload = True + + + def process(self, pyfile): + """main function""" + + #: debug part, for api exerciser + if pyfile.url.startswith("DEBUG_API"): + self.multiDL = False + return + + if pyfile.url.startswith("http"): + + try: + self.downloadFile(pyfile) + except BadHeader, e: + if e.code in (401, 403): + self.logDebug("Auth required") + + account = self.core.accountManager.getAccountPlugin('Http') + servers = [x['login'] for x in account.getAllAccounts()] + server = urlparse(pyfile.url).netloc + + if server in servers: + self.logDebug("Logging on to %s" % server) + self.req.addAuth(account.accounts[server]['password']) + else: + for pwd in pyfile.package().password.splitlines(): + if ":" in pwd: + self.req.addAuth(pwd.strip()) + break + else: + self.fail(_("Authorization required (username:password)")) + + self.downloadFile(pyfile) + else: + raise + + else: + self.fail(_("No Plugin matched and not a downloadable url")) + + + def downloadFile(self, pyfile): + url = pyfile.url + + for _i in xrange(5): + header = self.load(url, just_header=True) + + # self.load does not raise a BadHeader on 404 responses, do it here + if 'code' in header and header['code'] == 404: + raise BadHeader(404) + + if 'location' in header: + self.logDebug("Location: " + header['location']) + base = re.match(r'https?://[^/]+', url).group(0) + if header['location'].startswith("http"): + url = header['location'] + elif header['location'].startswith("/"): + url = base + unquote(header['location']) + else: + url = '%s/%s' % (base, unquote(header['location'])) + else: + break + + name = html_unescape(unquote(urlparse(url).path.split("/")[-1])) + + if 'content-disposition' in header: + self.logDebug("Content-Disposition: " + header['content-disposition']) + m = re.search("filename(?P<type>=|\*=(?P<enc>.+)'')(?P<name>.*)", header['content-disposition']) + if m: + disp = m.groupdict() + self.logDebug(disp) + if not disp['enc']: + disp['enc'] = 'utf-8' + name = remove_chars(disp['name'], "\"';").strip() + name = unicode(unquote(name), disp['enc']) + + if not name: + name = url + pyfile.name = name + self.logDebug("Filename: %s" % pyfile.name) + self.download(url, disposition=True) diff --git a/pyload/plugins/internal/Captcha.py b/pyload/plugins/internal/Captcha.py index b2fd980e2..7197c390e 100644 --- a/pyload/plugins/internal/Captcha.py +++ b/pyload/plugins/internal/Captcha.py @@ -30,7 +30,7 @@ class Captcha(Plugin): html = self.plugin.html else: errmsg = _("%s html not found") % self.__name__ - self.plugin.fail(errmsg) #@TODO: replace all plugin.fail(errmsg) with plugin.error(errmsg) in 0.4.10 + self.plugin.error(errmsg) raise TypeError(errmsg) m = re.search(self.KEY_PATTERN, html) diff --git a/pyload/plugins/internal/DeadCrypter.py b/pyload/plugins/internal/DeadCrypter.py index ad99c6a13..bf150f3d5 100644 --- a/pyload/plugins/internal/DeadCrypter.py +++ b/pyload/plugins/internal/DeadCrypter.py @@ -16,5 +16,4 @@ class DeadCrypter(_Crypter): def setup(self): - self.pyfile.error = "Crypter is no longer available" - self.offline() #@TODO: self.offline("Crypter is no longer available") + self.offline("Crypter is no longer available") diff --git a/pyload/plugins/internal/DeadHoster.py b/pyload/plugins/internal/DeadHoster.py index 3c59f1489..036ed3cb6 100644 --- a/pyload/plugins/internal/DeadHoster.py +++ b/pyload/plugins/internal/DeadHoster.py @@ -24,5 +24,4 @@ class DeadHoster(_Hoster): def setup(self): - self.pyfile.error = "Hoster is no longer available" - self.offline() #@TODO: self.offline("Hoster is no longer available") + self.offline("Hoster is no longer available") diff --git a/pyload/plugins/internal/SimpleCrypter.py b/pyload/plugins/internal/SimpleCrypter.py index 251acd6b8..460084919 100644 --- a/pyload/plugins/internal/SimpleCrypter.py +++ b/pyload/plugins/internal/SimpleCrypter.py @@ -69,21 +69,6 @@ class SimpleCrypter(Crypter): LOGIN_PREMIUM = False - #@TODO: remove in 0.4.10 - def init(self): - self.info = {} - - account_name = (self.__name__ + ".py").replace("Folder.py", "").replace(".py", "") - account = self.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.account = account - - def prepare(self): if self.LOGIN_ACCOUNT and not self.account: self.fail(_("Required account not found")) @@ -162,10 +147,5 @@ class SimpleCrypter(Crypter): self.links += self.getLinks() - #@TODO: Remove in 0.4.10 - def wait(self, seconds=0, reconnect=None): - return _wait(self, seconds, reconnect) - - def error(self, reason="", type="parse"): - return _error(self, reason, type) + return super(SimpleCrypter, self).error(self, reason, type) diff --git a/pyload/plugins/internal/SimpleHoster.py b/pyload/plugins/internal/SimpleHoster.py index ee8ef712b..afd61d821 100644 --- a/pyload/plugins/internal/SimpleHoster.py +++ b/pyload/plugins/internal/SimpleHoster.py @@ -14,25 +14,6 @@ from pyload.plugins.Plugin import Fail from pyload.utils import fixup, html_unescape, parseFileSize -#@TODO: Remove in 0.4.10 and redirect to self.error instead -def _error(self, reason, type): - if not reason and not type: - type = "unknown" - - msg = _("%s error") % type.strip().capitalize() if type else _("Error") - msg += ": " + reason.strip() if reason else "" - msg += _(" | Plugin may be out of date") - - raise Fail(msg) - - -#@TODO: Remove in 0.4.10 -def _wait(self, seconds, reconnect): - if seconds: - self.setWait(seconds, reconnect) - super(SimpleHoster, self).wait() - - def replace_patterns(string, ruleslist): for r in ruleslist: rf, rt = r @@ -108,9 +89,6 @@ def parseFileInfo(self, url="", html=""): if hasattr(self, "OFFLINE_PATTERN") and re.search(self.OFFLINE_PATTERN, html): info['status'] = 1 - elif hasattr(self, "FILE_OFFLINE_PATTERN") and re.search(self.FILE_OFFLINE_PATTERN, html): #@TODO: Remove in 0.4.10 - info['status'] = 1 - elif hasattr(self, "TEMP_OFFLINE_PATTERN") and re.search(self.TEMP_OFFLINE_PATTERN, html): info['status'] = 6 @@ -121,8 +99,7 @@ def parseFileInfo(self, url="", html=""): except: pass - for pattern in ("INFO_PATTERN", "NAME_PATTERN", "SIZE_PATTERN", - "FILE_INFO_PATTERN", "FILE_NAME_PATTERN", "FILE_SIZE_PATTERN"): #@TODO: Remove in 0.4.10 + for pattern in ("INFO_PATTERN", "NAME_PATTERN", "SIZE_PATTERN"): try: info.update(re.search(getattr(self, pattern), html).groupdict()) online = True @@ -134,12 +111,10 @@ def parseFileInfo(self, url="", html=""): info['status'] = 2 if 'N' in info: - 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 + info['name'] = replace_patterns(info['N'].strip(), self.NAME_REPLACEMENTS) if 'S' in info: - size = replace_patterns(info['S'] + info['U'] if 'U' in info else info['S'], - self.FILE_SIZE_REPLACEMENTS if hasattr(self, "FILE_SIZE_REPLACEMENTS") else self.SIZE_REPLACEMENTS) #@TODO: Remove FILE_SIZE_REPLACEMENTS check in 0.4.10 + size = replace_patterns(info['S'] + info['U'] if 'U' in info else info['S'], self.SIZE_REPLACEMENTS) info['size'] = parseFileSize(size) elif isinstance(info['size'], basestring): @@ -178,9 +153,6 @@ def create_getInfo(plugin): 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"): html = getURL(url, cookies=bool(cj), decode=not plugin.TEXT_ENCODING) if isinstance(plugin.TEXT_ENCODING, basestring): @@ -264,8 +236,7 @@ class SimpleHoster(Hoster): self.req.setOption("timeout", 120) - self.pyfile.url = replace_patterns(self.pyfile.url, - self.FILE_URL_REPLACEMENTS if hasattr(self, "FILE_URL_REPLACEMENTS") else self.URL_REPLACEMENTS) #@TODO: Remove FILE_URL_REPLACEMENTS check in 0.4.10 + self.pyfile.url = replace_patterns(self.pyfile.url, self.URL_REPLACEMENTS) if self.premium: self.logDebug(_("Looking for direct download link...")) @@ -315,7 +286,7 @@ class SimpleHoster(Hoster): if parseFileInfo(self, url, html)[2] is not 2: try: - return re.search(r'Location\s*:\s*(.+)', self.req.http.header, re.I).group(1).rstrip() #@TODO: Remove .rstrip() in 0.4.10 + return re.search(r'Location\s*:\s*(.+)', self.req.http.header, re.I).group(1) except: pass @@ -410,10 +381,5 @@ class SimpleHoster(Hoster): return size <= traffic - #@TODO: Remove in 0.4.10 - def wait(self, seconds=0, reconnect=None): - return _wait(self, seconds, reconnect) - - def error(self, reason="", type="parse"): - return _error(self, reason, type) + return super(SimpleHoster, self).error(self, reason, type) diff --git a/pyload/plugins/internal/UpdateManager.py b/pyload/plugins/internal/UpdateManager.py index 651cdde80..4a7fa736a 100644 --- a/pyload/plugins/internal/UpdateManager.py +++ b/pyload/plugins/internal/UpdateManager.py @@ -187,7 +187,7 @@ class UpdateManager(Addon): for plugin in upgradable: filename = plugin['name'] - prefix = plugin['type'] + type = plugin['type'] version = plugin['version'] if filename.endswith(".pyc"): @@ -195,12 +195,6 @@ class UpdateManager(Addon): else: name = filename.replace(".py", "") - #@TODO: obsolete after 0.4.10 - if prefix.endswith("s"): - type = prefix[:-1] - else: - type = prefix - plugins = getattr(self.core.pluginManager, "%sPlugins" % type) oldver = float(plugins[name]['v']) if name in plugins else None diff --git a/pyload/plugins/internal/XFSAccount.py b/pyload/plugins/internal/XFSAccount.py index 0992a8c31..df28191f1 100644 --- a/pyload/plugins/internal/XFSAccount.py +++ b/pyload/plugins/internal/XFSAccount.py @@ -35,11 +35,6 @@ class XFSAccount(Account): LOGIN_FAIL_PATTERN = r'>(Incorrect Login or Password|Error<)' - def __init__(self, manager, accounts): #@TODO: remove in 0.4.10 - self.init() - return super(XFSAccount, self).__init__(manager, accounts) - - def init(self): # if not self.HOSTER_DOMAIN: # self.fail(_("Missing HOSTER_DOMAIN")) diff --git a/pyload/plugins/internal/XFSHoster.py b/pyload/plugins/internal/XFSHoster.py index 80ddda002..87ddfab3f 100644 --- a/pyload/plugins/internal/XFSHoster.py +++ b/pyload/plugins/internal/XFSHoster.py @@ -143,7 +143,7 @@ class XFSHoster(SimpleHoster): self.errmsg = None - return m.group(1).strip() #@TODO: Remove .strip() in 0.4.10 + return m.group(1) def handleOverriden(self): @@ -195,7 +195,7 @@ class XFSHoster(SimpleHoster): if m is None: self.error(_("OVR_LINK_PATTERN not found")) - header = self.load(m.group(1).strip(), just_header=True, decode=True) #@TODO: Remove .strip() in 0.4.10 + header = self.load(m.group(1), just_header=True, decode=True) if 'location' in header: #: Direct download link self.download(header['location'], ref=True, cookies=True, disposition=True) else: |