Skip to content

Commit

Permalink
feat: user.User.get_opus
Browse files Browse the repository at this point in the history
  • Loading branch information
Nemo2011 committed Feb 10, 2025
1 parent 54c870c commit 93e1e34
Show file tree
Hide file tree
Showing 3 changed files with 95 additions and 8 deletions.
22 changes: 19 additions & 3 deletions bilibili_api/data/api/user.json
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,8 @@
"wbi": true,
"wbi2": true,
"params": {
"mid": "int: uid"
"mid": "int: uid",
"w_webid": "str: w_webid"
},
"comment": "用户基本信息"
},
Expand Down Expand Up @@ -123,7 +124,8 @@
"verify": false,
"wbi": true,
"params": {
"mid": "int: uid"
"mid": "int: uid",
"w_webid": "str: w_webid"
},
"comment": "直播间基本信息"
},
Expand All @@ -138,7 +140,8 @@
"ps": "const int: 30",
"tid": "int: 分区 ID,0 表示全部",
"pn": "int: 页码",
"keyword": "str: 关键词,可为空"
"keyword": "str: 关键词,可为空",
"w_webid": "str: w_webid"
},
"comment": "搜索用户视频"
},
Expand Down Expand Up @@ -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": {
Expand Down
45 changes: 42 additions & 3 deletions bilibili_api/user.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
36 changes: 34 additions & 2 deletions docs/modules/user.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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)
Expand Down Expand Up @@ -226,6 +228,21 @@ medialist排序顺序。



---

## class OpusType()

**Extend: enum.Enum**

图文类型

+ ALL: 所有
+ ARTICLE: 属于专栏的图文
+ DYNAMIC: 不属于专栏(但为动态)的图文




---

## class OrderType()
Expand Down Expand Up @@ -278,7 +295,7 @@ medialist排序顺序。

### async def get_access_id()

获取用户 access_id 如未过期直接从本地获取 防止重复请求
获取用户 access_id (w_webid) 如未过期直接从本地获取 防止重复请求



Expand Down Expand Up @@ -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()

获取用户的简易订阅和投稿信息。
Expand Down Expand Up @@ -673,7 +705,7 @@ medialist排序顺序。



**Returns:** dict: 调用 API 返回的结果
**Returns:** dict: 调用 API 返回的结果



Expand Down

0 comments on commit 93e1e34

Please sign in to comment.