mirror of
https://github.com/amtoaer/bili-sync.git
synced 2026-08-25 02:00:30 +08:00
feat: 支持设置时间格式化字符串,支持在 video_name 和 page_name 中使用 time (#152)
This commit is contained in:
@@ -78,6 +78,12 @@ pub struct Config {
|
|||||||
pub nfo_time_type: NFOTimeType,
|
pub nfo_time_type: NFOTimeType,
|
||||||
#[serde(default)]
|
#[serde(default)]
|
||||||
pub delay: DelayConfig,
|
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)]
|
#[derive(Serialize, Deserialize, Default)]
|
||||||
@@ -124,6 +130,7 @@ impl Default for Config {
|
|||||||
upper_path: CONFIG_DIR.join("upper_face"),
|
upper_path: CONFIG_DIR.join("upper_face"),
|
||||||
nfo_time_type: NFOTimeType::FavTime,
|
nfo_time_type: NFOTimeType::FavTime,
|
||||||
delay: Default::default(),
|
delay: Default::default(),
|
||||||
|
time_format: default_time_format(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -3,6 +3,7 @@ use sea_orm::{IntoActiveModel, Set};
|
|||||||
use serde_json::json;
|
use serde_json::json;
|
||||||
|
|
||||||
use crate::bilibili::VideoInfo;
|
use crate::bilibili::VideoInfo;
|
||||||
|
use crate::config::CONFIG;
|
||||||
use crate::utils::id_time_key;
|
use crate::utils::id_time_key;
|
||||||
|
|
||||||
impl VideoInfo {
|
impl VideoInfo {
|
||||||
@@ -124,24 +125,46 @@ impl VideoInfo {
|
|||||||
pub fn to_fmt_args(&self) -> Option<serde_json::Value> {
|
pub fn to_fmt_args(&self) -> Option<serde_json::Value> {
|
||||||
match self {
|
match self {
|
||||||
VideoInfo::Simple { .. } => None, // 不能从简单的视频信息中构造格式化参数
|
VideoInfo::Simple { .. } => None, // 不能从简单的视频信息中构造格式化参数
|
||||||
VideoInfo::Detail { title, bvid, upper, .. } => Some(json!({
|
VideoInfo::Detail {
|
||||||
"bvid": &bvid,
|
title,
|
||||||
"title": &title,
|
bvid,
|
||||||
"upper_name": &upper.name,
|
upper,
|
||||||
"upper_mid": &upper.mid,
|
pubtime,
|
||||||
})),
|
fav_time,
|
||||||
VideoInfo::View { title, bvid, upper, .. } => Some(json!({
|
..
|
||||||
"bvid": &bvid,
|
}
|
||||||
"title": &title,
|
| VideoInfo::WatchLater {
|
||||||
"upper_name": &upper.name,
|
title,
|
||||||
"upper_mid": &upper.mid,
|
bvid,
|
||||||
})),
|
upper,
|
||||||
VideoInfo::WatchLater { title, bvid, upper, .. } => Some(json!({
|
pubtime,
|
||||||
|
fav_time,
|
||||||
|
..
|
||||||
|
} => Some(json!({
|
||||||
"bvid": &bvid,
|
"bvid": &bvid,
|
||||||
"title": &title,
|
"title": &title,
|
||||||
"upper_name": &upper.name,
|
"upper_name": &upper.name,
|
||||||
"upper_mid": &upper.mid,
|
"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,
|
||||||
|
}))
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -324,6 +324,8 @@ pub async fn download_page(
|
|||||||
"upper_mid": &video_model.upper_id,
|
"upper_mid": &video_model.upper_id,
|
||||||
"ptitle": &page_model.name,
|
"ptitle": &page_model.name,
|
||||||
"pid": page_model.pid,
|
"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 {
|
let (poster_path, video_path, nfo_path, danmaku_path, fanart_path) = if is_single_page {
|
||||||
|
|||||||
Reference in New Issue
Block a user