bpi_rs/live/
live_replay.rs1use serde::{ Deserialize, Serialize };
2
3use crate::{ BilibiliRequest, BpiClient, BpiError, BpiResponse };
4
5#[derive(Debug, Serialize, Clone, Deserialize)]
6pub struct LiveInfo {
7 pub title: String,
9 pub cover: String,
11 pub live_time: i64,
13 pub live_type: i32,
15}
16
17#[derive(Debug, Serialize, Clone, Deserialize)]
18pub struct VideoInfo {
19 pub replay_status: i32,
21 pub estimated_time: String,
23 pub duration: i32,
25 pub download_url: Option<String>,
27 pub alert_code: Option<i32>,
29 pub alert_message: Option<String>,
31}
32
33#[derive(Debug, Serialize, Clone, Deserialize)]
34pub struct AlarmInfo {
35 pub code: i32,
37 pub message: String,
39 pub cur_time: i64,
41 pub is_ban_publish: bool,
43}
44
45#[derive(Debug, Serialize, Clone, Deserialize)]
46pub struct ReplayInfo {
47 pub replay_id: i64,
49 pub live_info: LiveInfo,
51 pub video_info: VideoInfo,
53 pub alarm_info: AlarmInfo,
55 pub room_id: i64,
57 pub live_key: String,
59 pub start_time: i64,
61 pub end_time: i64,
63}
64
65#[derive(Debug, Serialize, Clone, Deserialize)]
66pub struct Pagination {
67 pub page: i32,
69 pub page_size: i32,
71 pub total: Option<i32>,
73}
74
75#[derive(Debug, Serialize, Clone, Deserialize)]
76pub struct ReplayListData {
77 pub replay_info: Option<Vec<ReplayInfo>>,
79 pub pagination: Pagination,
81}
82
83impl BpiClient {
84 pub async fn live_replay_list(
90 &self,
91 page: Option<i32>,
92 page_size: Option<i32>
93 ) -> Result<BpiResponse<ReplayListData>, BpiError> {
94 let mut query = Vec::new();
95
96 if let Some(page) = page {
97 query.push(("page", page.to_string()));
98 }
99
100 if let Some(page_size) = page_size {
101 query.push(("page_size", page_size.to_string()));
102 }
103
104 self
105 .get("https://api.live.bilibili.com/xlive/app-blink/v1/anchorVideo/AnchorGetReplayList")
106 .query(&query)
107 .send_bpi("获取直播回放列表").await
108 }
109}
110
111#[cfg(test)]
112mod tests {
113 use super::*;
114
115 #[tokio::test]
116 async fn test_get_live_replay_list() {
117 let bpi = BpiClient::new();
118 let resp = bpi.live_replay_list(Some(1), Some(2)).await.unwrap();
119 tracing::info!("{:?}", resp);
120 }
121}