diff --git a/Cargo.toml b/Cargo.toml index 612ddd6..921fd72 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -5,6 +5,7 @@ authors = ["Jordan Petridis "] [dependencies] rayon = "0.8.2" +regex = "0.2" error-chain = "0.11.0" structopt = "0.1.0" structopt-derive = "0.1.0" diff --git a/src/feedparser.rs b/src/feedparser.rs index 8aeecaf..81262fc 100644 --- a/src/feedparser.rs +++ b/src/feedparser.rs @@ -1,5 +1,7 @@ use rss::{Channel, Item}; use chrono::DateTime; +use regex; + use models; use errors::*; use std::collections::HashMap; @@ -70,13 +72,32 @@ pub fn parse_episode<'a>(item: &'a Item, parent_id: i32) -> Result { let mut foo = String::from(abc); + // Pad HH:MM:SS with exta zero if needed. + let re = regex::Regex::new(r"(\d{1,2}):(\d{1,2}):(\d{1,2})")?; + // hours, minutes, seconds = cap[1], cap[2], cap[3] + let cap = re.captures(&abc).unwrap(); + let mut newtime = Vec::new(); + + cap.iter().skip(1).for_each(|x| if let Some(y) = x { + if y.end() - y.start() == 1 { + // warn!("{}", y.as_str()); + newtime.push(format!("0{}", y.as_str())); + } else { + newtime.push(y.as_str().to_string()); + } + }); + + let ntime = &newtime.join(":"); + foo = foo.replace(cap.get(0).unwrap().as_str(), ntime); + debug!("{:?}", foo); + // Weekday name is not required for rfc2822 // for stable, replace for_each with map and add // .fold((), |(),_|()) or .collect() - weekdays.iter().for_each(|x| if abc.starts_with(x) { + weekdays.iter().for_each(|x| if foo.starts_with(x) { // TODO: handle to lower etc. // For sure someone has a weird feed with the day in lowercase - foo = format!("{}", &abc[x.len()..]); + foo = format!("{}", &foo[x.len()..]); foo = foo.trim().to_string(); }); @@ -85,8 +106,6 @@ pub fn parse_episode<'a>(item: &'a Item, parent_id: i32) -> Result