diff options
| author | Nathan Jaremko | 2018-05-16 23:32:15 -0400 | 
|---|---|---|
| committer | Nathan Jaremko | 2018-05-16 23:32:15 -0400 | 
| commit | 07db1bb3e6e55cc433c286f03eea8a4df8bcbfaf (patch) | |
| tree | d94e8da64e8d987d0186d53cfb03e1aa0ae76187 /src/structs.rs | |
| parent | e394ea52b04a99ba55719a7a9764bca3ebb591d2 (diff) | |
| download | podcast-07db1bb3e6e55cc433c286f03eea8a4df8bcbfaf.tar.bz2 | |
Escape filenames to prevent issues on some filesystems
Diffstat (limited to 'src/structs.rs')
| -rw-r--r-- | src/structs.rs | 13 | 
1 files changed, 9 insertions, 4 deletions
| diff --git a/src/structs.rs b/src/structs.rs index 0caed73..97e6718 100644 --- a/src/structs.rs +++ b/src/structs.rs @@ -8,11 +8,16 @@ use std::io::{self, BufReader, Read, Write};  use chrono::prelude::*;  use rayon::prelude::*; +use regex::Regex;  use reqwest;  use rss::{Channel, Item};  use serde_json;  use yaml_rust::YamlLoader; +lazy_static! { +    static ref FILENAME_ESCAPE: Regex = Regex::new(r#"[\\/:*?"<>|]"#).unwrap(); +} +  pub struct Config {      pub auto_download_limit: i64,  } @@ -230,7 +235,7 @@ impl Podcast {              Ok(downloaded) => {                  self.episodes().par_iter().for_each(|i| {                      if let Some(ep_title) = i.title() { -                        if !downloaded.contains(ep_title) { +                        if !downloaded.contains(&ep_title) {                              if let Err(err) = i.download(self.title()) {                                  eprintln!("{}", err);                              } @@ -259,7 +264,7 @@ impl Podcast {          episode_numbers.par_iter().for_each(|ep_num| {              if let Some(ep_title) = episodes[episodes.len() - ep_num].title() { -                if !downloaded.contains(ep_title) { +                if !downloaded.contains(&ep_title) {                      if let Err(err) = episodes[episodes.len() - ep_num].download(self.title()) {                          println!("{}", err);                      } @@ -271,8 +276,8 @@ impl Podcast {  }  impl Episode { -    pub fn title(&self) -> Option<&str> { -        self.0.title() +    pub fn title(&self) -> Option<String> { +        Some(FILENAME_ESCAPE.replace_all(self.0.title()?, "_").to_string())      }      pub fn url(&self) -> Option<&str> { | 
