import os from urllib.request import urlopen import requests from tqdm import tqdm def download_from_url(url, dst): file_size = int(urlopen(url).info().get('Content-Length', -1)) if os.path.exists(dst): first_byte = os.path.getsize(dst) else: first_byte = 0 if first_byte >= file_size: return file_size header = {"Range": "bytes=%s-%s" % (first_byte, file_size)} pbar = tqdm( total=file_size, initial=first_byte, unit='B', unit_scale=True, desc='歌名') req = requests.get(url, headers=header, stream=True) with(open(dst, 'ab')) as f: for chunk in req.iter_content(chunk_size=1024): if chunk: f.write(chunk) pbar.update(1024) pbar.close() return file_size if __name__ == '__main__': url = "http://dl.stream.qqmusic.qq.com/C400000YAVGg3tvltV.m4a?vkey=BFE038E4F6F4FD50F9C38E7B34BE6209831B072157BFD66CB79ED02188A655424FFA9C20776C809A631C872B3DA331C2EDB3CA54C03FD6CE&guid=6612300644&uin=0&fromtag=66" download_from_url(url, "./new.mp4")
tqmd实现进度条
最新推荐文章于 2023-11-01 20:56:47 发布