aboutsummaryrefslogtreecommitdiffstats
path: root/src/structs.rs
diff options
context:
space:
mode:
authorNathan Jaremko2018-02-08 00:42:17 -0500
committerNathan Jaremko2018-02-08 00:42:17 -0500
commit36ec8131c0e71bad454aeb5e66c63f04cfb93e2c (patch)
tree30c07bd1e1989ddbe4c404c317516b3de2a26176 /src/structs.rs
parentaf8f2907c99c0a4cf5d26c5da74efb51b576909c (diff)
downloadpodcast-36ec8131c0e71bad454aeb5e66c63f04cfb93e2c.tar.bz2
0.5.0
Diffstat (limited to 'src/structs.rs')
-rw-r--r--src/structs.rs35
1 files changed, 26 insertions, 9 deletions
diff --git a/src/structs.rs b/src/structs.rs
index b6a1d38..b9db14d 100644
--- a/src/structs.rs
+++ b/src/structs.rs
@@ -41,7 +41,6 @@ impl Config {
}
}
-
#[derive(Serialize, Deserialize, Clone)]
pub struct Subscription {
pub title: String,
@@ -216,20 +215,39 @@ impl Podcast {
}
pub fn download(&self) -> Result<(), io::Error> {
+ print!("You are about to download all episodes (y/n): ");
+ io::stdout().flush().ok();
+ let mut input = String::new();
+ if let Ok(_) = io::stdin().read_line(&mut input) {
+ if input.to_lowercase().trim() != "y" {
+ return Ok(());
+ }
+ }
+
let mut path = get_podcast_dir();
path.push(self.title());
- let downloaded = already_downloaded(self.title())?;
-
- self.episodes().par_iter().for_each(|ref i| {
- if let Some(ep_title) = i.title() {
- if !downloaded.contains(ep_title) {
+ match already_downloaded(self.title()) {
+ Ok(downloaded) => {
+ self.episodes().par_iter().for_each(|ref i| {
+ if let Some(ep_title) = i.title() {
+ if !downloaded.contains(ep_title) {
+ if let Err(err) = i.download(self.title()) {
+ println!("{}", err);
+ }
+ }
+ }
+ });
+ }
+ Err(_) => {
+ self.episodes().par_iter().for_each(|ref i| {
if let Err(err) = i.download(self.title()) {
println!("{}", err);
}
- }
+ });
}
- });
+ }
+
Ok(())
}
@@ -277,7 +295,6 @@ impl Episode {
}
}
-
pub fn download(&self, podcast_name: &str) -> Result<(), io::Error> {
let mut path = get_podcast_dir();
path.push(podcast_name);