def download_file(self, url: str, filepath: str, fname="", progf=False):
"""Download a file from `url` to `filepath/name`"""
r = self.session.get(url, stream=True)
dlen = r.headers.get("content-length")
step = (100 / int(dlen))
prog = 0
if not fname:
fname = unquote(Path(r.url).name)
with open(filepath+"/"+fname, 'wb') as f:
for chunk in r.iter_content(chunk_size=1024):
if chunk:
prog += len(chunk)
if progf:
progf(int(step * prog))
f.write(chunk)
if progf:
progf(0)
return filepath+"/"+fname
评论列表
文章目录