aboutsummaryrefslogtreecommitdiffstats
path: root/src/utils.rs
diff options
context:
space:
mode:
Diffstat (limited to 'src/utils.rs')
-rw-r--r--src/utils.rs41
1 files changed, 38 insertions, 3 deletions
diff --git a/src/utils.rs b/src/utils.rs
index b2c590a..02c9983 100644
--- a/src/utils.rs
+++ b/src/utils.rs
@@ -15,10 +15,18 @@ pub fn already_downloaded(dir: &str) -> BTreeSet<String> {
if let Ok(entry) = entry {
match entry.file_name().into_string() {
Ok(val) => {
- result.insert(String::from(val.trim_right_matches(".mp3")));
+ // TODO There has to be a better way to do this...later
+ result.insert(String::from(
+ val.trim_right_matches(".mp3")
+ .trim_right_matches(".m4a")
+ .trim_right_matches(".ogg"),
+ ));
}
- Err(err) => {
- println!("OsString: {:?} couldn't be converted to String", err);
+ Err(_) => {
+ println!(
+ "OsString: {:?} couldn't be converted to String",
+ entry.file_name()
+ );
}
}
}
@@ -37,3 +45,30 @@ pub fn get_podcast_dir() -> PathBuf {
}
}
}
+
+pub fn parse_download_episodes(e_search: &str) -> Vec<usize> {
+ let input = String::from(e_search);
+ let mut ranges = Vec::<(usize, usize)>::new();
+ let mut elements = Vec::<usize>::new();
+ let comma_separated: Vec<&str> = input.split(',').collect();
+ for elem in comma_separated {
+ let temp = String::from(elem);
+ if temp.contains("-") {
+ let range: Vec<usize> = elem.split('-')
+ .map(|i| i.parse::<usize>().unwrap())
+ .collect();
+ ranges.push((range[0], range[1]));
+ } else {
+ elements.push(elem.parse::<usize>().unwrap());
+ }
+ }
+
+ for range in ranges {
+ // Add 1 to upper range to include given episode in the download
+ for num in range.0..range.1 + 1 {
+ elements.push(num);
+ }
+ }
+ elements.dedup();
+ elements
+}