bpi_rs/video/
report.rs

1//! 视频观看进度上报相关接口
2//!
3//! 文档: https://github.com/SocialSisterYi/bilibili-API-collect/tree/master/docs/video
4use crate::{BilibiliRequest, BpiClient, BpiError, BpiResponse};
5
6impl BpiClient {
7    /// 上报视频观看进度(双端)
8    ///
9    /// 文档: https://socialsisteryi.github.io/bilibili-API-collect/docs/video/report.html#上报视频观看进度
10    ///
11    /// # 参数
12    /// | 名称      | 类型         | 说明                 |
13    /// | --------- | ------------| -------------------- |
14    /// | `aid`     | u64         | 稿件 avid            |
15    /// | `cid`     | u64         | 视频 cid             |
16    /// | `progress`| Option<u64> | 观看进度,单位为秒,可选,默认0 |
17    pub async fn video_report_watch_progress(
18        &self,
19        aid: u64,
20        cid: u64,
21        progress: Option<u64>,
22    ) -> Result<BpiResponse<serde_json::Value>, BpiError> {
23        let csrf = self.csrf()?;
24
25        let mut form = reqwest::multipart::Form::new()
26            .text("aid", aid.to_string())
27            .text("cid", cid.to_string())
28            .text("csrf", csrf.to_string());
29
30        if let Some(p) = progress {
31            form = form.text("progress", p.to_string());
32        } else {
33            form = form.text("progress", "0");
34        }
35
36        self.post("https://api.bilibili.com/x/v2/history/report")
37            .multipart(form)
38            .send_bpi("上报观看进度")
39            .await
40    }
41}
42
43// --- 测试模块 ---
44
45#[cfg(test)]
46mod tests {
47    use super::*;
48    use tracing::info;
49
50    const TEST_AID: u64 = 10001;
51    const TEST_CID: u64 = 16546;
52
53    #[tokio::test]
54
55    async fn test_report_watch_progress() -> Result<(), BpiError> {
56        let bpi = BpiClient::new();
57        // 上报观看进度为 1248 秒
58        let resp = bpi
59            .video_report_watch_progress(TEST_AID, TEST_CID, Some(120))
60            .await?;
61
62        info!("上报观看进度结果: {:?}", resp);
63
64        Ok(())
65    }
66}