bpi_rs/video/info/
desc.rs

1//! 查询稿件简介相关接口
2//!
3//! 文档: https://github.com/SocialSisterYi/bilibili-API-collect/tree/master/docs/video
4
5use crate::{ BilibiliRequest, BpiClient, BpiError, BpiResponse };
6use serde::{ Deserialize, Serialize };
7
8/// 稿件简介响应
9#[derive(Debug, Clone, Serialize, Deserialize)]
10pub struct VideoDescResponse {
11    /// 返回码
12    /// - 0:成功
13    /// - -400:请求错误
14    /// - 62002:稿件不可见
15    pub code: i32,
16    /// 错误信息,默认为 "0"
17    pub message: String,
18    /// ttl,一般为1
19    pub ttl: i32,
20    /// 简介内容
21    pub data: String,
22}
23
24impl BpiClient {
25    /// 查询稿件简介
26    ///
27    /// 文档: https://socialsisteryi.github.io/bilibili-API-collect/docs/video/info.html#获取稿件简介
28    ///
29    /// # 参数
30    /// | 名称   | 类型         | 说明                 |
31    /// | ------ | ------------| -------------------- |
32    /// | `aid`  | Option<u64> | 稿件 avid,可选      |
33    /// | `bvid` | Option<&str>| 稿件 bvid,可选      |
34    ///
35    /// 两者任选一个
36    pub async fn video_desc(
37        &self,
38        aid: Option<u64>,
39        bvid: Option<&str>
40    ) -> Result<BpiResponse<String>, BpiError> {
41        let mut builder = self.get("http://api.bilibili.com/x/web-interface/archive/desc");
42
43        if let Some(aid) = aid {
44            builder = builder.query(&[("aid", aid.to_string())]);
45        }
46        if let Some(bvid) = bvid {
47            builder = builder.query(&[("bvid", bvid)]);
48        }
49
50        builder.send_bpi("获取稿件简介").await
51    }
52}
53
54#[cfg(test)]
55mod tests {
56    use super::*;
57
58    #[tokio::test]
59    async fn test_video_desc() {
60        let bpi = BpiClient::new();
61
62        match bpi.video_desc(Some(10001), None).await {
63            Ok(resp) => {
64                if resp.code == 0 {
65                    tracing::info!("稿件简介: {}", resp.data.unwrap());
66                } else {
67                    tracing::info!("请求失败: code={}, message={}", resp.code, resp.message);
68                }
69            }
70            Err(err) => {
71                panic!("请求出错: {}", err);
72            }
73        }
74    }
75}