diff options
Diffstat (limited to 'module/network')
-rw-r--r-- | module/network/HTTPChunk.py | 23 | ||||
-rw-r--r-- | module/network/HTTPDownload.py | 10 |
2 files changed, 19 insertions, 14 deletions
diff --git a/module/network/HTTPChunk.py b/module/network/HTTPChunk.py index 582067aa8..b637aef32 100644 --- a/module/network/HTTPChunk.py +++ b/module/network/HTTPChunk.py @@ -20,7 +20,8 @@ from os import remove, stat, fsync from os.path import exists from time import sleep from re import search - +from module.utils import fs_encode +import codecs import pycurl from HTTPRequest import HTTPRequest @@ -31,7 +32,7 @@ class WrongFormat(Exception): class ChunkInfo(): def __init__(self, name): - self.name = name + self.name = unicode(name) self.size = 0 self.resume = False self.chunks = [] @@ -64,7 +65,8 @@ class ChunkInfo(): def save(self): - fh = open("%s.chunks" % self.name, "w") + fs_name = fs_encode("%s.chunks" % self.name) + fh = codecs.open(fs_name, "w", "utf_8") fh.write("name:%s\n" % self.name) fh.write("size:%s\n" % self.size) for i, c in enumerate(self.chunks): @@ -75,9 +77,10 @@ class ChunkInfo(): @staticmethod def load(name): - if not exists("%s.chunks" % name): + fs_name = fs_encode("%s.chunks" % name) + if not exists(fs_name): raise IOError() - fh = open("%s.chunks" % name, "r") + fh = codecs.open(fs_name, "r", "utf_8") name = fh.readline()[:-1] size = fh.readline()[:-1] if name.startswith("name:") and size.startswith("size:"): @@ -105,7 +108,8 @@ class ChunkInfo(): return ci def remove(self): - if exists("%s.chunks" % self.name): remove("%s.chunks" % self.name) + fs_name = fs_encode("%s.chunks" % self.name) + if exists(fs_name): remove(fs_name) def getCount(self): return len(self.chunks) @@ -162,11 +166,12 @@ class HTTPChunk(HTTPRequest): # request all bytes, since some servers in russia seems to have a defect arihmetic unit + fs_name = fs_encode(self.p.info.getChunkName(self.id)) if self.resume: - self.fp = open(self.p.info.getChunkName(self.id), "ab") + self.fp = open(fs_name, "ab") self.arrived = self.fp.tell() if not self.arrived: - self.arrived = stat(self.p.info.getChunkName(self.id)).st_size + self.arrived = stat(fs_name).st_size if self.range: #do nothing if chunk already finished @@ -193,7 +198,7 @@ class HTTPChunk(HTTPRequest): self.log.debug("Chunked with range %s" % range) self.c.setopt(pycurl.RANGE, range) - self.fp = open(self.p.info.getChunkName(self.id), "wb") + self.fp = open(fs_name, "wb") return self.c diff --git a/module/network/HTTPDownload.py b/module/network/HTTPDownload.py index ec742596c..fe8075539 100644 --- a/module/network/HTTPDownload.py +++ b/module/network/HTTPDownload.py @@ -29,7 +29,7 @@ from HTTPChunk import ChunkInfo, HTTPChunk from HTTPRequest import BadHeader from module.plugins.Plugin import Abort -from module.utils import save_join +from module.utils import save_join, fs_encode class HTTPDownload(): """ loads a url http + ftp """ @@ -88,7 +88,7 @@ class HTTPDownload(): return (self.arrived * 100) / self.size def _copyChunks(self): - init = self.info.getChunkName(0) #initial chunk name + init = fs_encode(self.info.getChunkName(0)) #initial chunk name if self.info.getCount() > 1: fo = open(init, "rb+") #first chunkfile @@ -96,7 +96,7 @@ class HTTPDownload(): #input file fo.seek( self.info.getChunkRange(i - 1)[1] + 1) #seek to beginning of chunk, to get rid of overlapping chunks - fname = "%s.chunk%d" % (self.filename, i) + fname = fs_encode("%s.chunk%d" % (self.filename, i)) fi = open(fname, "rb") buf = 32 * 1024 while True: #copy in chunks, consumes less memory @@ -116,7 +116,7 @@ class HTTPDownload(): if self.nameDisposition and self.disposition: self.filename = save_join(dirname(self.filename), self.nameDisposition) - move(init, self.filename) + move(init, fs_encode(self.filename)) self.info.remove() #remove info file def download(self, chunks=1, resume=False): @@ -249,7 +249,7 @@ class HTTPDownload(): for chunk in to_clean: self.closeChunk(chunk) self.chunks.remove(chunk) - remove(self.info.getChunkName(chunk.id)) + remove(fs_encode(self.info.getChunkName(chunk.id))) #let first chunk load the rest and update the info file init.resetRange() |