1use serde::{ Deserialize, Serialize };
2
3use crate::{ BilibiliRequest, BpiClient, BpiError, BpiResponse };
4
5#[derive(Debug, Serialize, Clone, Deserialize)]
8pub struct RoomPendantFrame {
9 pub name: String,
11 pub value: String,
13 pub position: i32,
15 pub desc: String,
17 pub area: i32,
19 pub area_old: i32,
21 pub bg_color: String,
23 pub bg_pic: String,
25 pub use_old_area: bool,
27}
28
29#[derive(Debug, Serialize, Clone, Deserialize)]
30pub struct RoomPendantBadge {
31 pub name: String,
33 pub position: i32,
35 pub value: String,
37 pub desc: String,
39}
40
41#[derive(Debug, Serialize, Clone, Deserialize)]
42pub struct RoomPendants {
43 pub frame: RoomPendantFrame,
45 pub mobile_frame: Option<RoomPendantFrame>,
47 pub badge: RoomPendantBadge,
49 pub mobile_badge: Option<RoomPendantBadge>,
51}
52
53#[derive(Debug, Serialize, Clone, Deserialize)]
54pub struct RoomStudioInfo {
55 #[serde(flatten)]
57 pub extra: serde_json::Value,
58}
59
60#[derive(Debug, Serialize, Clone, Deserialize)]
61pub struct RoomInfoData {
62 pub uid: i64,
64 pub room_id: i64,
66 pub short_id: i64,
68 pub attention: i64,
70 pub online: i64,
72 pub is_portrait: bool,
74 pub description: String,
76 pub live_status: i32,
78 pub area_id: i32,
80 pub parent_area_id: i32,
82 pub parent_area_name: String,
84 pub old_area_id: i32,
86 pub background: String,
88 pub title: String,
90 pub user_cover: String,
92 pub keyframe: String,
94 pub live_time: String,
96 pub tags: String,
98 pub room_silent_type: String,
100 pub room_silent_level: i32,
102 pub room_silent_second: i64,
104 pub area_name: String,
106 pub hot_words: Vec<String>,
108 pub hot_words_status: i32,
110 pub new_pendants: RoomPendants,
112 pub pk_status: i32,
114 pub pk_id: i64,
116 pub allow_change_area_time: i64,
118 pub allow_upload_cover_time: i64,
120 pub studio_info: Option<RoomStudioInfo>,
122}
123
124impl BpiClient {
125 pub async fn live_room_info(
131 &self,
132 room_id: i64
133 ) -> Result<BpiResponse<RoomInfoData>, BpiError> {
134 let params = [("room_id", room_id.to_string())];
135
136 let resp = self
137 .get("https://api.live.bilibili.com/room/v1/Room/get_info")
138 .query(¶ms)
139 .send_bpi("获取直播间信息").await?;
140
141 Ok(resp)
142 }
143}
144
145#[cfg(test)]
146mod tests {
147 use super::*;
148
149 #[tokio::test]
150 async fn test_get_room_info() -> Result<(), Box<BpiError>> {
151 let bpi = BpiClient::new();
152 let result = bpi.live_room_info(23174842).await?;
153
154 let data = result.data.unwrap();
155 assert_eq!(data.room_id, 23174842);
156 Ok(())
157 }
158}