mirror of
https://github.com/spaam/svtplay-dl.git
synced 2024-11-27 21:54:17 +01:00
svtplay_dl.output: Make progress() wrap progressbar()
The progressbar() currently does not handle the case where the total size is unknown. But with this change, progress() will internally use progressbar() for its bar generation, while still supporting a more basic progress info when total size is unknown.
This commit is contained in:
parent
ae8fda8963
commit
b31834fd6e
@ -76,24 +76,8 @@ def progress(byte, total, extra = ""):
|
||||
if total == 0:
|
||||
progresstr = "Downloaded %dkB bytes" % (byte >> 10)
|
||||
progress_stream.write(progresstr + '\r')
|
||||
else:
|
||||
ratio = float(byte) / total
|
||||
percent = round(ratio*100, 2)
|
||||
tlen = str(len(str(total)))
|
||||
fmt = "Downloaded %"+tlen+"dkB of %dkB bytes (% 3.2f%%)"
|
||||
progresstr = fmt % (byte >> 10, total >> 10, percent)
|
||||
|
||||
columns = int(os.getenv("COLUMNS", "80"))
|
||||
if len(progresstr) < columns - 13:
|
||||
p = int((columns - len(progresstr) - 3) * ratio)
|
||||
q = int((columns - len(progresstr) - 3) * (1 - ratio))
|
||||
progresstr = "[" + ("#" * p) + (" " * q) + "] " + progresstr
|
||||
progress_stream.write(progresstr + ' ' + extra + '\r')
|
||||
|
||||
if byte >= total:
|
||||
progress_stream.write('\n')
|
||||
|
||||
progress_stream.flush()
|
||||
return
|
||||
progressbar(total, byte, extra)
|
||||
|
||||
def progressbar(total, pos, msg=""):
|
||||
"""
|
||||
|
Loading…
Reference in New Issue
Block a user