From 2d894dc7b43313d021d61ba201d0efa10994c696 Mon Sep 17 00:00:00 2001 From: RaNaN Date: Sun, 9 Jan 2011 18:43:50 +0100 Subject: enabled chunk download for files.mail.ru --- module/network/HTTPChunk.py | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) (limited to 'module/network') diff --git a/module/network/HTTPChunk.py b/module/network/HTTPChunk.py index 573ed1766..89770769f 100644 --- a/module/network/HTTPChunk.py +++ b/module/network/HTTPChunk.py @@ -142,6 +142,8 @@ class HTTPChunk(HTTPRequest): self.c.setopt(pycurl.WRITEFUNCTION, self.writeBody) self.c.setopt(pycurl.HEADERFUNCTION, self.writeHeader) + # request one byte more, since some servers in russia seems to have a defect arihmetic unit + if self.resume: self.fp = open(self.p.info.getChunkName(self.id), "ab") self.arrived = self.fp.tell() @@ -150,7 +152,11 @@ class HTTPChunk(HTTPRequest): #do nothing if chunk already finished if not self.arrived + self.range[0] - self.range[1]: return None - range = "%i-%i" % (self.arrived + self.range[0], self.range[1]) + if self.id == len(self.p.info.chunks) - 1: #as last chunk dont set end range, so we get everything + range = "%i-" % self.range[0] + else: + range = "%i-%i" % (self.arrived + self.range[0], min(self.range[1] + 1, self.p.size - 1)) + print "Chunked resume with range %s" % range self.c.setopt(pycurl.RANGE, range) else: @@ -159,7 +165,11 @@ class HTTPChunk(HTTPRequest): else: if self.range: - range = "%i-%i" % self.range + if self.id == len(self.p.info.chunks) - 1: # see above + range = "%i-" % self.range[0] + else: + range = "%i-%i" % (self.range[0], min(self.range[1] + 1, self.p.size - 1)) + print "Chunked with range %s" % range self.c.setopt(pycurl.RANGE, range) -- cgit v1.2.3