✨ Download audio and show progress
This commit is contained in:
parent
dffedeeb4e
commit
56fedd3beb
1 changed files with 15 additions and 0 deletions
15
snippets/download.py
Normal file
15
snippets/download.py
Normal file
|
@ -0,0 +1,15 @@
|
|||
from bilibili_api import HEADERS
|
||||
import httpx
|
||||
|
||||
|
||||
def download_video(url: str):
|
||||
with httpx.stream("GET", url, headers=HEADERS) as r:
|
||||
length = int(r.headers["content-length"])
|
||||
received_bytes = 0
|
||||
with open("demo.m4a", "wb") as f:
|
||||
for chunk in r.iter_bytes(1024):
|
||||
if not chunk:
|
||||
break
|
||||
received_bytes += len(chunk)
|
||||
f.write(chunk)
|
||||
print(f"downloaded {int(received_bytes / length * 100)}%")
|
Loading…
Reference in a new issue