-
Notifications
You must be signed in to change notification settings - Fork 1
/
like.rs
40 lines (36 loc) · 1.08 KB
/
like.rs
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
use crate::config::config;
use reqwest::header::COOKIE;
use tracing::{info, warn};
const LIKE_API: &str = "https://api.bilibili.com/x/web-interface/archive/like";
pub(crate) async fn like(bvid: String) {
let cookie = &config().cookie;
let url = reqwest::Url::parse_with_params(
LIKE_API,
[
("bvid", bvid.as_str()),
("like", "1"),
("csrf", cookie.bili_jct.as_str()),
],
)
.unwrap();
let resp = reqwest::Client::new()
.post(url)
.header(
COOKIE,
format!("SESSDATA={}; buvid3={}", cookie.SESSDATA, cookie.buvid3),
)
.send()
.await
.unwrap();
let json: serde_json::Value = resp.json().await.unwrap();
match json.pointer("/code").unwrap().as_i64().unwrap() {
0 => info!("Liked bvid:{}", bvid),
65006 => info!("Already liked bvid:{}", bvid),
_ => warn!(
"Failed to like bvid:{}; Error Message, {}",
bvid,
json.pointer("/message").unwrap()
),
}
}
pub(crate) async fn like_all() {}