summaryrefslogtreecommitdiffstats
path: root/module/network
diff options
context:
space:
mode:
authorGravatar mkaay <mkaay@mkaay.de> 2011-01-27 14:49:40 +0100
committerGravatar mkaay <mkaay@mkaay.de> 2011-01-27 14:49:40 +0100
commitba84504faca42476cedeb717558b114f4084605b (patch)
tree47fc38486c75ab423d60ca5a305b31ee05a950e6 /module/network
parentsome improvements (diff)
downloadpyload-ba84504faca42476cedeb717558b114f4084605b.tar.xz
progress update optimizations
Diffstat (limited to 'module/network')
-rw-r--r--module/network/Browser.py4
-rw-r--r--module/network/HTTPDownload.py13
2 files changed, 12 insertions, 5 deletions
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)