feat: 引入更健壮的新视频检测方法 (#228)
* feat: 为各个 video list 表添加 latest_row_at 字段 * chore: 为 model 引入新增的字段 * feat: 实现新版中断条件(待测试) * test: 更新测试
This commit is contained in:
@@ -1,10 +1,10 @@
|
||||
use chrono::{DateTime, Utc};
|
||||
use sea_orm::ActiveValue::{NotSet, Set};
|
||||
use sea_orm::IntoActiveModel;
|
||||
use serde_json::json;
|
||||
|
||||
use crate::bilibili::VideoInfo;
|
||||
use crate::config::CONFIG;
|
||||
use crate::utils::id_time_key;
|
||||
|
||||
impl VideoInfo {
|
||||
/// 将 VideoInfo 转换为 ActiveModel
|
||||
@@ -20,7 +20,7 @@ impl VideoInfo {
|
||||
}
|
||||
};
|
||||
match self {
|
||||
VideoInfo::Simple {
|
||||
VideoInfo::Collection {
|
||||
bvid,
|
||||
cover,
|
||||
ctime,
|
||||
@@ -34,7 +34,7 @@ impl VideoInfo {
|
||||
valid: Set(true),
|
||||
..base_model
|
||||
},
|
||||
VideoInfo::Detail {
|
||||
VideoInfo::Favorite {
|
||||
title,
|
||||
vtype,
|
||||
bvid,
|
||||
@@ -63,7 +63,7 @@ impl VideoInfo {
|
||||
upper_face: Set(upper.face.clone()),
|
||||
..base_model
|
||||
},
|
||||
VideoInfo::View {
|
||||
VideoInfo::Detail {
|
||||
title,
|
||||
bvid,
|
||||
intro,
|
||||
@@ -140,8 +140,8 @@ impl VideoInfo {
|
||||
|
||||
pub fn to_fmt_args(&self) -> Option<serde_json::Value> {
|
||||
match self {
|
||||
VideoInfo::Simple { .. } | VideoInfo::Submission { .. } => None, // 不能从简单视频信息中构造格式化参数
|
||||
VideoInfo::Detail {
|
||||
VideoInfo::Collection { .. } | VideoInfo::Submission { .. } => None, // 不能从简单视频信息中构造格式化参数
|
||||
VideoInfo::Favorite {
|
||||
title,
|
||||
bvid,
|
||||
upper,
|
||||
@@ -164,7 +164,7 @@ impl VideoInfo {
|
||||
"pubtime": pubtime.format(&CONFIG.time_format).to_string(),
|
||||
"fav_time": fav_time.format(&CONFIG.time_format).to_string(),
|
||||
})),
|
||||
VideoInfo::View {
|
||||
VideoInfo::Detail {
|
||||
title,
|
||||
bvid,
|
||||
upper,
|
||||
@@ -184,31 +184,12 @@ impl VideoInfo {
|
||||
}
|
||||
}
|
||||
|
||||
pub fn video_key(&self) -> String {
|
||||
pub fn release_datetime(&self) -> &DateTime<Utc> {
|
||||
match self {
|
||||
// 对于合集没有 fav_time,只能用 pubtime 代替
|
||||
VideoInfo::Simple {
|
||||
bvid, pubtime: time, ..
|
||||
}
|
||||
| VideoInfo::Detail {
|
||||
bvid, fav_time: time, ..
|
||||
}
|
||||
| VideoInfo::WatchLater {
|
||||
bvid, fav_time: time, ..
|
||||
}
|
||||
| VideoInfo::Submission { bvid, ctime: time, .. } => id_time_key(bvid, time),
|
||||
// 详情接口返回的数据仅用于填充详情,不会被作为 video_key
|
||||
_ => unreachable!(),
|
||||
}
|
||||
}
|
||||
|
||||
pub fn bvid(&self) -> &str {
|
||||
match self {
|
||||
VideoInfo::Simple { bvid, .. }
|
||||
| VideoInfo::Detail { bvid, .. }
|
||||
| VideoInfo::WatchLater { bvid, .. }
|
||||
| VideoInfo::Submission { bvid, .. } => bvid,
|
||||
// 同上
|
||||
VideoInfo::Collection { pubtime: time, .. }
|
||||
| VideoInfo::Favorite { fav_time: time, .. }
|
||||
| VideoInfo::WatchLater { fav_time: time, .. }
|
||||
| VideoInfo::Submission { ctime: time, .. } => time,
|
||||
_ => unreachable!(),
|
||||
}
|
||||
}
|
||||
|
||||
@@ -4,7 +4,6 @@ pub mod model;
|
||||
pub mod nfo;
|
||||
pub mod status;
|
||||
|
||||
use chrono::{DateTime, Utc};
|
||||
use tracing_subscriber::util::SubscriberInitExt;
|
||||
|
||||
pub fn init_logger(log_level: &str) {
|
||||
@@ -17,8 +16,3 @@ pub fn init_logger(log_level: &str) {
|
||||
.try_init()
|
||||
.expect("初始化日志失败");
|
||||
}
|
||||
|
||||
/// 生成视频的唯一标记,均由 bvid 和时间戳构成
|
||||
pub fn id_time_key(bvid: &String, time: &DateTime<Utc>) -> String {
|
||||
format!("{}-{}", bvid, time.timestamp())
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user