use serde::{ Deserialize, Serialize };
use crate::{ BilibiliRequest, BpiClient, BpiError, BpiResponse };
#[derive(Debug, Serialize, Clone, Deserialize)]
pub struct RoomPendantFrame {
pub name: String,
pub value: String,
pub position: i32,
pub desc: String,
pub area: i32,
pub area_old: i32,
pub bg_color: String,
pub bg_pic: String,
pub use_old_area: bool,
}
#[derive(Debug, Serialize, Clone, Deserialize)]
pub struct RoomPendantBadge {
pub name: String,
pub position: i32,
pub value: String,
pub desc: String,
}
#[derive(Debug, Serialize, Clone, Deserialize)]
pub struct RoomPendants {
pub frame: RoomPendantFrame,
pub mobile_frame: Option<RoomPendantFrame>,
pub badge: RoomPendantBadge,
pub mobile_badge: Option<RoomPendantBadge>,
}
#[derive(Debug, Serialize, Clone, Deserialize)]
pub struct RoomStudioInfo {
#[serde(flatten)]
pub extra: serde_json::Value,
}
#[derive(Debug, Serialize, Clone, Deserialize)]
pub struct RoomInfoData {
pub uid: i64,
pub room_id: i64,
pub short_id: i64,
pub attention: i64,
pub online: i64,
pub is_portrait: bool,
pub description: String,
pub live_status: i32,
pub area_id: i32,
pub parent_area_id: i32,
pub parent_area_name: String,
pub old_area_id: i32,
pub background: String,
pub title: String,
pub user_cover: String,
pub keyframe: String,
pub live_time: String,
pub tags: String,
pub room_silent_type: String,
pub room_silent_level: i32,
pub room_silent_second: i64,
pub area_name: String,
pub hot_words: Vec<String>,
pub hot_words_status: i32,
pub new_pendants: RoomPendants,
pub pk_status: i32,
pub pk_id: i64,
pub allow_change_area_time: i64,
pub allow_upload_cover_time: i64,
pub studio_info: Option<RoomStudioInfo>,
}
impl BpiClient {
pub async fn live_room_info(
&self,
room_id: i64
) -> Result<BpiResponse<RoomInfoData>, BpiError> {
let params = [("room_id", room_id.to_string())];
let resp = self
.get("https://api.live.bilibili.com/room/v1/Room/get_info")
.query(¶ms)
.send_bpi("获取直播间信息").await?;
Ok(resp)
}
}
#[cfg(test)]
mod tests {
use super::*;
#[tokio::test]
async fn test_get_room_info() -> Result<(), Box<BpiError>> {
let bpi = BpiClient::new();
let result = bpi.live_room_info(23174842).await?;
let data = result.data.unwrap();
assert_eq!(data.room_id, 23174842);
Ok(())
}
}