Minor readability imprvments.

This commit is contained in:
Jordan Petridis 2017-10-21 18:56:18 +03:00
parent 90c637ed53
commit 24d088ffc3
No known key found for this signature in database
GPG Key ID: CEABAD9F5683B9A6
4 changed files with 17 additions and 17 deletions

View File

@ -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 {

View File

@ -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<String> {
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::<Episode>(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<String> {
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() {

View File

@ -65,7 +65,6 @@ pub fn get_headerbar(db: &Arc<Mutex<SqliteConnection>>, stack: &gtk::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);
});

View File

@ -95,8 +95,8 @@ pub fn setup_stack(db: &Arc<Mutex<SqliteConnection>>) -> 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