mirror of
https://github.com/lifegpc/pixiv_downloader.git
synced 2026-06-22 20:04:19 +08:00
add new option update-exif
This commit is contained in:
@@ -110,6 +110,15 @@ impl Main {
|
||||
if !overwrite {
|
||||
#[cfg(feature = "exif")]
|
||||
{
|
||||
if pw.helper.update_exif() {
|
||||
if add_exifdata_to_image(&file_name, &datas, np).is_err() {
|
||||
println!(
|
||||
"{} {}",
|
||||
gettext("Failed to add exif data to image:"),
|
||||
file_name.to_str().unwrap_or("(null)")
|
||||
);
|
||||
}
|
||||
}
|
||||
np += 1;
|
||||
}
|
||||
continue;
|
||||
@@ -179,6 +188,15 @@ impl Main {
|
||||
}
|
||||
};
|
||||
if !overwrite {
|
||||
if pw.helper.update_exif() {
|
||||
if add_exifdata_to_image(&file_name, &datas, 0).is_err() {
|
||||
println!(
|
||||
"{} {}",
|
||||
gettext("Failed to add exif data to image:"),
|
||||
file_name.to_str().unwrap_or("(null)")
|
||||
);
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -104,4 +104,16 @@ impl<'a> OptHelper<'a> {
|
||||
}
|
||||
false
|
||||
}
|
||||
|
||||
/// Return whether to add/update exif information to image files even
|
||||
/// when overwrite are disabled.
|
||||
pub fn update_exif(&self) -> bool {
|
||||
if self.opt.update_exif {
|
||||
return true;
|
||||
}
|
||||
if self.settings.have_bool("update-exif") {
|
||||
return self.settings.get_bool("update-exif").unwrap();
|
||||
}
|
||||
false
|
||||
}
|
||||
}
|
||||
|
||||
@@ -59,6 +59,8 @@ pub struct CommandOpts {
|
||||
pub retry_interval: Option<NonTailList<Duration>>,
|
||||
/// Use data from webpage first
|
||||
pub use_webpage: bool,
|
||||
/// Add/Update exif information to image files even when overwrite are disabled
|
||||
pub update_exif: bool,
|
||||
}
|
||||
|
||||
impl CommandOpts {
|
||||
@@ -75,6 +77,7 @@ impl CommandOpts {
|
||||
retry: None,
|
||||
retry_interval: None,
|
||||
use_webpage: false,
|
||||
update_exif: false,
|
||||
}
|
||||
}
|
||||
|
||||
@@ -158,6 +161,11 @@ pub fn parse_cmd() -> Option<CommandOpts> {
|
||||
"LIST",
|
||||
);
|
||||
opts.optflag("", "use-webpage", gettext("Use data from webpage first."));
|
||||
opts.optflag(
|
||||
"",
|
||||
"update-exif",
|
||||
gettext("Add/Update exif information to image files even when overwrite are disabled."),
|
||||
);
|
||||
let result = match opts.parse(&argv[1..]) {
|
||||
Ok(m) => m,
|
||||
Err(err) => {
|
||||
@@ -265,5 +273,6 @@ pub fn parse_cmd() -> Option<CommandOpts> {
|
||||
re.as_mut().unwrap().retry_interval = Some(r.unwrap());
|
||||
}
|
||||
re.as_mut().unwrap().use_webpage = result.opt_present("use-webpage");
|
||||
re.as_mut().unwrap().update_exif = result.opt_present("update-exif");
|
||||
re
|
||||
}
|
||||
|
||||
@@ -14,6 +14,8 @@ pub fn get_settings_list() -> Vec<SettingDes> {
|
||||
SettingDes::new("retry-interval", gettext("The interval (in seconds) between two retries."), JsonValueType::Multiple, Some(check_retry_interval)).unwrap(),
|
||||
SettingDes::new("use-webpage", gettext("Use data from webpage first."), JsonValueType::Boolean, None).unwrap(),
|
||||
SettingDes::new("author-name-filters", gettext("Remove the part which after these parttens."), JsonValueType::Array, Some(check_author_name_filters)).unwrap(),
|
||||
#[cfg(feature = "exif")]
|
||||
SettingDes::new("update-exif", gettext("Add/Update exif information to image files even when overwrite are disabled."), JsonValueType::Boolean, None).unwrap(),
|
||||
]
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user