diff options
author | RaNaN <Mast3rRaNaN@hotmail.de> | 2014-01-13 20:15:31 +0100 |
---|---|---|
committer | RaNaN <Mast3rRaNaN@hotmail.de> | 2014-01-13 20:15:31 +0100 |
commit | 8525f2b4e6ccbd1030bbe0f044f53e3c1206c250 (patch) | |
tree | 41068032d96f8f9cefb16c832272ea8b9425c4d5 | |
parent | fixed setup (diff) | |
download | pyload-8525f2b4e6ccbd1030bbe0f044f53e3c1206c250.tar.xz |
small fixes and improvements for download engine
-rw-r--r-- | pyload/datatypes/PyFile.py | 5 | ||||
-rw-r--r-- | pyload/plugins/Hoster.py | 2 | ||||
-rw-r--r-- | pyload/plugins/network/CurlChunk.py | 21 | ||||
-rw-r--r-- | pyload/plugins/network/CurlDownload.py | 4 | ||||
-rw-r--r-- | pyload/utils/fs.py | 2 |
5 files changed, 17 insertions, 17 deletions
diff --git a/pyload/datatypes/PyFile.py b/pyload/datatypes/PyFile.py index 58d9f6a6f..18ac06c50 100644 --- a/pyload/datatypes/PyFile.py +++ b/pyload/datatypes/PyFile.py @@ -21,6 +21,7 @@ from ReadWriteLock import ReadWriteLock from pyload.Api import ProgressInfo, ProgressType, DownloadProgress, FileInfo, DownloadInfo, DownloadStatus from pyload.utils import lock, read_lock +from pyload.utils.fs import safe_filename from pyload.utils.filetypes import guess_type statusMap = { @@ -75,7 +76,7 @@ class PyFile(object): self.m = manager self.fid = int(fid) - self._name = name + self._name = safe_filename(name) self._size = size self.filestatus = filestatus self.media = media @@ -127,6 +128,8 @@ class PyFile(object): if type(name) == str: name = name.decode("utf8") + name = safe_filename(name) + # media type is updated if needed if self._name != name: self.media = guess_type(name) diff --git a/pyload/plugins/Hoster.py b/pyload/plugins/Hoster.py index 0ad07878a..f63b83f5f 100644 --- a/pyload/plugins/Hoster.py +++ b/pyload/plugins/Hoster.py @@ -274,7 +274,7 @@ class Hoster(Base): # convert back to unicode location = fs_decode(location) - name = safe_filename(self.pyfile.name) + name = self.pyfile.name filename = join(location, name) diff --git a/pyload/plugins/network/CurlChunk.py b/pyload/plugins/network/CurlChunk.py index 75be9ce6c..7f9d6282a 100644 --- a/pyload/plugins/network/CurlChunk.py +++ b/pyload/plugins/network/CurlChunk.py @@ -16,23 +16,19 @@ # @author: RaNaN ############################################################################### + +import re from os import remove, stat, fsync from os.path import exists from time import sleep -from re import search import codecs import pycurl -from pyload.utils import remove_chars -from pyload.utils.fs import fs_encode, fs_decode +from pyload.utils.fs import fs_encode, fs_decode, safe_filename from CurlRequest import CurlRequest -class WrongFormat(Exception): - pass - - class ChunkInfo(): def __init__(self, name): self.name = fs_decode(name) @@ -91,7 +87,7 @@ class ChunkInfo(): size = size[5:] else: fh.close() - raise WrongFormat() + raise TypeError("chunk.file has wrong format") ci = ChunkInfo(name) ci.loaded = True ci.setSize(size) @@ -104,7 +100,7 @@ class ChunkInfo(): name = name[5:] range = range[6:].split("-") else: - raise WrongFormat() + raise TypeError("chunk.file has wrong format") ci.addChunk(name, (long(range[0]), long(range[1]))) fh.close() @@ -123,6 +119,7 @@ class ChunkInfo(): def getChunkRange(self, index): return self.chunks[index][1] +re_filename = re.compile(r"filename(?P<type>=|\*=(?P<enc>.+)'')(?P<name>.*)", re.I) class CurlChunk(CurlRequest): def __init__(self, id, parent, range=None, resume=False): @@ -215,7 +212,7 @@ class CurlChunk(CurlRequest): if not self.range and self.header.endswith("\r\n\r\n"): self.parseHeader() elif not self.range and buf.startswith("150") and "data connection" in buf: #ftp file size parsing - size = search(r"(\d+) bytes", buf) + size = re.search(r"(\d+) bytes", buf) if size: self.p._size = int(size.group(1)) self.p.chunkSupport = True @@ -266,9 +263,9 @@ class CurlChunk(CurlRequest): if "content-disposition" in line: - m = search("filename(?P<type>=|\*=(?P<enc>.+)'')(?P<name>.*)", line) + m = re_filename.search(orgline.strip()) if m: - name = remove_chars(m.groupdict()['name'], "\"';/").strip() + name = safe_filename(m.groupdict()['name']).strip("\"' ") self.p._name = name self.log.debug("Content-Disposition: %s" % name) diff --git a/pyload/plugins/network/CurlDownload.py b/pyload/plugins/network/CurlDownload.py index 985513691..e23f193e7 100644 --- a/pyload/plugins/network/CurlDownload.py +++ b/pyload/plugins/network/CurlDownload.py @@ -97,7 +97,7 @@ class CurlDownload(Download): fo.close() if self.name: - self.filename = save_join(dirname(self.path), self.name) + self.path = save_join(dirname(self.path), self.name) move(init, fs_encode(self.path)) self.info.remove() #remove info file @@ -254,7 +254,7 @@ class CurlDownload(Download): #let first chunk load the rest and update the info file init.resetRange() self.info.clear() - self.info.addChunk("%s.chunk0" % self.filename, (0, self.size)) + self.info.addChunk("%s.chunk0" % self.path, (0, self.size)) self.info.save() elif failed: raise ex diff --git a/pyload/utils/fs.py b/pyload/utils/fs.py index 939adb87c..95fcd9e9f 100644 --- a/pyload/utils/fs.py +++ b/pyload/utils/fs.py @@ -51,7 +51,7 @@ def listdir(path): def safe_filename(name): #remove some chars if os.name == 'nt': - return remove_chars(name, '/\\?%*:|"<>,') + return remove_chars(name, '/\\?%*:;|"<>,') else: return remove_chars(name, '/\\"') |