bpi_rs/video/info/
pagelist.rs1use crate::{ BilibiliRequest, BpiClient, BpiError, BpiResponse };
8use serde::{ Deserialize, Serialize };
9
10#[derive(Debug, Clone, Serialize, Deserialize)]
12pub struct PageDimension {
13 pub width: u32,
15 pub height: u32,
17 pub rotate: u8,
19}
20
21#[derive(Debug, Clone, Serialize, Deserialize)]
23pub struct PageItem {
24 pub cid: u64,
26 pub page: u32,
28 pub from: String,
30 pub part: String,
32 pub duration: u32,
34 pub vid: String,
36 pub weblink: String,
38 pub dimension: Option<PageDimension>,
40 pub first_frame: Option<String>,
42
43 pub ctime: u64,
44}
45
46type PageListResponse = BpiResponse<Vec<PageItem>>;
48impl BpiClient {
49 pub async fn video_pagelist(
61 &self,
62 aid: Option<u64>,
63 bvid: Option<&str>
64 ) -> Result<PageListResponse, BpiError> {
65 let aid = aid.map(|v| v.to_string());
66 let bvid = bvid.map(|v| v.to_string());
67 self
68 .get("https://api.bilibili.com/x/player/pagelist")
69 .query(
70 &[
71 ("aid", aid),
72 ("bvid", bvid),
73 ]
74 )
75 .send_bpi("查询视频分P列表").await
76 }
77}
78
79#[cfg(test)]
80mod tests {
81 use super::*;
82
83 #[tokio::test]
84 async fn test_video_pagelist() {
85 let bpi = BpiClient::new();
86
87 match bpi.video_pagelist(Some(10001), None).await {
88 Ok(resp) => {
89 if resp.code == 0 {
90 for item in resp.data.unwrap() {
91 tracing::info!(
92 "P{}: {}, cid={}, duration={}秒",
93 item.page,
94 item.part,
95 item.cid,
96 item.duration
97 );
98 if let Some(dim) = item.dimension {
99 tracing::info!(
100 "分辨率: {}x{}, rotate={}",
101 dim.width,
102 dim.height,
103 dim.rotate
104 );
105 }
106 }
107 } else {
108 tracing::info!("请求失败: code={}, message={}", resp.code, resp.message);
109 }
110 }
111 Err(err) => {
112 panic!("请求出错: {}", err);
113 }
114 }
115 }
116}