From af8f2907c99c0a4cf5d26c5da74efb51b576909c Mon Sep 17 00:00:00 2001 From: Nathan Jaremko Date: Sun, 24 Dec 2017 13:49:19 -0500 Subject: 0.4.7 --- src/main.rs | 4 ++-- src/structs.rs | 13 +++---------- src/utils.rs | 55 +++++++++++++++++++++++++++++++++++++++++++++++++++---- 3 files changed, 56 insertions(+), 16 deletions(-) (limited to 'src') diff --git a/src/main.rs b/src/main.rs index 539b0ed..61d4258 100644 --- a/src/main.rs +++ b/src/main.rs @@ -20,7 +20,7 @@ use structs::*; use clap::{App, Arg, SubCommand}; -const VERSION: &str = "0.4.5"; +const VERSION: &str = "0.4.7"; fn main() { if let Err(err) = create_directories() { @@ -178,4 +178,4 @@ fn main() { if let Err(err) = state.save() { eprintln!("{}", err); } -} +} \ No newline at end of file diff --git a/src/structs.rs b/src/structs.rs index 817a0d1..b6a1d38 100644 --- a/src/structs.rs +++ b/src/structs.rs @@ -14,14 +14,12 @@ use yaml_rust::YamlLoader; pub struct Config { pub auto_download_limit: i64, - pub auto_delete_limit: i64, } impl Config { pub fn new() -> Config { let mut path = get_podcast_dir(); let mut download_limit = 1; - let mut delete_limit = 0; path.push(".config"); if path.exists() { let mut s = String::new(); @@ -32,9 +30,6 @@ impl Config { if let Some(val) = doc["auto_download_limit"].as_i64() { download_limit = val; } - if let Some(val) = doc["auto_delete_limit"].as_i64() { - delete_limit = val; - } } } else { let mut file = File::create(&path).unwrap(); @@ -42,7 +37,6 @@ impl Config { } Config { auto_download_limit: download_limit, - auto_delete_limit: delete_limit, } } } @@ -92,10 +86,9 @@ impl State { }; state.version = String::from(version); // Check if a day has passed (86400 seconds) since last launch - if state - .last_run_time - .signed_duration_since(Utc::now()) - .num_seconds() < -86400 + if Utc::now() + .signed_duration_since(state.last_run_time) + .num_seconds() > 86400 { update_rss(&mut state); check_for_update(&state.version); diff --git a/src/utils.rs b/src/utils.rs index 789c7da..29bd15a 100644 --- a/src/utils.rs +++ b/src/utils.rs @@ -18,14 +18,16 @@ pub fn trim_extension(filename: &str) -> Option { pub fn find_extension(input: &str) -> Option<&str> { let tmp = String::from(input); - if tmp.contains(".mp3") { + if tmp.ends_with(".mp3") { Some(".mp3") - } else if tmp.contains(".m4a") { + } else if tmp.ends_with(".m4a") { Some(".m4a") - } else if tmp.contains(".wav") { + } else if tmp.ends_with(".wav") { Some(".wav") - } else if tmp.contains(".ogg") { + } else if tmp.ends_with(".ogg") { Some(".ogg") + } else if tmp.ends_with(".opus") { + Some(".opus") } else { None } @@ -135,3 +137,48 @@ pub fn parse_download_episodes(e_search: &str) -> Result, ParseIntErr elements.dedup(); Ok(elements) } + +#[cfg(test)] +mod tests { + use super::*; + + #[test] + fn test_find_extension_mp3() { + assert_eq!(find_extension("test.mp3"), Some(".mp3")) + } + + #[test] + fn test_find_extension_m4a() { + assert_eq!(find_extension("test.m4a"), Some(".m4a")) + } + + #[test] + fn test_find_extension_wav() { + assert_eq!(find_extension("test.wav"), Some(".wav")) + } + + #[test] + fn test_find_extension_ogg() { + assert_eq!(find_extension("test.ogg"), Some(".ogg")) + } + + #[test] + fn test_find_extension_opus() { + assert_eq!(find_extension("test.opus"), Some(".opus")) + } + + #[test] + fn test_find_extension_invalid() { + assert_eq!(find_extension("test.taco"), None) + } + + #[test] + fn test_trim_extension() { + assert_eq!(trim_extension("test.taco"), Some(String::from("test"))) + } + + #[test] + fn test_trim_extension_invalid() { + assert_eq!(trim_extension("test"), None) + } +} -- cgit v1.2.3