Some code cleanup.
This commit is contained in:
parent
07d3135d91
commit
108ed34b40
@ -4,7 +4,7 @@ version = "0.1.0"
|
|||||||
authors = ["Jordan Petridis <jordanpetridis@protonmail.com>"]
|
authors = ["Jordan Petridis <jordanpetridis@protonmail.com>"]
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
rfc822_sanitizer = "0.1.0"
|
rfc822_sanitizer = "0.2.0"
|
||||||
rayon = "0.8.2"
|
rayon = "0.8.2"
|
||||||
regex = "0.2"
|
regex = "0.2"
|
||||||
error-chain = "0.11.0"
|
error-chain = "0.11.0"
|
||||||
@ -23,4 +23,7 @@ chrono = "0.4.0"
|
|||||||
rss = { version = "1.1.0", features = ["from_url"]}
|
rss = { version = "1.1.0", features = ["from_url"]}
|
||||||
# overide diesel's dependancy that would otherwise turn a dotenv feature of
|
# overide diesel's dependancy that would otherwise turn a dotenv feature of
|
||||||
# that rss depends upon
|
# that rss depends upon
|
||||||
dotenv = "*"
|
dotenv = "*"
|
||||||
|
|
||||||
|
[dev-dependencies]
|
||||||
|
tempdir = "0.3.5"
|
||||||
|
|||||||
@ -22,6 +22,6 @@ merge_derives = true
|
|||||||
array_horizontal_layout_threshold = 5
|
array_horizontal_layout_threshold = 5
|
||||||
condense_wildcard_suffixes = true
|
condense_wildcard_suffixes = true
|
||||||
# rustfmt 0.2.7 panics with format_string = true atm
|
# rustfmt 0.2.7 panics with format_string = true atm
|
||||||
# format_strings = false
|
# format_strings = true
|
||||||
chain_one_line_max = 60
|
chain_one_line_max = 60
|
||||||
chain_split_single_child = false
|
chain_split_single_child = false
|
||||||
|
|||||||
@ -7,14 +7,7 @@ use errors::*;
|
|||||||
pub fn parse_podcast(chan: &Channel, source_id: i32) -> Result<models::NewPodcast> {
|
pub fn parse_podcast(chan: &Channel, source_id: i32) -> Result<models::NewPodcast> {
|
||||||
let title = chan.title().to_owned();
|
let title = chan.title().to_owned();
|
||||||
let link = chan.link().to_owned();
|
let link = chan.link().to_owned();
|
||||||
|
|
||||||
let description = chan.description().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 image_uri = chan.image().map(|foo| foo.url().to_owned());
|
||||||
|
|
||||||
let foo = models::NewPodcast {
|
let foo = models::NewPodcast {
|
||||||
@ -27,7 +20,6 @@ pub fn parse_podcast(chan: &Channel, source_id: i32) -> Result<models::NewPodcas
|
|||||||
Ok(foo)
|
Ok(foo)
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO: Factor out rfc822 to rfc2822 normalization
|
|
||||||
pub fn parse_episode<'a>(item: &'a Item, parent_id: i32) -> Result<models::NewEpisode<'a>> {
|
pub fn parse_episode<'a>(item: &'a Item, parent_id: i32) -> Result<models::NewEpisode<'a>> {
|
||||||
let title = item.title();
|
let title = item.title();
|
||||||
let description = item.description();
|
let description = item.description();
|
||||||
@ -44,20 +36,14 @@ pub fn parse_episode<'a>(item: &'a Item, parent_id: i32) -> Result<models::NewEp
|
|||||||
let local_uri = None;
|
let local_uri = None;
|
||||||
|
|
||||||
let date = parse_from_rfc2822_with_fallback(item.pub_date().unwrap());
|
let date = parse_from_rfc2822_with_fallback(item.pub_date().unwrap());
|
||||||
// let pub_date = date.map(|x| x.to_rfc2822());
|
|
||||||
//
|
|
||||||
let pub_date = match date {
|
|
||||||
Ok(foo) => Some(foo.to_rfc2822()),
|
|
||||||
Err(_) => None,
|
|
||||||
};
|
|
||||||
|
|
||||||
let epoch = match date {
|
// Should treat information from the rss feeds as invalid by default.
|
||||||
Ok(foo) => foo.timestamp() as i32,
|
// Case: Thu, 05 Aug 2016 06:00:00 -0400 <-- Actually that was friday.
|
||||||
Err(_) => 0,
|
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()
|
let length = item.enclosure()
|
||||||
.map(|x| x.length().parse().unwrap_or_default());
|
.map(|x| x.length().parse().unwrap_or(0));
|
||||||
|
|
||||||
let foo = models::NewEpisode {
|
let foo = models::NewEpisode {
|
||||||
title,
|
title,
|
||||||
|
|||||||
@ -248,6 +248,8 @@ pub struct NewPodcast {
|
|||||||
}
|
}
|
||||||
|
|
||||||
impl 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<NewPodcast> {
|
pub fn from_url(uri: &str, parent: &Source) -> Result<NewPodcast> {
|
||||||
let chan = Channel::from_url(uri)?;
|
let chan = Channel::from_url(uri)?;
|
||||||
let foo = ::feedparser::parse_podcast(&chan, parent.id())?;
|
let foo = ::feedparser::parse_podcast(&chan, parent.id())?;
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user