diff --git a/bilibili_api/data/api/user.json b/bilibili_api/data/api/user.json index 77f714a5..33a30d59 100644 --- a/bilibili_api/data/api/user.json +++ b/bilibili_api/data/api/user.json @@ -48,7 +48,8 @@ "wbi": true, "wbi2": true, "params": { - "mid": "int: uid" + "mid": "int: uid", + "w_webid": "str: w_webid" }, "comment": "用户基本信息" }, @@ -123,7 +124,8 @@ "verify": false, "wbi": true, "params": { - "mid": "int: uid" + "mid": "int: uid", + "w_webid": "str: w_webid" }, "comment": "直播间基本信息" }, @@ -138,7 +140,8 @@ "ps": "const int: 30", "tid": "int: 分区 ID,0 表示全部", "pn": "int: 页码", - "keyword": "str: 关键词,可为空" + "keyword": "str: 关键词,可为空", + "w_webid": "str: w_webid" }, "comment": "搜索用户视频" }, @@ -520,6 +523,19 @@ "verify": true, "wbi": true, "comment": "获取与某用户的关系" + }, + "opus": { + "url": "https://api.bilibili.com/x/polymer/web-dynamic/v1/opus/feed/space", + "method": "GET", + "wbi": true, + "params": { + "host_mid": "int: uid", + "page": "int: 页码 非必要,且貌似对结果影响不大", + "offset": "int: 动态偏移用,第一页为空", + "type": "str: all / article / dynamic", + "web_location": "333.1387", + "w_webid":"str: w_webid" + } } }, "operate": { diff --git a/bilibili_api/user.py b/bilibili_api/user.py index e8f15100..c3bc6488 100644 --- a/bilibili_api/user.py +++ b/bilibili_api/user.py @@ -199,6 +199,20 @@ class OrderType(Enum): asc = "asc" +class OpusType(Enum): + """ + 图文类型 + + + ALL: 所有 + + ARTICLE: 属于专栏的图文 + + DYNAMIC: 不属于专栏(但为动态)的图文 + """ + + ALL = "all" + ARTICLE = "article" + DYNAMIC = "dynamic" + + async def name2uid(names: Union[str, List[str]], credential: Credential = None): """ 将用户名转为 uid @@ -1007,15 +1021,40 @@ async def get_uplikeimg(self) -> dict: 视频三联特效 Returns: - dict: 调用 API 返回的结果。 + dict: 调用 API 返回的结果 """ api = API["info"]["uplikeimg"] params = {"vmid": self.get_uid()} - return await Api(**api).update_params(**params).result + return ( + await Api(**api, credential=self.credential).update_params(**params).result + ) + + async def get_opus(self, type_: OpusType = OpusType.ALL, offset: str = "") -> dict: + """ + 获取用户发布过的图文 + + Args: + type_ (OpusType, optional): 获取的图文类型. Defaults to OpusType.ALL. + offset (str, optional) : 偏移量。每次请求可获取下次请求对应的偏移量,类似单向链表。对应返回结果的 `["offset"]` Defaults to "". + + Returns: + dict: 调用 API 返回的结果 + """ + api = API["info"]["opus"] + params = { + "host_mid": self.get_uid(), + "offset": offset, + "type": type_.value, + "web_location": "333.1387", + "w_webid": await self.get_access_id(), + } + return ( + await Api(**api, credential=self.credential).update_params(**params).result + ) async def get_access_id(self) -> str: """ - 获取用户 access_id 如未过期直接从本地获取 防止重复请求 + 获取用户 access_id (w_webid) 如未过期直接从本地获取 防止重复请求 Returns: str: access_id diff --git a/docs/modules/user.md b/docs/modules/user.md index 8b0354a7..c76e6768 100644 --- a/docs/modules/user.md +++ b/docs/modules/user.md @@ -19,6 +19,7 @@ from bilibili_api import user - [class HistoryBusinessType()](#class-HistoryBusinessType) - [class HistoryType()](#class-HistoryType) - [class MedialistOrder()](#class-MedialistOrder) +- [class OpusType()](#class-OpusType) - [class OrderType()](#class-OrderType) - [class RelationType()](#class-RelationType) - [class User()](#class-User) @@ -42,6 +43,7 @@ from bilibili_api import user - [async def get\_live\_info()](#async-def-get\_live\_info) - [async def get\_masterpiece()](#async-def-get\_masterpiece) - [async def get\_media\_list()](#async-def-get\_media\_list) + - [async def get\_opus()](#async-def-get\_opus) - [async def get\_overview\_stat()](#async-def-get\_overview\_stat) - [async def get\_relation()](#async-def-get\_relation) - [async def get\_relation\_info()](#async-def-get\_relation\_info) @@ -226,6 +228,21 @@ medialist排序顺序。 +--- + +## class OpusType() + +**Extend: enum.Enum** + +图文类型 + ++ ALL: 所有 ++ ARTICLE: 属于专栏的图文 ++ DYNAMIC: 不属于专栏(但为动态)的图文 + + + + --- ## class OrderType() @@ -278,7 +295,7 @@ medialist排序顺序。 ### async def get_access_id() -获取用户 access_id 如未过期直接从本地获取 防止重复请求 +获取用户 access_id (w_webid) 如未过期直接从本地获取 防止重复请求 @@ -547,6 +564,21 @@ medialist排序顺序。 +### async def get_opus() + +获取用户发布过的图文 + + +| name | type | description | +| - | - | - | +| type_ | OpusType, optional | 获取的图文类型. Defaults to OpusType.ALL. | +| offset | str, optional | 偏移量。每次请求可获取下次请求对应的偏移量,类似单向链表。对应返回结果的 `["offset"]` Defaults to "". | + +**Returns:** dict: 调用 API 返回的结果 + + + + ### async def get_overview_stat() 获取用户的简易订阅和投稿信息。 @@ -673,7 +705,7 @@ medialist排序顺序。 -**Returns:** dict: 调用 API 返回的结果。 +**Returns:** dict: 调用 API 返回的结果