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(
89 &self,
90 page: Option<i32>,
91 page_size: Option<i32>,
92 ) -> Result<BpiResponse<ReplayListData>, BpiError> {
93 let mut query = Vec::new();
94
95 if let Some(page) = page {
96 query.push(("page", page.to_string()));
97 }
98
99 if let Some(page_size) = page_size {
100 query.push(("page_size", page_size.to_string()));
101 }
102
103 self.get("https://api.live.bilibili.com/xlive/app-blink/v1/anchorVideo/AnchorGetReplayList")
104 .query(&query)
105 .send_bpi("获取直播回放列表")
106 .await
107 }
108}
109
110#[cfg(test)]
111mod tests {
112 use super::*;
113
114 #[tokio::test]
115 async fn test_get_live_replay_list() {
116 let bpi = BpiClient::new();
117 let resp = bpi.live_replay_list(Some(1), Some(2)).await.unwrap();
118 tracing::info!("{:?}", resp);
119 }
120}