diff --git a/src/download.rs b/src/download.rs index f774a92..e2ce1e4 100644 --- a/src/download.rs +++ b/src/download.rs @@ -237,7 +237,7 @@ pub async fn download_artwork( "Failed to get pages' data.", ))); } - let base = Arc::new(PathBuf::from(".")); + let base = Arc::new(PathBuf::from(helper.download_base())); let json_file = base.join(format!("{}.json", id)); let mut datas = PixivData::new(id).unwrap(); if ajax_ver { diff --git a/src/opthelper.rs b/src/opthelper.rs index 6064a9c..9502b33 100644 --- a/src/opthelper.rs +++ b/src/opthelper.rs @@ -85,6 +85,23 @@ impl OptHelper { } } + /// The base directory to save downloaded files + pub fn download_base(&self) -> String { + match self.opt.get_ref().download_base { + Some(ref r) => { + return r.clone(); + } + None => {} + } + match self.settings.get_ref().get_str("download-base") { + Some(r) => { + return r; + } + None => {} + } + String::from("./") + } + /// Whether to download multiple posts/artworks at the same time. pub fn download_multiple_posts(&self) -> bool { match self.opt.get_ref().download_multiple_posts { diff --git a/src/opts.rs b/src/opts.rs index bb2f232..59a1ec8 100644 --- a/src/opts.rs +++ b/src/opts.rs @@ -106,6 +106,8 @@ pub struct CommandOpts { #[cfg(feature = "ugoira")] /// The x264 profile when converting ugoira(GIF) to video. pub x264_profile: Option, + /// The base directory to save downloaded files. + pub download_base: Option, } impl CommandOpts { @@ -141,6 +143,7 @@ impl CommandOpts { force_yuv420p: None, #[cfg(feature = "ugoira")] x264_profile: None, + download_base: None, } } @@ -510,6 +513,12 @@ pub fn parse_cmd() -> Option { HasArg::Maybe, getopts::Occur::Optional, ); + opts.optopt( + "d", + "download-base", + gettext("The base directory to download files."), + "DIR", + ); let result = match opts.parse(&argv[1..]) { Ok(m) => m, Err(err) => { @@ -793,6 +802,7 @@ pub fn parse_cmd() -> Option { return None; } } + re.as_mut().unwrap().download_base = result.opt_str("download-base"); re } diff --git a/src/settings_list.rs b/src/settings_list.rs index f31b20f..fec5b4f 100644 --- a/src/settings_list.rs +++ b/src/settings_list.rs @@ -53,6 +53,7 @@ pub fn get_settings_list() -> Vec { SettingDes::new("x264-profile", gettext("The x264 profile when converting ugoira(GIF) to video."), JsonValueType::Str, Some(check_x264_profile)).unwrap(), #[cfg(feature = "db")] SettingDes::new("db", gettext("Database settings."), JsonValueType::Object, Some(check_db_config)).unwrap(), + SettingDes::new("download-base", gettext("The base directory to save downloaded files."), JsonValueType::Str, None).unwrap(), ] }