bpi_rs/dynamic/
get_dynamic_detail.rs

1use serde::{Deserialize, Serialize};
2
3use crate::models::{LevelInfo, Official, Pendant, Vip};
4use crate::{BilibiliRequest, BpiClient, BpiError, BpiResponse};
5
6#[derive(Debug, Serialize, Clone, Deserialize)]
7pub struct DynamicCardData {
8    pub card: DynamicCard,
9}
10
11#[derive(Debug, Clone, Serialize, Deserialize)]
12pub struct DynamicCard {
13    pub desc: Desc,
14    pub card: String,
15    pub extend_json: String,
16    pub display: serde_json::Value,
17}
18
19#[derive(Debug, Clone, Serialize, Deserialize)]
20pub struct Desc {
21    pub uid: i64,
22    #[serde(rename = "type")]
23    pub type_field: i64,
24    pub rid: i64,
25    pub acl: i64,
26    pub view: i64,
27    pub repost: i64,
28    pub comment: i64,
29    pub like: i64,
30    pub is_liked: i64,
31    pub dynamic_id: i64,
32    pub timestamp: i64,
33    pub pre_dy_id: i64,
34    pub orig_dy_id: i64,
35    pub orig_type: i64,
36    pub user_profile: UserProfile,
37    pub spec_type: i64,
38    pub uid_type: i64,
39    pub stype: i64,
40    pub r_type: i64,
41    pub inner_id: i64,
42    pub status: i64,
43    pub dynamic_id_str: String,
44    pub pre_dy_id_str: String,
45    pub orig_dy_id_str: String,
46    pub rid_str: String,
47    pub bvid: String,
48}
49
50#[derive(Debug, Clone, Serialize, Deserialize)]
51pub struct UserProfile {
52    pub info: Info,
53    pub card: Card,
54    pub vip: Vip,
55    pub pendant: Pendant,
56    pub rank: String,
57    pub sign: String,
58    pub level_info: LevelInfo,
59}
60
61#[derive(Debug, Clone, Serialize, Deserialize)]
62pub struct Info {
63    pub uid: i64,
64    pub uname: String,
65    pub face: String,
66}
67
68#[derive(Debug, Clone, Serialize, Deserialize)]
69pub struct Card {
70    pub official_verify: OfficialVerify,
71}
72
73#[derive(Debug, Clone, Serialize, Deserialize)]
74pub struct OfficialVerify {
75    #[serde(rename = "type")]
76    pub type_field: i64,
77}
78
79#[derive(Debug, Serialize, Clone, Deserialize)]
80pub struct RecentUpData {
81    /// 直播用户(暂不明确,可能为 null)
82    pub live_users: Option<serde_json::Value>,
83    /// 我的信息
84    pub my_info: Option<MyInfo>,
85    /// 最近更新的 UP 主列表
86    pub up_list: Vec<UpUser>,
87}
88
89/// 我的信息对象
90#[derive(Debug, Serialize, Clone, Deserialize)]
91pub struct MyInfo {
92    /// 个人动态数
93    pub dyns: i32,
94    /// 头像地址
95    pub face: String,
96    /// 粉丝数
97    pub follower: String,
98    /// 我的关注数
99    pub following: i32,
100    /// 等级信息
101    pub level_info: LevelInfo,
102    /// 用户 mid
103    pub mid: i64,
104    /// 用户昵称
105    pub name: String,
106    /// 认证信息
107    #[serde(rename = "official")]
108    pub official: Official,
109    /// 个人空间背景图
110    pub space_bg: String,
111    /// 会员信息
112    pub vip: Vip,
113}
114
115/// 最近更新的 UP 主
116#[derive(Debug, Serialize, Clone, Deserialize)]
117pub struct UpUser {
118    /// 头像
119    pub face: String,
120    /// 是否有更新
121    pub has_update: bool,
122    /// 作用不明
123    pub is_reserve_recall: bool,
124    /// 用户 mid
125    pub mid: i64,
126    /// 用户昵称
127    pub uname: String,
128}
129
130impl BpiClient {
131    /// 获取特定动态卡片信息
132    ///
133    /// 文档: https://github.com/SocialSisterYi/bilibili-API-collect/tree/master/docs/dynamic
134    ///
135    /// 参数
136    ///
137    /// | 名称 | 类型 | 说明 |
138    /// | ---- | ---- | ---- |
139    /// | `dynamic_id` | &str | 动态 ID |
140    pub async fn dynamic_card_detail(
141        &self,
142        dynamic_id: &str,
143    ) -> Result<BpiResponse<DynamicCardData>, BpiError> {
144        self.get("https://api.vc.bilibili.com/dynamic_svr/v1/dynamic_svr/get_dynamic_detail")
145            .query(&[("dynamic_id", dynamic_id)])
146            .send_bpi("获取特定动态卡片信息")
147            .await
148    }
149
150    /// 获取最近更新 UP 主列表
151    ///
152    /// 文档: https://github.com/SocialSisterYi/bilibili-API-collect/tree/master/docs/dynamic
153    pub async fn dynamic_recent_up_list(&self) -> Result<BpiResponse<RecentUpData>, BpiError> {
154        self.get("https://api.bilibili.com/x/polymer/web-dynamic/v1/portal")
155            .send_bpi("获取最近更新 UP 主列表")
156            .await
157    }
158}
159
160#[cfg(test)]
161mod tests {
162    use super::*;
163
164    #[tokio::test]
165    async fn test_dynamic_get_card_detail() {
166        let bpi = BpiClient::new();
167        let resp = bpi.dynamic_card_detail("1099138163191840776").await;
168        assert!(resp.is_ok());
169    }
170
171    #[tokio::test]
172    async fn test_dynamic_recent_up_list() {
173        let bpi = BpiClient::new();
174        let resp = bpi.dynamic_recent_up_list().await;
175        assert!(resp.is_ok());
176        if let Ok(res) = resp {
177            tracing::info!("{:#?}", res.data.unwrap().up_list.len());
178        }
179    }
180}