1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
use chrono::{DateTime, Utc};
use serde_with::{serde_as, DurationSeconds};
use std::time::Duration;
use super::prelude::*;
#[serde_as]
#[derive(Debug, Deserialize, Serialize, Clone)]
pub struct VideoInfo {
pub bvid: String,
pub aid: u64,
pub videos: usize,
pub title: String,
#[serde(rename = "pubdate", with = "chrono::serde::ts_seconds")]
pub publish_at: DateTime<Utc>,
#[serde(rename = "ctime", with = "chrono::serde::ts_seconds")]
pub create_at: DateTime<Utc>,
pub desc: String,
#[serde_as(as = "DurationSeconds<u64>")]
pub duration: Duration,
#[serde(rename = "pic")]
pub cover_url: String,
pub stat: VideoStat,
}
#[derive(Debug, Deserialize, Serialize, Clone)]
pub struct VideoStat {
pub aid: u64,
pub view: u64,
pub danmaku: u64,
pub reply: u64,
pub favorite: u64,
pub coin: u64,
pub share: u64,
pub now_rank: u64,
#[serde(rename = "his_rank")]
pub history_rank: u64,
pub like: u64,
pub dislike: u64,
pub argue_msg: String,
}
impl Request for VideoInfo {
type Args = String;
fn request(client: &Client, args: Self::Args) -> RequestResponse<Self> {
const URL: &str = "https://api.bilibili.com/x/web-interface/view";
let request = client.get(URL).query(&[("bvid", &args)]).send();
Box::pin(async move { request.await?.bili_data().await })
}
}
#[tokio::test]
async fn test_video_info() -> Result<()> {
let client = crate::connection::new_client()?;
let info = VideoInfo::request(&client, "BV1QB4y1u7Jj".to_string()).await?;
assert_eq!(info.aid, 588385189);
assert!(info.stat.like > 4100);
assert!(info.title.contains("亲爱的那不是爱情"));
Ok(())
}