From: James Bunton Date: Mon, 3 Dec 2012 06:02:41 +0000 (+1100) Subject: improved CLI status display X-Git-Url: https://code.delx.au/youtube-cgi/commitdiff_plain/dff9fe7acc006eeadc47ac893890830ea8608ee8 improved CLI status display --- diff --git a/youtube.cgi b/youtube.cgi index 8b103be..f5845a4 100755 --- a/youtube.cgi +++ b/youtube.cgi @@ -238,27 +238,32 @@ def pp_size(size): def copy_with_progress(content_length, infile, outfile): def print_status(): + rate = 0 + if now != last_ts: + rate = last_bytes_read / (now - last_ts) sys.stdout.write("\33[2K\r") sys.stdout.write("%s / %s (%s/sec)" % ( pp_size(bytes_read), pp_size(content_length), - pp_size(bytes_read / (now - start_ts)), + pp_size(rate), )) sys.stdout.flush() - start_ts = time.time() last_ts = 0 + last_bytes_read = 0 bytes_read = 0 while True: now = time.time() if now - last_ts > 0.5: - last_ts = now print_status() + last_ts = now + last_bytes_read = 0 buf = infile.read(32768) if not buf: break outfile.write(buf) + last_bytes_read += len(buf) bytes_read += len(buf) # Newline at the end