diff --git a/hammond-downloader/src/downloader.rs b/hammond-downloader/src/downloader.rs index b19de6c..97b1752 100644 --- a/hammond-downloader/src/downloader.rs +++ b/hammond-downloader/src/downloader.rs @@ -38,24 +38,7 @@ fn download_into(dir: &str, file_title: &str, url: &str) -> Result { ct_len.map(|x| info!("File Lenght: {}", x)); ct_type.map(|x| info!("Content Type: {}", x)); - // This could be prettier. - // Determine the file extension from the http content-type header. - let ext = if let Some(t) = ct_type { - let mime = mime_guess::get_extensions(t.type_().as_ref(), t.subtype().as_ref()); - if let Some(m) = mime { - if m.contains(&t.subtype().as_ref()) { - t.subtype().as_ref().to_string() - } else { - m.first().unwrap().to_string() - } - } else { - error!("Unkown mime type. {}", t); - "unkown".to_string() - } - } else { - error!("Unkown mime type."); - "unkown".to_string() - }; + let ext = get_ext(ct_type.cloned()).unwrap_or(String::from("unkown")); info!("Extension: {}", ext); // Construct a temp file to save desired content. @@ -74,6 +57,19 @@ fn download_into(dir: &str, file_title: &str, url: &str) -> Result { Ok(target) } +// Determine the file extension from the http content-type header. +fn get_ext(content: Option) -> Option { + let cont = content.clone()?; + content.and_then(|c| mime_guess::get_extensions(c.type_().as_ref(), c.subtype().as_ref())) + .and_then(|c| { + if c.contains(&cont.subtype().as_ref()) { + Some(cont.subtype().as_ref().to_string()) + } else { + Some(c.first().unwrap().to_string()) + } + }) +} + // TODO: Write unit-tests. /// Handles the I/O of fetching a remote file and saving into a Buffer and A File. fn save_io(file: &str, resp: &mut reqwest::Response, content_lenght: Option) -> Result<()> { diff --git a/hammond-gtk/src/content.rs b/hammond-gtk/src/content.rs index 2d91541..0783f8c 100644 --- a/hammond-gtk/src/content.rs +++ b/hammond-gtk/src/content.rs @@ -1,8 +1,6 @@ use gtk; use gtk::prelude::*; -// use gdk_pixbuf::Pixbuf; -// use diesel::associations::Identifiable; use hammond_data::Podcast; use widgets::podcast::PodcastWidget; @@ -89,6 +87,7 @@ fn replace_podcasts(stack: >k::Stack, pop: &PopulatedView) { // old.destroy(); // } +#[allow(dead_code)] pub fn show_widget(stack: >k::Stack) { stack.set_visible_child_name("widget") }