diff --git a/plugins/bilibili_sub/utils.py b/plugins/bilibili_sub/utils.py index 26c1166a..861b62ea 100755 --- a/plugins/bilibili_sub/utils.py +++ b/plugins/bilibili_sub/utils.py @@ -1,8 +1,9 @@ from utils.image_utils import BuildImage from configs.path_config import IMAGE_PATH -from utils.http_utils import AsyncHttpx +from utils.http_utils import AsyncHttpx, get_user_agent # from bilibili_api import user from bilireq.user import get_user_info +from httpx import AsyncClient from io import BytesIO @@ -85,8 +86,7 @@ async def get_meta(media_id: int, auth=None, reqtype="both", **kwargs): async def get_videos( - uid: int, tid: int = 0, pn: int = 1, keyword: str = "", order: str = "pubdate", - *, auth=None, reqtype="both", **kwargs + uid: int, tid: int = 0, pn: int = 1, keyword: str = "", order: str = "pubdate" ): """ 获取用户投该视频信息 @@ -99,17 +99,34 @@ async def get_videos( :param keyword: 搜索关键词 :param order: 排序方式,可以为 “pubdate(上传日期从新到旧), stow(收藏从多到少), click(播放量从多到少)” """ - from bilireq.utils import get + from bilireq.utils import ResponseCodeError + url = f"{BASE_URL}/x/space/arc/search" - params = { - "mid": uid, - "ps": 30, - "tid": tid, - "pn": pn, - "keyword": keyword, - "order": order - } - return await get(url, params=params, auth=auth, reqtype=reqtype, **kwargs) + headers = get_user_agent() + headers["Referer"] = f"https://space.bilibili.com/{uid}/video" + async with AsyncClient() as client: + r = await client.head( + "https://space.bilibili.com", + headers=headers, + ) + params = { + "mid": uid, + "ps": 30, + "tid": tid, + "pn": pn, + "keyword": keyword, + "order": order, + } + raw_json = ( + await client.get(url, params=params, headers=headers, cookies=r.cookies) + ).json() + if raw_json["code"] != 0: + raise ResponseCodeError( + code=raw_json["code"], + msg=raw_json["message"], + data=raw_json.get("data", None), + ) + return raw_json["data"] async def get_user_card(mid, photo: bool = False, auth=None, reqtype="both", **kwargs): from bilireq.utils import get