diff options
| author | Nathan Jaremko | 2018-02-08 00:42:17 -0500 | 
|---|---|---|
| committer | Nathan Jaremko | 2018-02-08 00:42:17 -0500 | 
| commit | 36ec8131c0e71bad454aeb5e66c63f04cfb93e2c (patch) | |
| tree | 30c07bd1e1989ddbe4c404c317516b3de2a26176 /src/structs.rs | |
| parent | af8f2907c99c0a4cf5d26c5da74efb51b576909c (diff) | |
| download | podcast-36ec8131c0e71bad454aeb5e66c63f04cfb93e2c.tar.bz2 | |
0.5.0
Diffstat (limited to 'src/structs.rs')
| -rw-r--r-- | src/structs.rs | 35 | 
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); | 
