summaryrefslogtreecommitdiffstats
path: root/module
diff options
context:
space:
mode:
authorGravatar RaNaN <Mast3rRaNaN@hotmail.de> 2012-01-15 19:28:12 +0100
committerGravatar RaNaN <Mast3rRaNaN@hotmail.de> 2012-01-15 19:28:12 +0100
commit17b3595dc5db8b3270e6bcd07176ed4b7b47930a (patch)
tree22585271445d40866e8a311db3372a93c39b4b82 /module
parentbackend + api test case, nicer format for plugin tester (diff)
downloadpyload-17b3595dc5db8b3270e6bcd07176ed4b7b47930a.tar.xz
improved handling of content-disposition
Diffstat (limited to 'module')
-rw-r--r--module/PyFile.py20
-rw-r--r--module/network/Browser.py7
-rw-r--r--module/network/HTTPChunk.py17
-rw-r--r--module/network/HTTPDownload.py13
-rw-r--r--module/network/HTTPRequest.py2
-rw-r--r--module/plugins/hoster/BasePlugin.py27
6 files changed, 46 insertions, 40 deletions
diff --git a/module/PyFile.py b/module/PyFile.py
index 0c4c20705..d70f852d1 100644
--- a/module/PyFile.py
+++ b/module/PyFile.py
@@ -49,7 +49,7 @@ class PyFile(object):
"""
Represents a file object at runtime
"""
- __slots__ = ("m", "id", "url", "name", "size", "_size", "status", "pluginname", "packageid",
+ __slots__ = ("m", "id", "url", "_name", "name", "size", "_size", "status", "pluginname", "packageid",
"error", "order", "lock", "plugin", "waitUntil", "active", "abort", "statusname",
"reconnected", "progress", "maxprogress", "pluginclass")
@@ -58,7 +58,7 @@ class PyFile(object):
self.id = int(id)
self.url = url
- self.name = name
+ self._name = name
self.size = size
self.status = status
self.pluginname = pluginname
@@ -89,7 +89,21 @@ class PyFile(object):
# will convert all sizes to ints
size = property(lambda self: self._size, setSize)
-
+
+ def getName(self):
+ try:
+ if self.plugin.req.name:
+ return self.plugin.req.name
+ else:
+ return self._name
+ except:
+ return self._name
+
+ def setName(self, name):
+ self._name = name
+
+ name = property(getName, setName)
+
def __repr__(self):
return "<PyFile %s: %s@%s>" % (self.id, self.name, self.pluginname)
diff --git a/module/network/Browser.py b/module/network/Browser.py
index d68a23687..3452184d8 100644
--- a/module/network/Browser.py
+++ b/module/network/Browser.py
@@ -55,6 +55,13 @@ class Browser(object):
return 0
@property
+ def name(self):
+ if self.dl:
+ return self.dl.name
+ else:
+ return ""
+
+ @property
def arrived(self):
if self.dl:
return self.dl.arrived
diff --git a/module/network/HTTPChunk.py b/module/network/HTTPChunk.py
index add2cc094..3380fb733 100644
--- a/module/network/HTTPChunk.py
+++ b/module/network/HTTPChunk.py
@@ -20,10 +20,13 @@ from os import remove, stat, fsync
from os.path import exists
from time import sleep
from re import search
-from module.utils.fs import fs_encode
+
import codecs
import pycurl
+from module.utils import remove_chars
+from module.utils.fs import fs_encode
+
from HTTPRequest import HTTPRequest
class WrongFormat(Exception):
@@ -256,11 +259,13 @@ class HTTPChunk(HTTPRequest):
if line.startswith("accept-ranges") and "bytes" in line:
self.p.chunkSupport = True
- if line.startswith("content-disposition") and "filename=" in line:
- name = orgline.partition("filename=")[2]
- name = name.replace('"', "").replace("'", "").replace(";", "").strip()
- self.p.nameDisposition = name
- self.log.debug("Content-Disposition: %s" % name)
+ if "content-disposition" in line:
+
+ m = search("filename(?P<type>=|\*=(?P<enc>.+)'')(?P<name>.*)", line)
+ if m:
+ name = remove_chars(m.groupdict()['name'], "\"';").strip()
+ self.p._name = name
+ self.log.debug("Content-Disposition: %s" % name)
if not self.resume and line.startswith("content-length"):
self.p.size = int(line.split(":")[1])
diff --git a/module/network/HTTPDownload.py b/module/network/HTTPDownload.py
index 6ac39a051..59d38beee 100644
--- a/module/network/HTTPDownload.py
+++ b/module/network/HTTPDownload.py
@@ -49,7 +49,7 @@ class HTTPDownload():
self.abort = False
self.size = 0
- self.nameDisposition = None #will be parsed from content disposition
+ self._name = ""# will be parsed from content disposition
self.chunks = []
@@ -87,6 +87,10 @@ class HTTPDownload():
if not self.size: return 0
return (self.arrived * 100) / self.size
+ @property
+ def name(self):
+ return self._name if self.disposition else ""
+
def _copyChunks(self):
init = fs_encode(self.info.getChunkName(0)) #initial chunk name
@@ -113,8 +117,8 @@ class HTTPDownload():
remove(fname) #remove chunk
fo.close()
- if self.nameDisposition and self.disposition:
- self.filename = save_join(dirname(self.filename), self.nameDisposition)
+ if self.name:
+ self.filename = save_join(dirname(self.filename), self.name)
move(init, fs_encode(self.filename))
self.info.remove() #remove info file
@@ -144,8 +148,7 @@ class HTTPDownload():
finally:
self.close()
- if self.nameDisposition and self.disposition: return self.nameDisposition
- return None
+ return self.name
def _download(self, chunks, resume):
if not resume:
diff --git a/module/network/HTTPRequest.py b/module/network/HTTPRequest.py
index 7887081e7..a0b419763 100644
--- a/module/network/HTTPRequest.py
+++ b/module/network/HTTPRequest.py
@@ -271,7 +271,7 @@ class HTTPRequest():
#TODO: html_unescape as default
except LookupError:
- self.log.debug("No Decoder foung for %s" % encoding)
+ self.log.debug("No Decoder found for %s" % encoding)
except Exception:
self.log.debug("Error when decoding string from %s." % encoding)
diff --git a/module/plugins/hoster/BasePlugin.py b/module/plugins/hoster/BasePlugin.py
index 2de47940d..7b204b90d 100644
--- a/module/plugins/hoster/BasePlugin.py
+++ b/module/plugins/hoster/BasePlugin.py
@@ -62,28 +62,5 @@ class BasePlugin(Hoster):
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 = 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) \ No newline at end of file
+ pyfile.name = html_unescape(urlparse(pyfile.url).path.split("/")[-1])
+ self.download(pyfile.url, disposition=True) \ No newline at end of file