diff options
author | mkaay <mkaay@mkaay.de> | 2010-12-23 11:28:03 +0100 |
---|---|---|
committer | mkaay <mkaay@mkaay.de> | 2010-12-23 11:28:03 +0100 |
commit | a4ba4ba12aff34c967f958576db40806656c3de8 (patch) | |
tree | 57a26d6559279fa4ed9c28fadfa31f4d36a7eceb | |
parent | new download backend integrated so far, downloading works, but still big todo... (diff) | |
download | pyload-a4ba4ba12aff34c967f958576db40806656c3de8.tar.xz |
fixed eta and progress, ready for first test
-rw-r--r-- | module/PyFile.py | 10 | ||||
-rw-r--r-- | module/gui/Queue.py | 1 | ||||
-rw-r--r-- | module/network/FTPBase.py | 4 | ||||
-rw-r--r-- | module/network/HTTPChunk.py | 4 | ||||
-rw-r--r-- | module/network/HTTPDownload.py | 8 | ||||
-rw-r--r-- | module/network/XDCCBase.py | 4 | ||||
-rw-r--r-- | module/network/helper.py | 8 | ||||
-rw-r--r-- | module/plugins/Plugin.py | 3 | ||||
-rwxr-xr-x | pyLoadCore.py | 4 |
9 files changed, 36 insertions, 10 deletions
diff --git a/module/PyFile.py b/module/PyFile.py index 1723808c7..e7c7c2c2b 100644 --- a/module/PyFile.py +++ b/module/PyFile.py @@ -70,6 +70,7 @@ class PyFile(): # database information ends here self.plugin = None + self.download = None self.waitUntil = 0 # time() + time to wait @@ -207,21 +208,21 @@ class PyFile(): def getSpeed(self): """ calculates speed """ try: - return self.plugin.req.speed/1024 #kb/s + return self.download.speed except: return 0 def getETA(self): """ gets established time of arrival""" try: - return self.plugin.req.get_ETA() + return self.getBytesLeft() / self.getSpeed() except: return 0 def getBytesLeft(self): """ gets bytes left """ try: - return self.plugin.req.bytes_left() + return self.download.size - self.download.arrived except: return 0 @@ -234,7 +235,8 @@ class PyFile(): if self.size: return self.size else: try: - return self.plugin.req.dl_size + if not self.download.size: return 0 + return self.download.size except: return 0 diff --git a/module/gui/Queue.py b/module/gui/Queue.py index aa1afbd3c..7c5c59f15 100644 --- a/module/gui/Queue.py +++ b/module/gui/Queue.py @@ -88,7 +88,6 @@ class QueueModel(CollectorModel): child = pack.getChild(d["id"]) if child: child.data["downloading"] = d - child.data["progress"] = child.data["downloading"]["percent"] k = pack.getChildKey(d["id"]) self.emit(SIGNAL("dataChanged(const QModelIndex &, const QModelIndex &)"), self.index(k, 0, self.index(p, 0)), self.index(k, self.cols, self.index(p, self.cols))) diff --git a/module/network/FTPBase.py b/module/network/FTPBase.py index 036da383a..ce4627d0c 100644 --- a/module/network/FTPBase.py +++ b/module/network/FTPBase.py @@ -128,6 +128,10 @@ class FTPDownload(): self.speed = self.speedCalcLen self.speedCalcTime = inttime() self.speedCalcLen = 0 + try: + self.deferred.progress("percent", 100-int((self.size - self.arrived)/float(self.size)*100)) + except: + pass size = len(data) self.speedCalcLen += size self.arrived += size diff --git a/module/network/HTTPChunk.py b/module/network/HTTPChunk.py index f26e681b6..48ebc13f3 100644 --- a/module/network/HTTPChunk.py +++ b/module/network/HTTPChunk.py @@ -92,6 +92,10 @@ class HTTPChunk(HTTPBase): self.speed = self.speedCalcLen self.speedCalcTime = inttime() self.speedCalcLen = 0 + try: + self.deferred.progress("percent", 100-int((self.size - self.arrived)/float(self.size)*100)) + except: + pass size = len(data) self.arrived += size diff --git a/module/network/HTTPDownload.py b/module/network/HTTPDownload.py index e38e1ba1b..1baf0ccad 100644 --- a/module/network/HTTPDownload.py +++ b/module/network/HTTPDownload.py @@ -167,6 +167,9 @@ class HTTPDownload(object): def speed(self): return self.getSpeed() + def calcProgress(self, p): + self.deferred.progress("percent", 100-int((self.size - self.arrived)/float(self.size)*100)) + def _copyChunks(self): fo = open(self.filename, "wb") for i in range(self.info.getCount()): @@ -219,6 +222,7 @@ class HTTPDownload(object): self.chunks.append(chunk) d = chunk.download() dg.addDeferred(d) + d.addProgress("percent", self.calcProgress) if not self.info.loaded: size = chunk.size @@ -266,6 +270,7 @@ class HTTPDownload(object): break self.chunks.append(chunk) dg.addDeferred(d) + d.addProgress("percent", self.calcProgress) if not self.info.loaded: self.info.addChunk("%s.chunk%d" % (self.filename, i), chunk.range, chunk.getEncoding()) @@ -274,7 +279,8 @@ class HTTPDownload(object): dg.addCallback(self._copyChunks) if not len(self.chunks): dg.callback() - return WrappedHTTPDeferred(self, dg) + dg.addErrback(self.deferred.error) + return WrappedHTTPDeferred(self, self.deferred) else: raise Exception("no chunks") diff --git a/module/network/XDCCBase.py b/module/network/XDCCBase.py index 6d9978b80..d36d6e897 100644 --- a/module/network/XDCCBase.py +++ b/module/network/XDCCBase.py @@ -120,6 +120,10 @@ class XDCCDownload(): self.speed = self.speedCalcLen self.speedCalcTime = inttime() self.speedCalcLen = 0 + try: + self.deferred.progress("percent", 100-int((self.size - self.arrived)/float(self.size)*100)) + except: + pass size = len(data) self.speedCalcLen += size self.arrived += size diff --git a/module/network/helper.py b/module/network/helper.py index ed9a88798..ebe0fa8f5 100644 --- a/module/network/helper.py +++ b/module/network/helper.py @@ -36,7 +36,6 @@ class Deferred(): kwargs.update(ckwargs) callInThread(f, *args, **kwargs) - #test not in use def addProgress(self, chain, f): if self.prgr.has_key(chain): self.prgr[chain].append(f) @@ -67,7 +66,6 @@ class Deferred(): kwargs.update(ckwargs) callInThread(f, *args, **kwargs) - #test not in use def progress(self, chain, *args, **kwargs): if not self.prgr.has_key(chain): return @@ -141,12 +139,18 @@ class WrappedDeferred(object): def addErrback(self, *args, **kwargs): self.__dict__["d"].addErrback(*args, **kwargs) + def addProgress(self, *args, **kwargs): + self.__dict__["d"].addProgress(*args, **kwargs) + def callback(self, *args, **kwargs): self.__dict__["d"].callback(*args, **kwargs) def error(self, *args, **kwargs): self.__dict__["d"].error(*args, **kwargs) + def progress(self, *args, **kwargs): + self.__dict__["d"].progress(*args, **kwargs) + def __getattr__(self, attr): return getattr(self.download, attr) diff --git a/module/plugins/Plugin.py b/module/plugins/Plugin.py index 4af3d0d8b..0406923c0 100644 --- a/module/plugins/Plugin.py +++ b/module/plugins/Plugin.py @@ -331,7 +331,10 @@ class Plugin(object): name = self.pyfile.name.encode(sys.getfilesystemencoding(), "replace") filename = join(location, name) d = self.req.httpDownload(url, filename, get=get, post=post, chunks=self.getChunkCount(), resume=self.resumeDownload) + self.pyfile.download = d + d.addProgress("percent", self.pyfile.progress.setValue) waitFor(d) + self.pyfile.download = None newname = basename(filename) self.pyfile.size = self.req.dl_size diff --git a/pyLoadCore.py b/pyLoadCore.py index bdbd29215..b64ef33f2 100755 --- a/pyLoadCore.py +++ b/pyLoadCore.py @@ -579,7 +579,7 @@ class ServerMethods(): download = {} download['id'] = pyfile.id download['name'] = pyfile.name - download['speed'] = pyfile.getSpeed() + download['speed'] = pyfile.getSpeed()/1024 download['eta'] = pyfile.getETA() download['format_eta'] = pyfile.formatETA() download['kbleft'] = pyfile.getBytesLeft() #holded for backward comp. @@ -640,7 +640,7 @@ class ServerMethods(): status['speed'] = 0 for pyfile in [x.active for x in self.core.threadManager.threads if x.active and x.active != "quit"]: - status['speed'] += pyfile.getSpeed() + status['speed'] += pyfile.getSpeed()/1024 status['download'] = not self.core.threadManager.pause and self.is_time_download() status['reconnect'] = self.core.config['reconnect']['activated'] and self.is_time_reconnect() |