Skip to main content

bpi_rs/live/
live_replay.rs

1use serde::{ Deserialize, Serialize };
2
3use crate::{ BilibiliRequest, BpiClient, BpiError, BpiResponse };
4
5#[derive(Debug, Serialize, Clone, Deserialize)]
6pub struct LiveInfo {
7    /// 直播标题
8    pub title: String,
9    /// 直播封面
10    pub cover: String,
11    /// 直播时间
12    pub live_time: i64,
13    /// 直播类型
14    pub live_type: i32,
15}
16
17#[derive(Debug, Serialize, Clone, Deserialize)]
18pub struct VideoInfo {
19    /// 回放状态
20    pub replay_status: i32,
21    /// 直播回放合成结束时间
22    pub estimated_time: String,
23    /// 直播时长(秒)
24    pub duration: i32,
25    /// 下载链接片段
26    pub download_url: Option<String>,
27    /// 快速检查警告代码
28    pub alert_code: Option<i32>,
29    /// 快速检查警告信息
30    pub alert_message: Option<String>,
31}
32
33#[derive(Debug, Serialize, Clone, Deserialize)]
34pub struct AlarmInfo {
35    /// 回放合成警报代码
36    pub code: i32,
37    /// 回放合成错误信息
38    pub message: String,
39    /// 当前时间戳
40    pub cur_time: i64,
41    /// 是否禁止发布
42    pub is_ban_publish: bool,
43}
44
45#[derive(Debug, Serialize, Clone, Deserialize)]
46pub struct ReplayInfo {
47    /// 直播回放id
48    pub replay_id: i64,
49    /// 直播信息
50    pub live_info: LiveInfo,
51    /// 回放视频信息
52    pub video_info: VideoInfo,
53    /// 警报信息
54    pub alarm_info: AlarmInfo,
55    /// 直播间id
56    pub room_id: i64,
57    /// 标记直播场次的key
58    pub live_key: String,
59    /// 直播开始秒时间戳
60    pub start_time: i64,
61    /// 直播结束秒时间戳
62    pub end_time: i64,
63}
64
65#[derive(Debug, Serialize, Clone, Deserialize)]
66pub struct Pagination {
67    /// 请求的页码
68    pub page: i32,
69    /// 内容数量
70    pub page_size: i32,
71    /// 总计内容数量
72    pub total: Option<i32>,
73}
74
75#[derive(Debug, Serialize, Clone, Deserialize)]
76pub struct ReplayListData {
77    /// 回放信息列表
78    pub replay_info: Option<Vec<ReplayInfo>>,
79    /// 分页信息
80    pub pagination: Pagination,
81}
82
83impl BpiClient {
84    /// 获取直播回放列表
85    ///
86
87    /// # 文档
88    /// [查看API文档](https://github.com/SocialSisterYi/bilibili-API-collect/tree/master/docs/live)
89    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}