summaryrefslogtreecommitdiffstats
path: root/module
diff options
context:
space:
mode:
authorGravatar RaNaN <Mast3rRaNaN@hotmail.de> 2011-04-24 19:46:59 +0200
committerGravatar RaNaN <Mast3rRaNaN@hotmail.de> 2011-04-24 19:46:59 +0200
commit1ef8f2435ec72fac64505fc11939e94665e11eef (patch)
tree76eb662a771923479e894b9c160a9b46326f33d1 /module
parentbitshare fixes (diff)
downloadpyload-1ef8f2435ec72fac64505fc11939e94665e11eef.tar.xz
parse content disposition
Diffstat (limited to 'module')
-rw-r--r--module/network/Browser.py8
-rw-r--r--module/network/HTTPChunk.py9
-rw-r--r--module/network/HTTPDownload.py13
-rw-r--r--module/plugins/Plugin.py6
-rw-r--r--module/web/pyload_app.py9
-rw-r--r--module/web/templates/default/info.html10
6 files changed, 42 insertions, 13 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()
diff --git a/module/plugins/Plugin.py b/module/plugins/Plugin.py
index 488d05432..5607b8331 100644
--- a/module/plugins/Plugin.py
+++ b/module/plugins/Plugin.py
@@ -327,7 +327,7 @@ class Plugin(object):
return res
- def download(self, url, get={}, post={}, ref=True, cookies=True):
+ def download(self, url, get={}, post={}, ref=True, cookies=True, disposition=True):
""" downloads the url content to disk """
self.pyfile.setStatus("downloading")
@@ -355,13 +355,13 @@ class Plugin(object):
filename = save_join(location, name)
try:
- newname = self.req.httpDownload(url, filename, get=get, post=post, ref=ref, chunks=self.getChunkCount(), resume=self.resumeDownload, progressNotify=self.pyfile.progress.setValue)
+ newname = self.req.httpDownload(url, filename, get=get, post=post, ref=ref, cookies=cookies, chunks=self.getChunkCount(), resume=self.resumeDownload, progressNotify=self.pyfile.progress.setValue, disposition=disposition)
finally:
self.pyfile.size = self.req.size
if newname and newname != filename:
self.log.info("%(name)s saved as %(newname)s" % {"name": name, "newname": newname})
- #self.pyfile.name = newname
+ self.pyfile.name = newname
filename = newname
if self.core.config["permission"]["change_file"]:
diff --git a/module/web/pyload_app.py b/module/web/pyload_app.py
index 102638885..fc2302809 100644
--- a/module/web/pyload_app.py
+++ b/module/web/pyload_app.py
@@ -18,11 +18,12 @@
"""
from copy import deepcopy
from datetime import datetime
-from itertools import chain
from operator import itemgetter
-import os
+
import time
+import os
+import sys
from os import listdir
from os.path import isdir, isfile, join ,abspath
from sys import getfilesystemencoding
@@ -514,7 +515,9 @@ def info():
conf = PYLOAD.get_config()
- data = {"version": PYLOAD.get_server_version(),
+ data = {"python": sys.version,
+ "os": " ".join((os.name,) + os.uname()),
+ "version": PYLOAD.get_server_version(),
"folder": abspath(PYLOAD_DIR), "config": abspath(""),
"download": abspath(conf["general"]["download_folder"]["value"]),
"remote": conf["remote"]["port"]["value"],
diff --git a/module/web/templates/default/info.html b/module/web/templates/default/info.html
index f1ef06814..b9ee3b1bd 100644
--- a/module/web/templates/default/info.html
+++ b/module/web/templates/default/info.html
@@ -20,8 +20,16 @@
<h3>{{ _("System") }}</h3>
<table class="system">
+ <tr>
+ <td>{{ _("Python:") }}</td>
+ <td>{{ python }}</td>
+ </tr>
+ <tr>
+ <td>{{ _("OS:") }}</td>
+ <td>{{ os }}</td>
+ </tr>
<tr>
- <td>{{ _("Version:") }}</td>
+ <td>{{ _("pyLoad version:") }}</td>
<td>{{ version }}</td>
</tr>
<tr>