diff options
Diffstat (limited to 'pyload/network/HTTPDownload.py')
-rw-r--r-- | pyload/network/HTTPDownload.py | 25 |
1 files changed, 11 insertions, 14 deletions
diff --git a/pyload/network/HTTPDownload.py b/pyload/network/HTTPDownload.py index 8bf822a15..a266548cf 100644 --- a/pyload/network/HTTPDownload.py +++ b/pyload/network/HTTPDownload.py @@ -3,14 +3,14 @@ from __future__ import with_statement +import pycurl + from os import remove, fsync from os.path import dirname from time import sleep, time from shutil import move from logging import getLogger -import pycurl - from pyload.network.HTTPChunk import ChunkInfo, HTTPChunk from pyload.network.HTTPRequest import BadHeader @@ -53,7 +53,7 @@ class HTTPDownload(object): self.chunkSupport = True self.m = pycurl.CurlMulti() - #needed for speed calculation + # needed for speed calculation self.lastArrived = [] self.speeds = [] self.lastSpeeds = [0, 0] @@ -74,10 +74,7 @@ class HTTPDownload(object): @property def percent(self): - if not self.size: - return 0 - return (self.arrived * 100) / self.size - + return (self.arrived * 100) / self.size if self.size else 0 def _copyChunks(self): init = fs_encode(self.info.getChunkName(0)) #: initial chunk name @@ -118,13 +115,13 @@ class HTTPDownload(object): try: self._download(chunks, resume) except pycurl.error, e: - #code 33 - no resume + # code 33 - no resume code = e.args[0] if resume is True and code == 33: # try again without resume self.log.debug("Errno 33 -> Restart without resume") - #remove old handles + # remove old handles for chunk in self.chunks: self.closeChunk(chunk) @@ -161,7 +158,7 @@ class HTTPDownload(object): self.chunkSupport = False while 1: - #need to create chunks + # need to create chunks if not chunksCreated and self.chunkSupport and self.size: #: will be setted later by first chunk if not resume: @@ -215,7 +212,7 @@ class HTTPDownload(object): for c in err_list: curl, errno, msg = c chunk = self.findChunk(curl) - #test if chunk was finished + # test if chunk was finished if errno != 23 or "0 !=" not in msg: failed.append(chunk) ex = pycurl.error(errno, msg) @@ -237,14 +234,14 @@ class HTTPDownload(object): if failed and init not in failed and init.c not in chunksDone: self.log.error(_("Download chunks failed, fallback to single connection | %s" % (str(ex)))) - #list of chunks to clean and remove + # list of chunks to clean and remove to_clean = filter(lambda x: x is not init, self.chunks) for chunk in to_clean: self.closeChunk(chunk) self.chunks.remove(chunk) remove(fs_encode(self.info.getChunkName(chunk.id))) - #let first chunk load the rest and update the info file + # 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)) @@ -257,7 +254,7 @@ class HTTPDownload(object): if len(chunksDone) >= len(self.chunks): if len(chunksDone) > len(self.chunks): self.log.warning("Finished download chunks size incorrect, please report bug.") - done = True #all chunks loaded + done = True # all chunks loaded break |