mirror of
https://github.com/spaam/svtplay-dl.git
synced 2024-11-30 23:24:16 +01:00
Merge pull request #16 from olof/topic/progressbar
Print a progressbar when downloading with HDS/HLS
This commit is contained in:
commit
878962186e
40
svtplay-dl
40
svtplay-dl
@ -330,8 +330,7 @@ def download_hds(options, url, output, swf):
|
|||||||
while i <= antal[1]["total"]:
|
while i <= antal[1]["total"]:
|
||||||
url = "%s/%sSeg1-Frag%s" % (baseurl, test["url"], i)
|
url = "%s/%sSeg1-Frag%s" % (baseurl, test["url"], i)
|
||||||
if output != "-":
|
if output != "-":
|
||||||
progresstr = "Downloading %s/%s fragments" % (i, antal[1]["total"])
|
progressbar(antal[1]["total"], i)
|
||||||
sys.stderr.write(progresstr + '\r')
|
|
||||||
data = get_http_data(url)
|
data = get_http_data(url)
|
||||||
number = decode_f4f(i, data)
|
number = decode_f4f(i, data)
|
||||||
file_d.write(data[number:])
|
file_d.write(data[number:])
|
||||||
@ -376,8 +375,7 @@ def download_hls(options, url, output, live, other):
|
|||||||
|
|
||||||
for i in files:
|
for i in files:
|
||||||
if output != "-":
|
if output != "-":
|
||||||
progresstr = "Downloading %s/%s fragments" % (n, len(files))
|
progressbar(len(files), n)
|
||||||
sys.stderr.write(progresstr + '\r')
|
|
||||||
data = get_http_data(i[0])
|
data = get_http_data(i[0])
|
||||||
if encrypted:
|
if encrypted:
|
||||||
lots = StringIO.StringIO(data)
|
lots = StringIO.StringIO(data)
|
||||||
@ -911,6 +909,40 @@ class Svt():
|
|||||||
else:
|
else:
|
||||||
download_http(filename, self.output)
|
download_http(filename, self.output)
|
||||||
|
|
||||||
|
def progressbar(total, pos, msg=""):
|
||||||
|
"""
|
||||||
|
Given a total and a progress position, output a progress bar
|
||||||
|
to stderr. It is important to not output anything else while
|
||||||
|
using this, as it relies soley on the behavior of carriage
|
||||||
|
return (\\r).
|
||||||
|
|
||||||
|
Can also take an optioal message to add after the
|
||||||
|
progressbar. It must not contain newliens.
|
||||||
|
|
||||||
|
The progress bar will look something like this:
|
||||||
|
|
||||||
|
[099/500][=========...............................] ETA: 13:36:59
|
||||||
|
|
||||||
|
Of course, the ETA part should be supplied be the calling
|
||||||
|
function.
|
||||||
|
"""
|
||||||
|
width = 50 # TODO hardcoded progressbar width
|
||||||
|
rel_pos = int(float(pos)/total*width)
|
||||||
|
bar = str()
|
||||||
|
|
||||||
|
# FIXME ugly generation of bar
|
||||||
|
for i in range(0, rel_pos):
|
||||||
|
bar += "="
|
||||||
|
for i in range(rel_pos, width):
|
||||||
|
bar += "."
|
||||||
|
|
||||||
|
# Determine how many digits in total (base 10)
|
||||||
|
digits_total = len(str(total))
|
||||||
|
fmt_width = "%0" + str(digits_total) + "d"
|
||||||
|
fmt = "\r[" + fmt_width + "/" + fmt_width + "][%s] %s"
|
||||||
|
|
||||||
|
sys.stderr.write(fmt % (pos, total, bar, msg))
|
||||||
|
|
||||||
def main():
|
def main():
|
||||||
""" Main program """
|
""" Main program """
|
||||||
usage = "usage: %prog [options] url"
|
usage = "usage: %prog [options] url"
|
||||||
|
Loading…
Reference in New Issue
Block a user