From 24d088ffc371e47b2b4503bcac546ab8975e9ad9 Mon Sep 17 00:00:00 2001 From: Jordan Petridis Date: Sat, 21 Oct 2017 18:56:18 +0300 Subject: [PATCH] Minor readability imprvments. --- hammond-data/src/feedparser.rs | 10 ++++++---- hammond-downloader/src/downloader.rs | 19 +++++++++---------- hammond-gtk/src/headerbar.rs | 1 - hammond-gtk/src/views/podcasts_view.rs | 4 ++-- 4 files changed, 17 insertions(+), 17 deletions(-) diff --git a/hammond-data/src/feedparser.rs b/hammond-data/src/feedparser.rs index adfc4f4..4614311 100644 --- a/hammond-data/src/feedparser.rs +++ b/hammond-data/src/feedparser.rs @@ -8,12 +8,13 @@ use models; // TODO: Extend the support for parsing itunes extensions pub fn parse_podcast(chan: &Channel, source_id: i32) -> models::NewPodcast { let title = chan.title().trim().to_owned(); - let link = chan.link().to_owned(); + let link = chan.link().trim().to_owned(); let description = chan.description().trim().to_owned(); // Some feeds miss baseurl and/or http:// // TODO: Sanitize the url, // could also be reuse to sanitize the new-url gui entrybox. - let image_uri = if let Some(img) = chan.itunes_ext().map(|s| s.image()) { + let x = chan.itunes_ext().map(|s| s.image()); + let image_uri = if let Some(img) = x { img.map(|s| s.to_string()) } else { chan.image().map(|foo| foo.url().to_owned()) @@ -38,8 +39,9 @@ pub fn parse_episode(item: &Item, parent_id: i32) -> models::NewEpisode { // Rss 2.0 specified that it's optional. // Though the db scema has a requirment of episode uri being Unique && Not Null. // TODO: Restructure - let uri = if item.enclosure().map(|x| x.url().trim()).is_some() { - item.enclosure().map(|x| x.url().trim()) + let x = item.enclosure().map(|x| x.url().trim()); + let uri = if x.is_some() { + x } else if item.link().is_some() { item.link() } else { diff --git a/hammond-downloader/src/downloader.rs b/hammond-downloader/src/downloader.rs index 57b41d0..9d9f784 100644 --- a/hammond-downloader/src/downloader.rs +++ b/hammond-downloader/src/downloader.rs @@ -62,7 +62,6 @@ pub fn latest_dl(connection: &SqliteConnection, limit: u32) -> Result<()> { let pds = dbqueries::get_podcasts(connection)?; let _: Vec<_> = pds.iter() - // This could be for_each instead of map. .map(|x| -> Result<()> { let mut eps = if limit == 0 { dbqueries::get_pd_episodes(connection, x)? @@ -73,12 +72,13 @@ pub fn latest_dl(connection: &SqliteConnection, limit: u32) -> Result<()> { let dl_fold = get_dl_folder(x.title())?; // Download the episodes - let _ :Vec<_> = eps.iter_mut() - .map(|ep| -> Result<()> { - // TODO: handle Result here and replace map with for_each - get_episode(connection, ep, &dl_fold) - }) - .collect(); + eps.iter_mut().for_each(|ep| { + let x = get_episode(connection, ep, &dl_fold); + if let Err(err) = x { + error!("An Error occured while downloading an episode."); + error!("Error: {}", err); + }; + }); Ok(()) }) @@ -93,7 +93,6 @@ pub fn get_dl_folder(pd_title: &str) -> Result { let dl_fold = format!("{}/{}", DL_DIR.to_str().unwrap(), pd_title); // Create the folder - // TODO: handle the unwrap properly DirBuilder::new().recursive(true).create(&dl_fold)?; Ok(dl_fold) } @@ -108,7 +107,7 @@ pub fn get_episode(connection: &SqliteConnection, ep: &mut Episode, dl_folder: & ep.save_changes::(connection)?; }; - // Unreliable and hacky way to extract the file extension from the url. + // FIXME: Unreliable and hacky way to extract the file extension from the url. let ext = ep.uri().split('.').last().unwrap().to_owned(); // Construct the download path. @@ -148,11 +147,11 @@ pub fn cache_image(title: &str, image_uri: Option<&str>) -> Option { return None; } + // FIXME: let ext = url.split('.').last().unwrap(); let dl_fold = format!("{}{}", HAMMOND_CACHE.to_str().unwrap(), title); DirBuilder::new().recursive(true).create(&dl_fold).unwrap(); - let dlpath = format!("{}/{}.{}", dl_fold, title, ext); if Path::new(&dlpath).exists() { diff --git a/hammond-gtk/src/headerbar.rs b/hammond-gtk/src/headerbar.rs index 80182df..ddd485d 100644 --- a/hammond-gtk/src/headerbar.rs +++ b/hammond-gtk/src/headerbar.rs @@ -65,7 +65,6 @@ pub fn get_headerbar(db: &Arc>, stack: >k::Stack) -> g let db_clone = db.clone(); // FIXME: There appears to be a memmory leak here. refresh_button.connect_clicked(move |_| { - // fsdaa, The things I do for the borrow checker. utils::refresh_db(&db_clone, &stack_clone); }); diff --git a/hammond-gtk/src/views/podcasts_view.rs b/hammond-gtk/src/views/podcasts_view.rs index d6c3a99..18a0ff9 100644 --- a/hammond-gtk/src/views/podcasts_view.rs +++ b/hammond-gtk/src/views/podcasts_view.rs @@ -95,8 +95,8 @@ pub fn setup_stack(db: &Arc>) -> gtk::Stack { // let _st_clone = stack.clone(); setup_podcast_widget(&db, &stack); setup_podcasts_grid(&db, &stack); - // stack.connect("foo", true, move |_| { - // update_podcasts_view(db.clone(), st_clone.clone()); + // stack.connect("update_grid", true, move |_| { + // update_podcasts_view(&db_clone, &st_clone); // None // }); stack