aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorNathan Jaremko2018-05-16 23:32:15 -0400
committerNathan Jaremko2018-05-16 23:32:15 -0400
commit07db1bb3e6e55cc433c286f03eea8a4df8bcbfaf (patch)
treed94e8da64e8d987d0186d53cfb03e1aa0ae76187 /src
parente394ea52b04a99ba55719a7a9764bca3ebb591d2 (diff)
downloadpodcast-07db1bb3e6e55cc433c286f03eea8a4df8bcbfaf.tar.bz2
Escape filenames to prevent issues on some filesystems
Diffstat (limited to 'src')
-rw-r--r--src/main.rs4
-rw-r--r--src/structs.rs13
2 files changed, 12 insertions, 5 deletions
diff --git a/src/main.rs b/src/main.rs
index 4016199..96572cc 100644
--- a/src/main.rs
+++ b/src/main.rs
@@ -4,6 +4,8 @@ extern crate chrono;
extern crate clap;
#[macro_use]
extern crate error_chain;
+#[macro_use]
+extern crate lazy_static;
extern crate rayon;
extern crate regex;
extern crate reqwest;
@@ -29,7 +31,7 @@ use utils::*;
use clap::{App, Arg, SubCommand};
-const VERSION: &str = "0.5.5";
+const VERSION: &str = "0.5.6";
fn main() -> Result<()> {
create_directories().chain_err(|| "unable to create directories")?;
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> {