diff --git a/Cargo.toml b/Cargo.toml index bca9f82..0bc1442 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -4,7 +4,7 @@ version = "0.1.0" authors = ["Jordan Petridis "] [dependencies] -rfc822_sanitizer = "0.1.0" +rfc822_sanitizer = "0.2.0" rayon = "0.8.2" regex = "0.2" error-chain = "0.11.0" @@ -23,4 +23,7 @@ chrono = "0.4.0" rss = { version = "1.1.0", features = ["from_url"]} # overide diesel's dependancy that would otherwise turn a dotenv feature of # that rss depends upon -dotenv = "*" \ No newline at end of file +dotenv = "*" + +[dev-dependencies] +tempdir = "0.3.5" diff --git a/rustfmt.toml b/rustfmt.toml index 3ea68a6..2f0d91b 100644 --- a/rustfmt.toml +++ b/rustfmt.toml @@ -22,6 +22,6 @@ merge_derives = true array_horizontal_layout_threshold = 5 condense_wildcard_suffixes = true # rustfmt 0.2.7 panics with format_string = true atm -# format_strings = false +# format_strings = true chain_one_line_max = 60 chain_split_single_child = false diff --git a/src/feedparser.rs b/src/feedparser.rs index 41e7984..b853f14 100644 --- a/src/feedparser.rs +++ b/src/feedparser.rs @@ -7,14 +7,7 @@ use errors::*; pub fn parse_podcast(chan: &Channel, source_id: i32) -> Result { let title = chan.title().to_owned(); let link = chan.link().to_owned(); - let description = chan.description().to_owned(); - - // let image_uri = match chan.image() { - // Some(foo) => Some(foo.url().to_owned()), - // None => None, - // }; - // Same as the above match expression. let image_uri = chan.image().map(|foo| foo.url().to_owned()); let foo = models::NewPodcast { @@ -27,7 +20,6 @@ pub fn parse_podcast(chan: &Channel, source_id: i32) -> Result(item: &'a Item, parent_id: i32) -> Result> { let title = item.title(); let description = item.description(); @@ -44,20 +36,14 @@ pub fn parse_episode<'a>(item: &'a Item, parent_id: i32) -> Result Some(foo.to_rfc2822()), - Err(_) => None, - }; - let epoch = match date { - Ok(foo) => foo.timestamp() as i32, - Err(_) => 0, - }; + // Should treat information from the rss feeds as invalid by default. + // Case: Thu, 05 Aug 2016 06:00:00 -0400 <-- Actually that was friday. + let pub_date = date.map(|x| x.to_rfc2822()).ok(); + let epoch = date.map(|x| x.timestamp() as i32).unwrap_or(0); let length = item.enclosure() - .map(|x| x.length().parse().unwrap_or_default()); + .map(|x| x.length().parse().unwrap_or(0)); let foo = models::NewEpisode { title, diff --git a/src/models.rs b/src/models.rs index 5522c8d..cd08319 100644 --- a/src/models.rs +++ b/src/models.rs @@ -248,6 +248,8 @@ pub struct NewPodcast { } impl NewPodcast { + // FIXME: This method seems to not be used anywhere atm. + // Drop dead code maybe? pub fn from_url(uri: &str, parent: &Source) -> Result { let chan = Channel::from_url(uri)?; let foo = ::feedparser::parse_podcast(&chan, parent.id())?;