Download video

def download_from_url(url, dst):
response = requests.get(url, stream=True)
file_size = int(response.headers['content-length'])
if os.path.exists(dst):
first_byte = os.path.getsize(dst)
else:
first_byte = 0
if first_byte >= first_byte:
return file_size
header = {"Range": f"bytes={first_byte}-{file_size}"}
bar = tqdm(total=file_size, initail=first_byte, unit='B', unit_sc=True, desc=dst)
re = requests.get(url, header=header, stream=True)
with(open(dst, 'ab')) as f:
for chunk in re.iter_content(chunk_size=1024):
if chunk:
f.write(chunk)
bar.update(1024)
bar.close()
return file_size

Guess you like

Origin www.cnblogs.com/yaohu/p/11359389.html