mirror of
https://github.com/lifegpc/pixiv_downloader.git
synced 2026-06-06 05:49:01 +08:00
Add new option ugoira-max-fps ( #330
This commit is contained in:
@@ -372,7 +372,7 @@ pub async fn download_artwork(
|
||||
&file_name,
|
||||
&output_file_name,
|
||||
&frames,
|
||||
60f32,
|
||||
helper.ugoira_max_fps(),
|
||||
&options,
|
||||
&metadata,
|
||||
)?;
|
||||
|
||||
@@ -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<f32> {
|
||||
|
||||
50
src/opts.rs
50
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<f32>,
|
||||
#[cfg(feature = "ugoira")]
|
||||
pub ugoira_max_fps: Option<f32>,
|
||||
}
|
||||
|
||||
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<CommandOpts> {
|
||||
);
|
||||
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<CommandOpts> {
|
||||
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 <opt>:")
|
||||
.replace("<opt>", "ugoira-max-fps")
|
||||
.as_str(),
|
||||
e
|
||||
);
|
||||
return None;
|
||||
}
|
||||
}
|
||||
re
|
||||
}
|
||||
|
||||
|
||||
@@ -59,6 +59,8 @@ pub fn get_settings_list() -> Vec<SettingDes> {
|
||||
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();
|
||||
|
||||
Reference in New Issue
Block a user