-
Notifications
You must be signed in to change notification settings - Fork 58
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
113 additions
and
43 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
from pathlib import Path | ||
|
||
import aiofiles | ||
import httpx | ||
from aiofiles.base import AiofilesContextManager | ||
from aiofiles.os import makedirs | ||
from aiofiles.ospath import exists | ||
from aiofiles.threadpool.text import AsyncTextIOWrapper | ||
from bilibili_api import HEADERS | ||
|
||
client = httpx.AsyncClient(headers=HEADERS) | ||
|
||
|
||
async def download_content(url: str, path: Path) -> None: | ||
async with client.stream("GET", url) as resp, aopen(path, "wb") as f: | ||
async for chunk in resp.aiter_bytes(40960): | ||
if not chunk: | ||
return | ||
await f.write(chunk) | ||
|
||
|
||
async def aexists(path: Path) -> bool: | ||
return await exists(path) | ||
|
||
|
||
async def amakedirs(path: Path, exist_ok=False) -> None: | ||
await makedirs(path, parents=True, exist_ok=exist_ok) | ||
|
||
|
||
def aopen( | ||
path: Path, mode: str = "r", **kwargs | ||
) -> AiofilesContextManager[None, None, AsyncTextIOWrapper]: | ||
return aiofiles.open(path, mode, **kwargs) |