diff --git a/src/core/command.rs b/src/core/command.rs index c135265..3e5d608 100644 --- a/src/core/command.rs +++ b/src/core/command.rs @@ -1,4 +1,5 @@ use std::collections::HashMap; +use std::env::{args, var}; use std::path::{Path, PathBuf}; use std::pin::Pin; @@ -7,6 +8,7 @@ use entity::{favorite, page, video}; use filenamify::filenamify; use futures::stream::{FuturesOrdered, FuturesUnordered}; use futures::{pin_mut, Future, StreamExt}; +use once_cell::sync::Lazy; use sea_orm::entity::prelude::*; use sea_orm::ActiveValue::Set; use sea_orm::TransactionTrait; @@ -26,6 +28,8 @@ use crate::core::utils::{ use crate::downloader::Downloader; use crate::error::{DownloadAbortError, ProcessPageError}; +pub static SCAN_ONLY: Lazy = Lazy::new(|| var("SCAN_ONLY").is_ok() || args().any(|arg| arg == "--scan-only")); + /// 处理某个收藏夹,首先刷新收藏夹信息,然后下载收藏夹中未下载成功的视频 pub async fn process_favorite_list( bili_client: &BiliClient, @@ -35,6 +39,10 @@ pub async fn process_favorite_list( ) -> Result<()> { let favorite_model = refresh_favorite_list(bili_client, fid, path, connection).await?; let favorite_model = fetch_video_details(bili_client, favorite_model, connection).await?; + if *SCAN_ONLY { + warn!("已开启仅扫描模式,跳过视频下载..."); + return Ok(()); + } download_unprocessed_videos(bili_client, favorite_model, connection).await } diff --git a/src/main.rs b/src/main.rs index a87bfcc..9bc73be 100644 --- a/src/main.rs +++ b/src/main.rs @@ -13,12 +13,13 @@ use once_cell::sync::Lazy; use self::bilibili::BiliClient; use self::config::CONFIG; -use self::core::command::process_favorite_list; +use self::core::command::{process_favorite_list, SCAN_ONLY}; use self::database::{database_connection, migrate_database}; #[tokio::main] async fn main() -> ! { env_logger::init_from_env(Env::default().default_filter_or("None,bili_sync=info")); + Lazy::force(&SCAN_ONLY); Lazy::force(&CONFIG); let mut anchor = chrono::Local::now().date_naive(); let bili_client = BiliClient::new();