[bar] dynamically calculate bar size

or it'll may be too short or too long as 'total_pieces' changes
old one has problems with http://www.letv.com/ptv/vplay/1709438.html
This commit is contained in:
lilydjwg 2016-01-23 13:06:23 +08:00
parent 1c208f2a91
commit 28d04b0ad4

View File

@ -540,8 +540,8 @@ def url_save_chunked(url, filepath, bar, refer = None, is_part = False, faker =
os.rename(temp_filepath, filepath)
class SimpleProgressBar:
bar_size = term.get_terminal_size()[1] - 42
bar = '{0:>5}% ({1:>5}/{2:<5}MB) ├{3:─<' + str(bar_size) + '}┤[{4}/{5}] {6}'
# minus the size of all statically known size in self.bar
bar_size = term.get_terminal_size()[1] - 38
def __init__(self, total_size, total_pieces = 1):
self.displayed = False
@ -552,6 +552,10 @@ class SimpleProgressBar:
self.speed = ''
self.last_updated = time.time()
total_pieces_len = len(str(total_pieces))
self.bar = '{0:>5}%% ({1:>5}/{2:<5}MB) ├{3:─<%s}┤[{4:>%s}/{5:>%s}] {6}' % (
self.bar_size - 2*total_pieces_len, total_pieces_len, total_pieces_len)
def update(self):
self.displayed = True
bar_size = self.bar_size