diff options
author | mkaay <mkaay@mkaay.de> | 2011-01-27 14:49:40 +0100 |
---|---|---|
committer | mkaay <mkaay@mkaay.de> | 2011-01-27 14:49:40 +0100 |
commit | ba84504faca42476cedeb717558b114f4084605b (patch) | |
tree | 47fc38486c75ab423d60ca5a305b31ee05a950e6 | |
parent | some improvements (diff) | |
download | pyload-ba84504faca42476cedeb717558b114f4084605b.tar.xz |
progress update optimizations
-rw-r--r-- | module/gui/Queue.py | 2 | ||||
-rw-r--r-- | module/network/Browser.py | 4 | ||||
-rw-r--r-- | module/network/HTTPDownload.py | 13 | ||||
-rw-r--r-- | module/plugins/Plugin.py | 2 |
4 files changed, 14 insertions, 7 deletions
diff --git a/module/gui/Queue.py b/module/gui/Queue.py index bcd254fb9..9751b652f 100644 --- a/module/gui/Queue.py +++ b/module/gui/Queue.py @@ -90,7 +90,7 @@ class QueueModel(CollectorModel): child = pack.getChild(d["id"]) if child: child.data["downloading"] = d - child.data["progress"] = child.data["downloading"]["percent"] + #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))) self.updateCount() diff --git a/module/network/Browser.py b/module/network/Browser.py index 054e099b3..9585eb7cc 100644 --- a/module/network/Browser.py +++ b/module/network/Browser.py @@ -74,11 +74,11 @@ class Browser(object): self._size = self.dl.size self.dl.abort = True - def httpDownload(self, url, filename, get={}, post={}, ref=True, cookies=True, chunks=1, resume=False): + def httpDownload(self, url, filename, get={}, post={}, ref=True, cookies=True, chunks=1, resume=False, progressNotify=None): """ this can also download ftp """ self.dl = HTTPDownload(url, filename, get, post, self.lastEffectiveURL if ref else None, self.cj if cookies else None, self.bucket, self.interface, - self.proxies) + self.proxies, progressNotify) self.dl.download(chunks, resume) self._size = self.dl.size diff --git a/module/network/HTTPDownload.py b/module/network/HTTPDownload.py index 5f3302ce2..394d759dc 100644 --- a/module/network/HTTPDownload.py +++ b/module/network/HTTPDownload.py @@ -31,7 +31,7 @@ from module.plugins.Plugin import Abort class HTTPDownload(): """ loads a url http + ftp """ def __init__(self, url, filename, get={}, post={}, referer=None, cj=None, bucket=None, - interface=None, proxies={}): + interface=None, proxies={}, progressNotify=None): self.url = url self.filename = filename #complete file destination, not only name self.get = get @@ -65,6 +65,8 @@ class HTTPDownload(): self.lastChecked = 0 self.lastArrived = [] self.speeds = [] + + self.progressNotify = progressNotify @property def speed(self): @@ -201,6 +203,7 @@ class HTTPDownload(): self.speeds = [float(a) / (t - self.lastChecked) for a in diff] self.lastArrived = [c.arrived for c in self.chunks] self.lastChecked = t + self.updateProgress() #print "------------------------" #print self.speed / 1024, "kb/s" #print "Arrived:", self.arrived @@ -226,7 +229,11 @@ class HTTPDownload(): if failed: raise BadHeader(failed) self._copyChunks() - + + def updateProgress(self): + if self.progressNotify: + self.progressNotify(self.percent) + def close(self): """ cleanup """ for chunk in self.chunks: @@ -254,4 +261,4 @@ if __name__ == "__main__": print "starting" dwnld = HTTPDownload(url, "test_100mb.bin", bucket=bucket) - dwnld.download(chunks=3, resume=True)
\ No newline at end of file + dwnld.download(chunks=3, resume=True) diff --git a/module/plugins/Plugin.py b/module/plugins/Plugin.py index e1c24a7f6..3c0cabb54 100644 --- a/module/plugins/Plugin.py +++ b/module/plugins/Plugin.py @@ -330,7 +330,7 @@ class Plugin(object): name = self.pyfile.name filename = save_join(location, name) try: - self.req.httpDownload(url, filename, get=get, post=post, ref=ref, chunks=self.getChunkCount(), resume=self.resumeDownload) + self.req.httpDownload(url, filename, get=get, post=post, ref=ref, chunks=self.getChunkCount(), resume=self.resumeDownload, progressNotify=self.pyfile.progress.setValue) finally: self.pyfile.size = self.req.size |