aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorNathan Jaremko2018-05-16 23:32:15 -0400
committerNathan Jaremko2018-05-16 23:32:15 -0400
commit07db1bb3e6e55cc433c286f03eea8a4df8bcbfaf (patch)
treed94e8da64e8d987d0186d53cfb03e1aa0ae76187
parente394ea52b04a99ba55719a7a9764bca3ebb591d2 (diff)
downloadpodcast-07db1bb3e6e55cc433c286f03eea8a4df8bcbfaf.tar.bz2
Escape filenames to prevent issues on some filesystems
-rw-r--r--CHANGELOG3
-rw-r--r--Cargo.toml3
-rw-r--r--src/main.rs4
-rw-r--r--src/structs.rs13
4 files changed, 17 insertions, 6 deletions
diff --git a/CHANGELOG b/CHANGELOG
index fecadbc..708cc65 100644
--- a/CHANGELOG
+++ b/CHANGELOG
@@ -1,3 +1,6 @@
+0.5.6
+- Escape filenames to prevent issues on some filesystems
+
0.5.5
- Attempt at better handling file handles to fix windows bug regarding renaming .subscriptions.tmp
diff --git a/Cargo.toml b/Cargo.toml
index fd507e3..55196b6 100644
--- a/Cargo.toml
+++ b/Cargo.toml
@@ -1,6 +1,6 @@
[package]
name = "podcast"
-version = "0.5.5"
+version = "0.5.6"
authors = ["Nathan Jaremko <njaremko@gmail.com>"]
description = "A command line podcast manager"
license = "GPL-3.0"
@@ -21,6 +21,7 @@ name = "podcast"
chrono = { version = "0.4", features = ["serde"] }
clap = "2.28"
error-chain = "0.11"
+lazy_static = "1.0"
rayon = "0.9"
regex = "0.2"
reqwest = "0.8"
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> {