bitrate'i adam gibi hesaplar mıyız lütfen.. teşekkürler.

This commit is contained in:
A. Murat Eren
2005-10-20 18:53:52 +00:00
parent bc84a9b95e
commit 43106ef33b
+8 -8
View File
@@ -26,6 +26,7 @@ from mimetypes import guess_type
from mimetools import Message from mimetools import Message
from base64 import encodestring from base64 import encodestring
from shutil import move from shutil import move
from time import time
import gettext import gettext
__trans = gettext.translation('pisi', fallback=True) __trans = gettext.translation('pisi', fallback=True)
@@ -88,28 +89,27 @@ class Fetcher:
def _do_grab(self, fileURI, dest, totalsize): def _do_grab(self, fileURI, dest, totalsize):
symbols = [' B/s', 'KB/s', 'MB/s', 'GB/s'] symbols = [' B/s', 'KB/s', 'MB/s', 'GB/s']
from time import time bs, tt, = 1024, int(time())
tt, oldsize = int(time()), 0 size = existsize = self.existsize
bs, size = 1024, self.existsize
symbol, depth = "B/s", 0 symbol, depth = "B/s", 0
st = time() st = time()
chunk = fileURI.read(bs) chunk = fileURI.read(bs)
size = size + len(chunk) size += len(chunk)
if self.progress: if self.progress:
p = self.progress(totalsize, self.existsize) p = self.progress(totalsize, existsize)
self.percent = p.update(size) self.percent = p.update(size)
while chunk: while chunk:
dest.write(chunk) dest.write(chunk)
chunk = fileURI.read(bs) chunk = fileURI.read(bs)
size = size + len(chunk) size += len(chunk)
ct = time() ct = time()
if int(tt) != int(ct): if int(tt) != int(ct):
self.rate = size / (ct - st) self.rate = (size - existsize) / (ct - st)
while self.rate > 1000 and depth < 3: while self.rate > 1000 and depth < 3:
self.rate /= 1024 self.rate /= 1024
depth += 1 depth += 1
symbol, depth = symbols[depth], 0 symbol, depth = symbols[depth], 0
oldsize, tt = size, time() tt = time()
if self.progress: if self.progress:
if p.update(size): if p.update(size):
self.percent = p.percent self.percent = p.percent