feat: 修改通知器,支持提示成功任务数量 (#672)
This commit is contained in:
@@ -17,6 +17,7 @@ use crate::bilibili::{BestStream, BiliClient, BiliError, Dimension, PageInfo, Vi
|
||||
use crate::config::{ARGS, Config, PathSafeTemplate};
|
||||
use crate::downloader::Downloader;
|
||||
use crate::error::ExecutionStatus;
|
||||
use crate::notifier::DownloadNotifyInfo;
|
||||
use crate::utils::download_context::DownloadContext;
|
||||
use crate::utils::format_arg::{page_format_args, video_format_args};
|
||||
use crate::utils::model::{
|
||||
@@ -24,6 +25,7 @@ use crate::utils::model::{
|
||||
update_videos_model,
|
||||
};
|
||||
use crate::utils::nfo::{NFO, ToNFO};
|
||||
use crate::utils::notify::notify;
|
||||
use crate::utils::rule::FieldEvaluatable;
|
||||
use crate::utils::status::{PageStatus, STATUS_OK, VideoStatus};
|
||||
|
||||
@@ -49,7 +51,11 @@ pub async fn process_video_source(
|
||||
warn!("已开启仅扫描模式,跳过视频下载..");
|
||||
} else {
|
||||
// 从数据库中查找所有未下载的视频与分页,下载并处理
|
||||
download_unprocessed_videos(bili_client, &video_source, connection, template, config).await?;
|
||||
let download_notify_info =
|
||||
download_unprocessed_videos(bili_client, &video_source, connection, template, config).await?;
|
||||
if download_notify_info.should_notify() {
|
||||
notify(config, bili_client, download_notify_info);
|
||||
}
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
@@ -176,7 +182,7 @@ pub async fn download_unprocessed_videos(
|
||||
connection: &DatabaseConnection,
|
||||
template: &handlebars::Handlebars<'_>,
|
||||
config: &Config,
|
||||
) -> Result<()> {
|
||||
) -> Result<DownloadNotifyInfo> {
|
||||
video_source.log_download_video_start();
|
||||
let semaphore = Semaphore::new(config.concurrent_limit.video);
|
||||
let downloader = Downloader::new(bili_client.client.clone());
|
||||
@@ -207,14 +213,16 @@ pub async fn download_unprocessed_videos(
|
||||
.filter_map(|res| futures::future::ready(res.ok()))
|
||||
// 将成功返回的 Model 按十个一组合并
|
||||
.chunks(10);
|
||||
let mut download_notify_info = DownloadNotifyInfo::new(video_source.display_name().into());
|
||||
while let Some(models) = stream.next().await {
|
||||
download_notify_info.record(&models);
|
||||
update_videos_model(models, connection).await?;
|
||||
}
|
||||
if let Some(e) = risk_control_related_error {
|
||||
bail!(e);
|
||||
}
|
||||
video_source.log_download_video_end();
|
||||
Ok(())
|
||||
Ok(download_notify_info)
|
||||
}
|
||||
|
||||
pub async fn download_video_pages(
|
||||
|
||||
Reference in New Issue
Block a user