almost transcoding
This commit is contained in:
@@ -7,9 +7,9 @@ pub struct Config {
|
||||
pub base_url: String,
|
||||
pub access_token: Option<String>,
|
||||
pub user_id: Option<String>,
|
||||
pub transcode_mbps: f32,
|
||||
}
|
||||
|
||||
|
||||
#[derive(Debug)]
|
||||
pub enum ConfigError {
|
||||
NotFound(PathBuf),
|
||||
@@ -45,6 +45,7 @@ fn parse_config(s: &str) -> Result<Config, String> {
|
||||
let mut base_url: Option<String> = None;
|
||||
let mut access_token: Option<String> = None;
|
||||
let mut user_id: Option<String> = None;
|
||||
let mut transcode_mbps: Option<f32> = None;
|
||||
|
||||
for (i, line) in s.lines().enumerate() {
|
||||
let line = line.trim();
|
||||
@@ -68,6 +69,12 @@ fn parse_config(s: &str) -> Result<Config, String> {
|
||||
"base_url" => base_url = Some(val),
|
||||
"access_token" => access_token = Some(val),
|
||||
"user_id" => user_id = Some(val),
|
||||
"transcode_mbps" => {
|
||||
// allow raw numbers or quoted numbers
|
||||
if let Ok(n) = val.parse::<f32>() {
|
||||
transcode_mbps = Some(n);
|
||||
}
|
||||
}
|
||||
_ => {}
|
||||
}
|
||||
}
|
||||
@@ -78,6 +85,7 @@ fn parse_config(s: &str) -> Result<Config, String> {
|
||||
base_url,
|
||||
access_token,
|
||||
user_id,
|
||||
transcode_mbps: transcode_mbps.unwrap_or(5.0),
|
||||
})
|
||||
}
|
||||
|
||||
@@ -100,6 +108,8 @@ pub fn save_config(cfg: &Config) -> Result<(), ConfigError> {
|
||||
out.push_str(&format!("user_id = \"{}\"\n", u));
|
||||
}
|
||||
|
||||
out.push_str(&format!("transcode_mbps = {}\n", cfg.transcode_mbps));
|
||||
|
||||
std::fs::write(path, out)?;
|
||||
Ok(())
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user