diff options
author | RaNaN <Mast3rRaNaN@hotmail.de> | 2011-04-24 19:46:59 +0200 |
---|---|---|
committer | RaNaN <Mast3rRaNaN@hotmail.de> | 2011-04-24 19:46:59 +0200 |
commit | 1ef8f2435ec72fac64505fc11939e94665e11eef (patch) | |
tree | 76eb662a771923479e894b9c160a9b46326f33d1 /module/network | |
parent | bitshare fixes (diff) | |
download | pyload-1ef8f2435ec72fac64505fc11939e94665e11eef.tar.xz |
parse content disposition
Diffstat (limited to 'module/network')
-rw-r--r-- | module/network/Browser.py | 8 | ||||
-rw-r--r-- | module/network/HTTPChunk.py | 9 | ||||
-rw-r--r-- | module/network/HTTPDownload.py | 13 |
3 files changed, 24 insertions, 6 deletions
diff --git a/module/network/Browser.py b/module/network/Browser.py index adb2cb5d9..0bf5cf3cf 100644 --- a/module/network/Browser.py +++ b/module/network/Browser.py @@ -74,17 +74,19 @@ class Browser(object): self._size = self.dl.size self.dl.abort = True - def httpDownload(self, url, filename, get={}, post={}, ref=True, cookies=True, chunks=1, resume=False, progressNotify=None): + def httpDownload(self, url, filename, get={}, post={}, ref=True, cookies=True, chunks=1, resume=False, progressNotify=None, disposition=True): """ this can also download ftp """ self._size = 0 self.dl = HTTPDownload(url, filename, get, post, self.lastEffectiveURL if ref else None, self.cj if cookies else None, self.bucket, self.interface, - self.proxies, progressNotify) - self.dl.download(chunks, resume) + self.proxies, progressNotify, disposition) + name = self.dl.download(chunks, resume) self._size = self.dl.size self.dl = None + return name + def download(self, url, file_name, folder, get={}, post={}, ref=True, cookies=True, no_post_encode=False): self.log.warning("Browser: deprecated call 'download'") diff --git a/module/network/HTTPChunk.py b/module/network/HTTPChunk.py index 2fc48a588..a88d94afe 100644 --- a/module/network/HTTPChunk.py +++ b/module/network/HTTPChunk.py @@ -226,11 +226,16 @@ class HTTPChunk(HTTPRequest): def parseHeader(self): """parse data from recieved header""" - for line in self.header.splitlines(): - line = line.strip().lower() + for orgline in self.header.splitlines(): + line = orgline.strip().lower() 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 + 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 295c8f465..b20f565ea 100644 --- a/module/network/HTTPDownload.py +++ b/module/network/HTTPDownload.py @@ -18,6 +18,7 @@ """ from os import remove, fsync +from os.path import dirname, join from time import sleep, time from shutil import move @@ -31,7 +32,7 @@ from module.plugins.Plugin import Abort class HTTPDownload(): """ loads a url http + ftp """ def __init__(self, url, filename, get={}, post={}, referer=None, cj=None, bucket=None, - interface=None, proxies={}, progressNotify=None): + interface=None, proxies={}, progressNotify=None, disposition=True): self.url = url self.filename = filename #complete file destination, not only name self.get = get @@ -41,10 +42,12 @@ class HTTPDownload(): self.bucket = bucket self.interface = interface self.proxies = proxies + self.disposition = disposition # all arguments self.abort = False self.size = 0 + self.nameDisposition = None #will be parsed from content disposition self.chunks = [] @@ -106,10 +109,15 @@ class HTTPDownload(): remove(fname) #remove chunk fo.close() + if self.nameDisposition and self.disposition: + self.filename = join(dirname(self.filename), self.nameDisposition) + move(init, self.filename) self.info.remove() #remove info file def download(self, chunks=1, resume=False): + """ returns new filename or None """ + chunks = max(1, chunks) resume = self.info.resume and resume self.chunks = [] @@ -119,6 +127,9 @@ class HTTPDownload(): finally: self.close() + if self.nameDisposition and self.disposition: return self.nameDisposition + return None + def _download(self, chunks, resume): if not resume: self.info.clear() |