mirror of
https://github.com/lifegpc/pixiv_downloader.git
synced 2026-07-08 01:32:41 +08:00
Allow to specify base download directory ( Fix #323
This commit is contained in:
@@ -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 {
|
||||
|
||||
@@ -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 {
|
||||
|
||||
10
src/opts.rs
10
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<X264Profile>,
|
||||
/// The base directory to save downloaded files.
|
||||
pub download_base: Option<String>,
|
||||
}
|
||||
|
||||
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<CommandOpts> {
|
||||
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<CommandOpts> {
|
||||
return None;
|
||||
}
|
||||
}
|
||||
re.as_mut().unwrap().download_base = result.opt_str("download-base");
|
||||
re
|
||||
}
|
||||
|
||||
|
||||
@@ -53,6 +53,7 @@ pub fn get_settings_list() -> Vec<SettingDes> {
|
||||
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(),
|
||||
]
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user