summaryrefslogtreecommitdiffstats
path: root/module/plugins
diff options
context:
space:
mode:
authorGravatar RaNaN <Mast3rRaNaN@hotmail.de> 2011-11-04 20:40:09 +0100
committerGravatar RaNaN <Mast3rRaNaN@hotmail.de> 2011-11-04 20:40:09 +0100
commit138c28777f8a09fd88c4002a00c87e8bd0c7be74 (patch)
tree5d8aea3a8dbc65276dc04722e62375ce6dc61b6a /module/plugins
parentBasePlugin: attempt to fix #266 (diff)
downloadpyload-138c28777f8a09fd88c4002a00c87e8bd0c7be74.tar.xz
closed #418
Diffstat (limited to 'module/plugins')
-rw-r--r--module/plugins/hooks/ExtractArchive.py2
-rw-r--r--module/plugins/hoster/BasePlugin.py78
2 files changed, 49 insertions, 31 deletions
diff --git a/module/plugins/hooks/ExtractArchive.py b/module/plugins/hooks/ExtractArchive.py
index 54dd6ff2d..23ae6c543 100644
--- a/module/plugins/hooks/ExtractArchive.py
+++ b/module/plugins/hooks/ExtractArchive.py
@@ -151,7 +151,7 @@ class ExtractArchive(Hook):
#iterate packages -> plugins -> targets
for pid in ids:
p = self.core.files.getPackage(pid)
- self.logInfo(_("Extract package %s") % p.name)
+ self.logInfo(_("Check package %s") % p.name)
if not p: continue
# determine output folder
diff --git a/module/plugins/hoster/BasePlugin.py b/module/plugins/hoster/BasePlugin.py
index ed11c378b..15e35ce24 100644
--- a/module/plugins/hoster/BasePlugin.py
+++ b/module/plugins/hoster/BasePlugin.py
@@ -1,13 +1,13 @@
#!/usr/bin/env python
# -*- coding: utf-8 -*-
-
-from module.plugins.Hoster import Hoster
-from module.utils import html_unescape
-
from urlparse import urlparse
from re import search
from urllib import unquote
+from module.network.HTTPRequest import BadHeader
+from module.plugins.Hoster import Hoster
+from module.utils import html_unescape, removeChars
+
class BasePlugin(Hoster):
__name__ = "BasePlugin"
__type__ = "hoster"
@@ -41,31 +41,49 @@ class BasePlugin(Hoster):
#
# return
if pyfile.url.startswith("http"):
- header = self.load(pyfile.url, just_header = True)
- #self.logDebug(header)
-
- if 'location' in header:
- self.logDebug("Location: " + header['location'])
- url = unquote(header['location'])
- else:
- url = pyfile.url
-
- name = html_unescape(urlparse(url).path.split("/")[-1])
-
- if 'content-disposition' in header:
- self.logDebug("Content-Disposition: " + header['content-disposition'])
- m = 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 = disp['name'].replace('"', "").replace("'", "").replace(";", "").strip()
- name = unicode(unquote(name), disp['enc'])
-
- if not name: self.offline()
- pyfile.name = name
- self.logDebug("Filename: %s" % pyfile.name)
- self.download(url, disposition=True)
+
+ try:
+ self.downloadFile(pyfile)
+ except BadHeader, e:
+ if e.code in (401, 403):
+ self.logDebug("Auth required")
+
+ pwd = pyfile.package().password.strip()
+ if ":" not in pwd:
+ self.fail(_("Authorization required (username:password)"))
+
+ self.req.addAuth(pwd)
+ self.downloadFile(pyfile)
+ else:
+ raise
else:
- self.fail("No Plugin matched and not a downloadable url.") \ No newline at end of file
+ self.fail("No Plugin matched and not a downloadable url.")
+
+
+ def downloadFile(self, pyfile):
+ header = self.load(pyfile.url, just_header = True)
+ #self.logDebug(header)
+
+ if 'location' in header:
+ self.logDebug("Location: " + header['location'])
+ url = unquote(header['location'])
+ else:
+ url = pyfile.url
+
+ name = html_unescape(urlparse(url).path.split("/")[-1])
+
+ if 'content-disposition' in header:
+ self.logDebug("Content-Disposition: " + header['content-disposition'])
+ m = 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 = removeChars(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) \ No newline at end of file