aboutsummaryrefslogtreecommitdiffstats
path: root/src/utils.rs
diff options
context:
space:
mode:
authornjaremko2017-07-17 18:10:12 -0400
committernjaremko2017-07-17 18:10:12 -0400
commitc8386aa0b9ccc6bf167cef769c4a5d8cfb86e3ef (patch)
treef83bf72473c11d3b67639078a8e0b8160b5031a5 /src/utils.rs
parent3483b857cf687fe3d1568b82ca7bb8ffec938a7c (diff)
downloadpodcast-c8386aa0b9ccc6bf167cef769c4a5d8cfb86e3ef.tar.bz2
More features
Diffstat (limited to 'src/utils.rs')
-rw-r--r--src/utils.rs34
1 files changed, 34 insertions, 0 deletions
diff --git a/src/utils.rs b/src/utils.rs
new file mode 100644
index 0000000..ab4876f
--- /dev/null
+++ b/src/utils.rs
@@ -0,0 +1,34 @@
+use std::fs;
+use std::path::PathBuf;
+use std::collections::BTreeSet;
+use std::env;
+
+
+pub fn already_downloaded(dir: &str) -> BTreeSet<String> {
+ let mut result = BTreeSet::new();
+
+ let mut path = get_podcast_dir();
+ path.push(dir);
+
+ if let Ok(entries) = fs::read_dir(path) {
+ for entry in entries {
+ if let Ok(entry) = entry {
+ match entry.file_name().into_string() {
+ Ok(val) => {
+ result.insert(String::from(val.trim_right_matches(".mp3")));
+ }
+ Err(err) => {
+ println!("OsString: {:?} couldn't be converted to String", err);
+ }
+ }
+ }
+ }
+ }
+ result
+}
+
+pub fn get_podcast_dir() -> PathBuf {
+ let mut path = env::home_dir().unwrap();
+ path.push("Podcasts");
+ path
+}