From dc99fe918b035b3a049493e945d837077f79aac8 Mon Sep 17 00:00:00 2001 From: RaNaN Date: Mon, 14 Feb 2011 21:48:48 +0100 Subject: averaged download speed --- module/network/HTTPDownload.py | 14 +++++--------- module/plugins/hoster/BasePlugin.py | 7 +++++++ module/web/pyload_app.py | 4 +++- module/web/utils.py | 12 ------------ 4 files changed, 15 insertions(+), 22 deletions(-) diff --git a/module/network/HTTPDownload.py b/module/network/HTTPDownload.py index 394d759dc..4c9d0705d 100644 --- a/module/network/HTTPDownload.py +++ b/module/network/HTTPDownload.py @@ -65,12 +65,14 @@ class HTTPDownload(): self.lastChecked = 0 self.lastArrived = [] self.speeds = [] + self.lastSpeeds = [0, 0] self.progressNotify = progressNotify @property def speed(self): - return sum(self.speeds) + last = [sum(x) for x in self.lastSpeeds if x] + return (sum(self.speeds) + sum(last)) / (1 + len(last)) @property def arrived(self): @@ -197,18 +199,12 @@ class HTTPDownload(): diff = [c.arrived - (self.lastArrived[i] if len(self.lastArrived) > i else 0) for i, c in enumerate(self.chunks)] - #for i, c in enumerate(self.chunks): - # diff[i] = c.arrived - (self.lastArrived[i] if len(self.lastArrived) > i else 0) - + self.lastSpeeds[1] = self.lastSpeeds[0] + self.lastSpeeds[0] = self.speeds 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 - #print "Size:", self.size - #print self.percent, "%" if self.abort: raise Abort() diff --git a/module/plugins/hoster/BasePlugin.py b/module/plugins/hoster/BasePlugin.py index 08c53a616..92853e578 100644 --- a/module/plugins/hoster/BasePlugin.py +++ b/module/plugins/hoster/BasePlugin.py @@ -20,6 +20,13 @@ class BasePlugin(Hoster): def process(self, pyfile): """main function""" + self.__name__ = "NetloadIn" + pyfile.name = "test" + self.load("http://localhost:9000/short") + self.download("http://localhost:9000/short") + self.decryptCaptcha("http://localhost:9000/captcha") + return + if pyfile.url.startswith("http"): pyfile.name = re.findall("([^/=]+)", pyfile.url)[-1] diff --git a/module/web/pyload_app.py b/module/web/pyload_app.py index d240564ab..4d6d4354c 100644 --- a/module/web/pyload_app.py +++ b/module/web/pyload_app.py @@ -35,9 +35,11 @@ from bottle import route, static_file, request, response, redirect, HTTPError, e from webinterface import PYLOAD, PROJECT_DIR -from utils import render_to_response, parse_permissions, parse_userdata, formatSize, login_required +from utils import render_to_response, parse_permissions, parse_userdata, login_required from filters import relpath, unquotepath +from module.utils import formatSize + # Helper def pre_processor(): diff --git a/module/web/utils.py b/module/web/utils.py index d7e76f84d..f738560f7 100644 --- a/module/web/utils.py +++ b/module/web/utils.py @@ -44,18 +44,6 @@ def parse_userdata(session): "is_staff": True, "is_authenticated": session.get("authenticated", False)} -def formatSize(size): - """formats size of bytes""" - size = int(size) - steps = 0 - sizes = ["KB", "MB", "GB", "TB"] - - while size > 1000: - size /= 1024.0 - steps += 1 - - return "%.2f %s" % (size, sizes[steps]) - def login_required(perm=None): def _dec(func): def _view(*args, **kwargs): -- cgit v1.2.3