From 75de39dfbbec851f7d46334c1cde8656b8cbedd9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E1=B4=80=E1=B4=8D=E1=B4=9B=E1=B4=8F=E1=B4=80=E1=B4=87?= =?UTF-8?q?=CA=80?= Date: Wed, 24 Jul 2024 21:06:40 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E6=94=AF=E6=8C=81=E8=AE=BE=E7=BD=AE?= =?UTF-8?q?=E6=97=B6=E9=97=B4=E6=A0=BC=E5=BC=8F=E5=8C=96=E5=AD=97=E7=AC=A6?= =?UTF-8?q?=E4=B8=B2=EF=BC=8C=E6=94=AF=E6=8C=81=E5=9C=A8=20video=5Fname=20?= =?UTF-8?q?=E5=92=8C=20page=5Fname=20=E4=B8=AD=E4=BD=BF=E7=94=A8=20time=20?= =?UTF-8?q?(#152)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- crates/bili_sync/src/config.rs | 7 ++++ crates/bili_sync/src/utils/convert.rs | 49 ++++++++++++++++++++------- crates/bili_sync/src/workflow.rs | 2 ++ 3 files changed, 45 insertions(+), 13 deletions(-) diff --git a/crates/bili_sync/src/config.rs b/crates/bili_sync/src/config.rs index a893304..9529a88 100644 --- a/crates/bili_sync/src/config.rs +++ b/crates/bili_sync/src/config.rs @@ -78,6 +78,12 @@ pub struct Config { pub nfo_time_type: NFOTimeType, #[serde(default)] pub delay: DelayConfig, + #[serde(default = "default_time_format")] + pub time_format: String, +} + +fn default_time_format() -> String { + "%Y-%m-%d".to_string() } #[derive(Serialize, Deserialize, Default)] @@ -124,6 +130,7 @@ impl Default for Config { upper_path: CONFIG_DIR.join("upper_face"), nfo_time_type: NFOTimeType::FavTime, delay: Default::default(), + time_format: default_time_format(), } } } diff --git a/crates/bili_sync/src/utils/convert.rs b/crates/bili_sync/src/utils/convert.rs index 99a0191..5dd5620 100644 --- a/crates/bili_sync/src/utils/convert.rs +++ b/crates/bili_sync/src/utils/convert.rs @@ -3,6 +3,7 @@ use sea_orm::{IntoActiveModel, Set}; use serde_json::json; use crate::bilibili::VideoInfo; +use crate::config::CONFIG; use crate::utils::id_time_key; impl VideoInfo { @@ -124,24 +125,46 @@ impl VideoInfo { pub fn to_fmt_args(&self) -> Option { match self { VideoInfo::Simple { .. } => None, // 不能从简单的视频信息中构造格式化参数 - VideoInfo::Detail { title, bvid, upper, .. } => Some(json!({ - "bvid": &bvid, - "title": &title, - "upper_name": &upper.name, - "upper_mid": &upper.mid, - })), - VideoInfo::View { title, bvid, upper, .. } => Some(json!({ - "bvid": &bvid, - "title": &title, - "upper_name": &upper.name, - "upper_mid": &upper.mid, - })), - VideoInfo::WatchLater { title, bvid, upper, .. } => Some(json!({ + VideoInfo::Detail { + title, + bvid, + upper, + pubtime, + fav_time, + .. + } + | VideoInfo::WatchLater { + title, + bvid, + upper, + pubtime, + fav_time, + .. + } => Some(json!({ "bvid": &bvid, "title": &title, "upper_name": &upper.name, "upper_mid": &upper.mid, + "pubtime": pubtime.format(&CONFIG.time_format).to_string(), + "fav_time": fav_time.format(&CONFIG.time_format).to_string(), })), + VideoInfo::View { + title, + bvid, + upper, + pubtime, + .. + } => { + let pubtime = pubtime.format(&CONFIG.time_format).to_string(); + Some(json!({ + "bvid": &bvid, + "title": &title, + "upper_name": &upper.name, + "upper_mid": &upper.mid, + "pubtime": &pubtime, + "fav_time": &pubtime, + })) + } } } diff --git a/crates/bili_sync/src/workflow.rs b/crates/bili_sync/src/workflow.rs index cf9e970..15552fc 100644 --- a/crates/bili_sync/src/workflow.rs +++ b/crates/bili_sync/src/workflow.rs @@ -324,6 +324,8 @@ pub async fn download_page( "upper_mid": &video_model.upper_id, "ptitle": &page_model.name, "pid": page_model.pid, + "pubtime": video_model.pubtime.format(&CONFIG.time_format).to_string(), + "fav_time": video_model.favtime.format(&CONFIG.time_format).to_string(), }), )?); let (poster_path, video_path, nfo_path, danmaku_path, fanart_path) = if is_single_page {