diff --git a/video/__init__.py b/video/__init__.py index b89740d..435cda2 100644 --- a/video/__init__.py +++ b/video/__init__.py @@ -1,6 +1,7 @@ from exceptions import * from bilibili_api import video, sync, HEADERS import httpx +import os class Video: @@ -54,14 +55,13 @@ class Video: ) self.url = streams[1].url - def download_video(self): + def download(self, file: int | str | bytes | os.PathLike): with httpx.stream("GET", self.url, headers=HEADERS) as r: self.length = int(r.headers["content-length"]) self.received_bytes = 0 - with open("demo.m4a", "wb") as f: + with open(file, "wb") as f: for chunk in r.iter_bytes(1024): if not chunk: break self.received_bytes += len(chunk) f.write(chunk) - print(f"downloaded {int(self.received_bytes / self.length * 100)}%")