diff --git a/src/download.rs b/src/download.rs index 75f4f9d..fa36d56 100644 --- a/src/download.rs +++ b/src/download.rs @@ -372,7 +372,7 @@ pub async fn download_artwork( &file_name, &output_file_name, &frames, - 60f32, + helper.ugoira_max_fps(), &options, &metadata, )?; diff --git a/src/opthelper.rs b/src/opthelper.rs index 0ddb037..056464b 100644 --- a/src/opthelper.rs +++ b/src/opthelper.rs @@ -439,6 +439,22 @@ impl OptHelper { false } + #[cfg(feature = "ugoira")] + /// The max fps when converting ugoira(GIF) to video. + pub fn ugoira_max_fps(&self) -> f32 { + match self.opt.get_ref().ugoira_max_fps { + Some(r) => { + return r; + } + None => {} + } + if self.settings.get_ref().have("ugoira-max-fps") { + let v = self.settings.get_ref().get("ugoira-max-fps").unwrap(); + return v.as_f32().unwrap(); + } + 60f32 + } + #[cfg(feature = "ugoira")] /// The Constant Rate Factor when converting ugoira(GIF) to video. pub fn x264_crf(&self) -> Option { diff --git a/src/opts.rs b/src/opts.rs index ee539cf..725c1dc 100644 --- a/src/opts.rs +++ b/src/opts.rs @@ -118,6 +118,8 @@ pub struct CommandOpts { #[cfg(feature = "ugoira")] /// The Constant Rate Factor when converting ugoira(GIF) to video. pub x264_crf: Option, + #[cfg(feature = "ugoira")] + pub ugoira_max_fps: Option, } impl CommandOpts { @@ -158,6 +160,8 @@ impl CommandOpts { urls: None, #[cfg(feature = "ugoira")] x264_crf: None, + #[cfg(feature = "ugoira")] + ugoira_max_fps: None, } } @@ -555,11 +559,28 @@ pub fn parse_cmd() -> Option { ); opts.optopt("", "user-agent", gettext("The User-Agent header."), "UA"); #[cfg(feature = "ugoira")] - opts.optopt( + opts.opt( "", "x264-crf", gettext("The Constant Rate Factor when converting ugoira(GIF) to video."), "float", + HasArg::Maybe, + getopts::Occur::Optional, + ); + #[cfg(feature = "ugoira")] + opts.opt( + "", + "ugoira-max-fps", + format!( + "{} ({} {})", + gettext("The max fps when converting ugoira(GIF) to video."), + gettext("Default:"), + "60" + ) + .as_str(), + "float", + HasArg::Maybe, + getopts::Occur::Optional, ); let result = match opts.parse(&argv[1..]) { Ok(m) => m, @@ -882,6 +903,33 @@ pub fn parse_cmd() -> Option { return None; } } + #[cfg(feature = "ugoira")] + match parse_optional_opt(&result, "ugoira-max-fps", 60f32, parse_f32) { + Ok(r) => match r { + Some(crf) => { + if crf <= 0f32 || crf > 1000f32 { + println!( + "{}", + gettext("ugoira-max-fps can not less than 0 or greater than 1000.") + ); + return None; + } else { + re.as_mut().unwrap().ugoira_max_fps.replace(crf); + } + } + None => {} + }, + Err(e) => { + println!( + "{} {}", + ("Failed to parse :") + .replace("", "ugoira-max-fps") + .as_str(), + e + ); + return None; + } + } re } diff --git a/src/settings_list.rs b/src/settings_list.rs index 3081a84..d3e47b4 100644 --- a/src/settings_list.rs +++ b/src/settings_list.rs @@ -59,6 +59,8 @@ pub fn get_settings_list() -> Vec { SettingDes::new("user-agent", gettext("The User-Agent header."), JsonValueType::Str, None).unwrap(), #[cfg(feature = "ugoira")] SettingDes::new("x264-crf", gettext("The Constant Rate Factor when converting ugoira(GIF) to video."), JsonValueType::Number, Some(check_crf)).unwrap(), + #[cfg(feature = "ugoira")] + SettingDes::new("ugoira-max-fps", gettext("The max fps when converting ugoira(GIF) to video."), JsonValueType::Number, Some(check_ugoira_max_fps)).unwrap(), ] } @@ -122,6 +124,14 @@ fn check_x264_profile(obj: &JsonValue) -> bool { } } +#[cfg(feature = "ugoira")] +fn check_ugoira_max_fps(obj: &JsonValue) -> bool { + match obj.as_f32() { + Some(fps) => fps > 0f32 && fps <= 1000f32, + None => false, + } +} + #[test] fn test_get_settings_list() { get_settings_list();