feat: 加入充电视频和番剧、影视判断,同时修复 category 被错误覆盖的问题 (#494)

This commit is contained in:
ᴀᴍᴛᴏᴀᴇʀ
2025-10-12 03:01:04 +08:00
committed by GitHub
parent 02c42861ab
commit eb2606f120
2 changed files with 67 additions and 2 deletions

View File

@@ -78,6 +78,9 @@ pub enum VideoInfo {
ctime: DateTime<Utc>,
#[serde(rename = "pubdate", with = "ts_seconds")]
pubtime: DateTime<Utc>,
is_upower_exclusive: bool,
is_upower_play: bool,
redirect_url: Option<String>,
pages: Vec<PageInfo>,
state: i32,
},
@@ -250,4 +253,58 @@ mod tests {
}
Ok(())
}
#[ignore = "only for manual test"]
#[tokio::test]
async fn test_upower_parse() -> Result<()> {
VersionedConfig::init_for_test(&setup_database(Path::new("./test.sqlite")).await?).await?;
let bili_client = BiliClient::new();
let Ok(Some(mixin_key)) = bili_client.wbi_img().await.map(|wbi_img| wbi_img.into()) else {
panic!("获取 mixin key 失败");
};
set_global_mixin_key(mixin_key);
for (bvid, (upower_exclusive, upower_play)) in [
("BV1HxXwYEEqt", (true, false)), // 充电专享且无权观看
("BV16w41187fx", (true, true)), // 充电专享但有权观看
("BV1n34jzPEYq", (false, false)), // 普通视频
] {
let video = Video::new(&bili_client, bvid.to_string());
let info = video.get_view_info().await?;
let VideoInfo::Detail {
is_upower_exclusive,
is_upower_play,
..
} = info
else {
unreachable!();
};
assert_eq!(is_upower_exclusive, upower_exclusive, "bvid: {}", bvid);
assert_eq!(is_upower_play, upower_play, "bvid: {}", bvid);
}
Ok(())
}
#[ignore = "only for manual test"]
#[tokio::test]
async fn test_ep_parse() -> Result<()> {
VersionedConfig::init_for_test(&setup_database(Path::new("./test.sqlite")).await?).await?;
let bili_client = BiliClient::new();
let Ok(Some(mixin_key)) = bili_client.wbi_img().await.map(|wbi_img| wbi_img.into()) else {
panic!("获取 mixin key 失败");
};
set_global_mixin_key(mixin_key);
for (bvid, redirect_is_none) in [
("BV1SF411g796", false), // EP
("BV13xtnzPEye", false), // 番剧
("BV1kT4NzTEZj", true), // 普通视频
] {
let video = Video::new(&bili_client, bvid.to_string());
let info = video.get_view_info().await?;
let VideoInfo::Detail { redirect_url, .. } = info else {
unreachable!();
};
assert_eq!(redirect_url.is_none(), redirect_is_none, "bvid: {}", bvid);
}
Ok(())
}
}

View File

@@ -130,11 +130,13 @@ impl VideoInfo {
ctime,
pubtime,
state,
is_upower_exclusive,
is_upower_play,
redirect_url,
..
} => bili_sync_entity::video::ActiveModel {
bvid: Set(bvid),
name: Set(title),
category: Set(2),
intro: Set(intro),
cover: Set(cover),
ctime: Set(ctime.naive_utc()),
@@ -145,7 +147,13 @@ impl VideoInfo {
Set(pubtime.naive_utc()) // 未设置过 favtime使用 pubtime 填充
},
download_status: Set(0),
valid: Set(state == 0),
// state == 0 表示开放浏览
// is_upower_exclusive 和 is_upower_play 相等有两种情况:
// 1. 都为 true表示视频是充电专享但是已经充过电有权观看
// 2. 都为 false表示视频是非充电视频
// redirect_url 仅在视频为番剧、影视、纪录片等特殊视频时才会有值,如果为空说明是普通视频
// 仅在三种条件都满足时,才认为视频是可下载的
valid: Set(state == 0 && (is_upower_exclusive == is_upower_play) && redirect_url.is_none()),
upper_id: Set(upper.mid),
upper_name: Set(upper.name),
upper_face: Set(upper.face),