Skip to content

Commit

Permalink
chore: 隐藏 target 并调整表述,缩减日志长度
Browse files Browse the repository at this point in the history
  • Loading branch information
amtoaer committed Jan 24, 2025
1 parent 979294b commit 2a98359
Show file tree
Hide file tree
Showing 10 changed files with 107 additions and 156 deletions.
50 changes: 14 additions & 36 deletions crates/bili_sync/src/adapter/collection.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,59 +37,37 @@ impl VideoListModel for collection::Model {
})
}

fn log_fetch_video_start(&self) {
info!(
"开始获取{} {} - {} 的视频与分页信息...",
CollectionType::from(self.r#type),
self.s_id,
self.name
);
fn log_refresh_video_start(&self) {
info!("开始扫描{}「{}」..", CollectionType::from(self.r#type), self.name);
}

fn log_fetch_video_end(&self) {
fn log_refresh_video_end(&self, count: usize) {
info!(
"获取{} {} - {} 的视频与分页信息完成",
"扫描{}「{}」完成,获取到 {} 条新视频",
CollectionType::from(self.r#type),
self.s_id,
self.name
self.name,
count,
);
}

fn log_download_video_start(&self) {
fn log_fetch_video_start(&self) {
info!(
"开始下载{}: {} - {} 中所有未处理过的视频...",
"开始填充{}「{}」视频详情..",
CollectionType::from(self.r#type),
self.s_id,
self.name
);
}

fn log_download_video_end(&self) {
info!(
"下载{}: {} - {} 中未处理过的视频完成",
CollectionType::from(self.r#type),
self.s_id,
self.name
);
fn log_fetch_video_end(&self) {
info!("填充{}「{}」视频详情完成", CollectionType::from(self.r#type), self.name);
}

fn log_refresh_video_start(&self) {
info!(
"开始扫描{}: {} - {} 的新视频...",
CollectionType::from(self.r#type),
self.s_id,
self.name
);
fn log_download_video_start(&self) {
info!("开始下载{}「{}」视频..", CollectionType::from(self.r#type), self.name);
}

fn log_refresh_video_end(&self, count: usize) {
info!(
"扫描{}: {} - {} 的新视频完成,获取了 {} 条新视频",
CollectionType::from(self.r#type),
self.s_id,
self.name,
count,
);
fn log_download_video_end(&self) {
info!("下载{}「{}」视频完成", CollectionType::from(self.r#type), self.name);
}
}

Expand Down
27 changes: 12 additions & 15 deletions crates/bili_sync/src/adapter/favorite.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,31 +37,28 @@ impl VideoListModel for favorite::Model {
})
}

fn log_fetch_video_start(&self) {
info!("开始获取收藏夹 {} - {} 的视频与分页信息...", self.f_id, self.name);
fn log_refresh_video_start(&self) {
info!("开始扫描收藏夹「{}」..", self.name);
}

fn log_fetch_video_end(&self) {
info!("获取收藏夹 {} - {} 的视频与分页信息完成", self.f_id, self.name);
fn log_refresh_video_end(&self, count: usize) {
info!("扫描收藏夹「{}」完成,获取到 {} 条新视频", self.name, count);
}

fn log_download_video_start(&self) {
info!("开始下载收藏夹: {} - {} 中所有未处理过的视频...", self.f_id, self.name);
fn log_fetch_video_start(&self) {
info!("开始填充收藏夹「{}」视频详情..", self.name);
}

fn log_download_video_end(&self) {
info!("下载收藏夹: {} - {} 中未处理过的视频完成", self.f_id, self.name);
fn log_fetch_video_end(&self) {
info!("填充收藏夹「{}」视频详情完成", self.name);
}

fn log_refresh_video_start(&self) {
info!("开始扫描收藏夹: {} - {} 的新视频...", self.f_id, self.name);
fn log_download_video_start(&self) {
info!("开始下载收藏夹「{}」视频..", self.name);
}

fn log_refresh_video_end(&self, count: usize) {
info!(
"扫描收藏夹: {} - {} 的新视频完成,获取了 {} 条新视频",
self.f_id, self.name, count
);
fn log_download_video_end(&self) {
info!("下载收藏夹「{}」视频完成", self.name);
}
}

Expand Down
17 changes: 9 additions & 8 deletions crates/bili_sync/src/adapter/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -52,25 +52,26 @@ pub trait VideoListModel {
/// Box<dyn ActiveModelTrait> 又提示 ActiveModelTrait 没有 object safety,因此手写一个 Enum 静态分发
fn update_latest_row_at(&self, datetime: DateTime) -> _ActiveModel;

/// 开始获取视频
/// 开始刷新视频
fn log_refresh_video_start(&self);

/// 结束刷新视频
fn log_refresh_video_end(&self, count: usize);

/// 开始填充视频
fn log_fetch_video_start(&self);

/// 结束获取视频
/// 结束填充视频
fn log_fetch_video_end(&self);

/// 开始下载视频
fn log_download_video_start(&self);

/// 结束下载视频
fn log_download_video_end(&self);

/// 开始刷新视频
fn log_refresh_video_start(&self);

/// 结束刷新视频
fn log_refresh_video_end(&self, count: usize);
}

#[derive(Clone, Copy)]
pub enum Args<'a> {
Favorite { fid: &'a str },
Collection { collection_item: &'a CollectionItem },
Expand Down
39 changes: 12 additions & 27 deletions crates/bili_sync/src/adapter/submission.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,43 +37,28 @@ impl VideoListModel for submission::Model {
})
}

fn log_fetch_video_start(&self) {
info!(
"开始获取 UP 主 {} - {} 投稿的视频与分页信息...",
self.upper_id, self.upper_name
);
fn log_refresh_video_start(&self) {
info!("开始扫描「{}」投稿..", self.upper_name);
}

fn log_fetch_video_end(&self) {
info!(
"获取 UP 主 {} - {} 投稿的视频与分页信息完成",
self.upper_id, self.upper_name
);
fn log_refresh_video_end(&self, count: usize) {
info!("扫描「{}」投稿完成,获取到 {} 条新视频", self.upper_name, count,);
}

fn log_download_video_start(&self) {
info!(
"开始下载 UP 主 {} - {} 投稿的所有未处理过的视频...",
self.upper_id, self.upper_name
);
fn log_fetch_video_start(&self) {
info!("开始填充「{}」投稿视频详情..", self.upper_name);
}

fn log_download_video_end(&self) {
info!(
"下载 UP 主 {} - {} 投稿的所有未处理过的视频完成",
self.upper_id, self.upper_name
);
fn log_fetch_video_end(&self) {
info!("填充「{}」投稿视频详情完成", self.upper_name);
}

fn log_refresh_video_start(&self) {
info!("开始扫描 UP 主 {} - {} 投稿的新视频...", self.upper_id, self.upper_name);
fn log_download_video_start(&self) {
info!("开始下载「{}」投稿视频..", self.upper_name);
}

fn log_refresh_video_end(&self, count: usize) {
info!(
"扫描 UP 主 {} - {} 投稿的新视频完成,获取了 {} 条新视频",
self.upper_id, self.upper_name, count,
);
fn log_download_video_end(&self) {
info!("下载「{}」投稿视频完成", self.upper_name);
}
}

Expand Down
24 changes: 12 additions & 12 deletions crates/bili_sync/src/adapter/watch_later.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,28 +37,28 @@ impl VideoListModel for watch_later::Model {
})
}

fn log_fetch_video_start(&self) {
info!("开始获取稍后再看的视频与分页信息...");
fn log_refresh_video_start(&self) {
info!("开始扫描稍后再看..");
}

fn log_fetch_video_end(&self) {
info!("获取稍后再看的视频与分页信息完成");
fn log_refresh_video_end(&self, count: usize) {
info!("扫描稍后再看完成,获取到 {} 条新视频", count);
}

fn log_download_video_start(&self) {
info!("开始下载稍后再看中所有未处理过的视频...");
fn log_fetch_video_start(&self) {
info!("开始填充稍后再看视频详情..");
}

fn log_download_video_end(&self) {
info!("下载稍后再看中未处理过的视频完成");
fn log_fetch_video_end(&self) {
info!("填充稍后再看视频详情完成");
}

fn log_refresh_video_start(&self) {
info!("开始扫描稍后再看的新视频...");
fn log_download_video_start(&self) {
info!("开始下载稍后再看视频..");
}

fn log_refresh_video_end(&self, count: usize) {
info!("扫描稍后再看的新视频完成,获取了 {} 条新视频", count);
fn log_download_video_end(&self) {
info!("下载稍后再看视频完成");
}
}

Expand Down
4 changes: 2 additions & 2 deletions crates/bili_sync/src/bilibili/collection.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,8 @@ impl From<i32> for CollectionType {
impl Display for CollectionType {
fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
let s = match self {
CollectionType::Series => "视频列表",
CollectionType::Season => "视频合集",
CollectionType::Series => "列表",
CollectionType::Season => "合集",
};
write!(f, "{}", s)
}
Expand Down
5 changes: 2 additions & 3 deletions crates/bili_sync/src/config/global.rs
Original file line number Diff line number Diff line change
Expand Up @@ -53,10 +53,9 @@ fn load_config() -> Config {
info!("已将默认配置写入 {}", CONFIG_DIR.join("config.toml").display());
default_config
});
// 检查配置文件内容
info!("校验配置文件内容...");
info!("检查配置文件..");
config.check();
info!("配置文件内容校验通过");
info!("配置文件检查通过");
config
}

Expand Down
58 changes: 28 additions & 30 deletions crates/bili_sync/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ mod error;
mod utils;
mod workflow;

use std::path::PathBuf;

use once_cell::sync::Lazy;
use tokio::time;

Expand All @@ -28,17 +30,17 @@ async fn main() {
let connection = database_connection().await.expect("获取数据库连接失败");
let mut anchor = chrono::Local::now().date_naive();
let bili_client = BiliClient::new();
let watch_later_config = &CONFIG.watch_later;
let params = build_params();
loop {
'inner: {
match bili_client.wbi_img().await.map(|wbi_img| wbi_img.into()) {
Ok(Some(mixin_key)) => bilibili::set_global_mixin_key(mixin_key),
Ok(_) => {
error!("获取 mixin key 失败,无法进行 wbi 签名,等待下一轮执行");
error!("解析 mixin key 失败,等待下一轮执行");
break 'inner;
}
Err(e) => {
error!("获取 mixin key 时遇到错误:{e},等待下一轮执行");
error!("获取 mixin key 遇到错误:{e},等待下一轮执行");
break 'inner;
}
};
Expand All @@ -49,37 +51,33 @@ async fn main() {
}
anchor = chrono::Local::now().date_naive();
}
for (fid, path) in &CONFIG.favorite_list {
if let Err(e) = process_video_list(Args::Favorite { fid }, &bili_client, path, &connection).await {
error!("处理收藏夹 {fid} 时遇到非预期的错误:{e}");
}
}
info!("所有收藏夹处理完毕");
for (collection_item, path) in &CONFIG.collection_list {
if let Err(e) =
process_video_list(Args::Collection { collection_item }, &bili_client, path, &connection).await
{
error!("处理合集 {collection_item:?} 时遇到非预期的错误:{e}");
}
}
info!("所有合集处理完毕");
if watch_later_config.enabled {
if let Err(e) =
process_video_list(Args::WatchLater, &bili_client, &watch_later_config.path, &connection).await
{
error!("处理稍后再看时遇到非预期的错误:{e}");
for (args, path) in &params {
if let Err(e) = process_video_list(*args, &bili_client, path, &connection).await {
error!("处理过程遇到错误:{e}");
}
}
info!("稍后再看处理完毕");
for (upper_id, path) in &CONFIG.submission_list {
if let Err(e) = process_video_list(Args::Submission { upper_id }, &bili_client, path, &connection).await
{
error!("处理 UP 主 {upper_id} 投稿时遇到非预期的错误:{e}");
}
}
info!("所有 UP 主投稿处理完毕");
info!("本轮任务执行完毕,等待下一轮执行");
}
time::sleep(time::Duration::from_secs(CONFIG.interval)).await;
}
}

fn build_params() -> Vec<(Args<'static>, &'static PathBuf)> {
let mut params = Vec::new();
CONFIG
.favorite_list
.iter()
.for_each(|(fid, path)| params.push((Args::Favorite { fid }, path)));
CONFIG
.collection_list
.iter()
.for_each(|(collection_item, path)| params.push((Args::Collection { collection_item }, path)));
if CONFIG.watch_later.enabled {
params.push((Args::WatchLater, &CONFIG.watch_later.path));
}
CONFIG
.submission_list
.iter()
.for_each(|(upper_id, path)| params.push((Args::Submission { upper_id }, path)));
params
}
4 changes: 3 additions & 1 deletion crates/bili_sync/src/utils/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,11 @@ use tracing_subscriber::util::SubscriberInitExt;

pub fn init_logger(log_level: &str) {
tracing_subscriber::fmt::Subscriber::builder()
.compact()
.with_env_filter(tracing_subscriber::EnvFilter::builder().parse_lossy(log_level))
.with_target(false)
.with_timer(tracing_subscriber::fmt::time::ChronoLocal::new(
"%Y-%m-%d %H:%M:%S%.3f".to_owned(),
"%b %d %H:%M:%S".to_owned(),
))
.finish()
.try_init()
Expand Down
Loading

0 comments on commit 2a98359

Please sign in to comment.