diff --git a/TODO.md b/TODO.md index 5190a13..71d1fda 100644 --- a/TODO.md +++ b/TODO.md @@ -10,7 +10,6 @@ ## Second - [ ] Make use of file metadas, [This](https://github.com/GuillaumeGomez/audio-video-metadata) might be helpfull. -- [ ] Notifications - [ ] Episode queue - [ ] Embedded player - [ ] MPRIS integration @@ -21,8 +20,8 @@ - [ ] Download Queue - [ ] Ability to Stream content on demand - [ ] soundcloud and itunes feeds // [This](http://getrssfeed.com) seems intresting. -- [ ] Integrate with Itunes API for various crap -- [ ] YoutubeFeeds +- [ ] Integrate with Itunes API for various crap? +- [ ] YoutubeFeeds? ## Rest Tasks diff --git a/hammond-data/benches/bench.rs b/hammond-data/benches/bench.rs index 6f79f9e..9d3dcbc 100644 --- a/hammond-data/benches/bench.rs +++ b/hammond-data/benches/bench.rs @@ -95,7 +95,6 @@ fn bench_get_normal_feeds(b: &mut Bencher) { b.iter(|| { let sources = hammond_data::dbqueries::get_sources().unwrap(); index_loop(sources); - println!("I RUN"); }); } diff --git a/hammond-data/src/feed.rs b/hammond-data/src/feed.rs index 01e3840..11bd6bc 100644 --- a/hammond-data/src/feed.rs +++ b/hammond-data/src/feed.rs @@ -14,11 +14,11 @@ use models::insertables::{NewEpisode, NewPodcast}; use database::connection; use errors::*; -#[cfg(test)] -use models::queryables::Episode; +// #[cfg(test)] +// use models::queryables::Episode; #[derive(Debug)] -/// Wrapper struct that hold a `Source` and the `rss::Channel` +/// Wrapper struct that hold a `Source` id and the `rss::Channel` /// that corresponds to the `Source.uri` field. pub struct Feed { channel: rss::Channel, @@ -36,18 +36,12 @@ impl Feed { Feed { channel, source_id } } - /// docs + /// Index the contents of the RSS `Feed` into the database. pub fn index(&self) -> Result<()> { - let pd = self.get_podcast()?; + let pd = self.parse_podcast().into_podcast()?; self.index_channel_items(&pd) } - // #[allow(dead_code)] - // fn index_channel(&self) -> Result<()> { - // self.parse_channel().index()?; - // Ok(()) - // } - // TODO: Refactor transcactions and find a way to do it in parallel. fn index_channel_items(&self, pd: &Podcast) -> Result<()> { let episodes = self.parse_channel_items(pd); @@ -56,8 +50,7 @@ impl Feed { let _ = con.transaction::<(), Error, _>(|| { episodes.into_iter().for_each(|x| { - let e = x.index(&con); - if let Err(err) = e { + if let Err(err) = x.index(&con) { error!("Failed to index episode: {:?}.", x.title()); error!("Error msg: {}", err); }; @@ -67,7 +60,7 @@ impl Feed { Ok(()) } - fn parse_channel(&self) -> NewPodcast { + fn parse_podcast(&self) -> NewPodcast { parser::new_podcast(&self.channel, self.source_id) } @@ -81,25 +74,20 @@ impl Feed { new_episodes } - fn get_podcast(&self) -> Result { - self.parse_channel().into_podcast() - } + // #[cfg(test)] + // /// This returns only the episodes in the xml feed. + // fn get_episodes(&self) -> Result> { + // let pd = self.get_podcast()?; + // let eps = self.parse_channel_items(&pd); - #[cfg(test)] - /// This returns only the episodes in the xml feed. - /// Used for unit-tests only. - fn get_episodes(&self) -> Result> { - let pd = self.get_podcast()?; - let eps = self.parse_channel_items(&pd); + // let db = connection(); + // let con = db.get()?; + // let episodes: Vec<_> = eps.into_iter() + // .filter_map(|ep| ep.into_episode(&con).ok()) + // .collect(); - let db = connection(); - let con = db.get()?; - let episodes: Vec<_> = eps.into_iter() - .filter_map(|ep| ep.into_episode(&con).ok()) - .collect(); - - Ok(episodes) - } + // Ok(episodes) + // } } /// Index a "list" of `Source`s. @@ -208,41 +196,4 @@ mod tests { assert_eq!(dbqueries::get_podcasts().unwrap().len(), 4); assert_eq!(dbqueries::get_episodes().unwrap().len(), 274); } - - #[test] - fn test_partial_index_podcast() { - truncate_db().unwrap(); - let url = "https://feeds.feedburner.com/InterceptedWithJeremyScahill"; - - let mut s1 = Source::from_url(url).unwrap(); - let mut s2 = Source::from_url(url).unwrap(); - assert_eq!(s1, s2); - assert_eq!(s1.id(), s2.id()); - - let f1 = s1.into_feed(false).unwrap(); - let f2 = s2.into_feed(false).unwrap(); - - let p1 = f1.get_podcast().unwrap(); - let p2 = { - f2.index().unwrap(); - f2.get_podcast().unwrap() - }; - assert_eq!(p1, p2); - assert_eq!(p1.id(), p2.id()); - assert_eq!(p1.source_id(), p2.source_id()); - - let eps1 = f1.get_episodes().unwrap(); - let eps2 = { - f2.index().unwrap(); - f2.get_episodes().unwrap() - }; - - eps1.into_par_iter().zip(eps2).into_par_iter().for_each( - |(ep1, ep2): (Episode, Episode)| { - assert_eq!(ep1, ep2); - assert_eq!(ep1.id(), ep2.id()); - assert_eq!(ep1.podcast_id(), ep2.podcast_id()); - }, - ); - } } diff --git a/hammond-data/src/models/insertables.rs b/hammond-data/src/models/insertables.rs index 972cd41..3dad2d9 100644 --- a/hammond-data/src/models/insertables.rs +++ b/hammond-data/src/models/insertables.rs @@ -113,6 +113,7 @@ impl NewPodcast { if (foo.link() != self.link) || (foo.title() != self.title) || (foo.image_uri() != self.image_uri.as_ref().map(|x| x.as_str())) { + info!("NewEpisode: {:?}\n OldEpisode: {:?}", self, foo); self.update(&con, foo.id())?; } }