From 02a1fbc554cdb1c30106260be893605557db19e8 Mon Sep 17 00:00:00 2001 From: Zhao Zuohong Date: Mon, 20 Feb 2023 19:24:48 +0800 Subject: [PATCH] =?UTF-8?q?=F0=9F=8E=A8=20Pass=20download=20path=20in=20pa?= =?UTF-8?q?rameter?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- video/__init__.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) 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)}%")