Minor readability imprvments.
This commit is contained in:
parent
90c637ed53
commit
24d088ffc3
@ -8,12 +8,13 @@ use models;
|
|||||||
// TODO: Extend the support for parsing itunes extensions
|
// TODO: Extend the support for parsing itunes extensions
|
||||||
pub fn parse_podcast(chan: &Channel, source_id: i32) -> models::NewPodcast {
|
pub fn parse_podcast(chan: &Channel, source_id: i32) -> models::NewPodcast {
|
||||||
let title = chan.title().trim().to_owned();
|
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();
|
let description = chan.description().trim().to_owned();
|
||||||
// Some feeds miss baseurl and/or http://
|
// Some feeds miss baseurl and/or http://
|
||||||
// TODO: Sanitize the url,
|
// TODO: Sanitize the url,
|
||||||
// could also be reuse to sanitize the new-url gui entrybox.
|
// 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())
|
img.map(|s| s.to_string())
|
||||||
} else {
|
} else {
|
||||||
chan.image().map(|foo| foo.url().to_owned())
|
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.
|
// Rss 2.0 specified that it's optional.
|
||||||
// Though the db scema has a requirment of episode uri being Unique && Not Null.
|
// Though the db scema has a requirment of episode uri being Unique && Not Null.
|
||||||
// TODO: Restructure
|
// TODO: Restructure
|
||||||
let uri = if item.enclosure().map(|x| x.url().trim()).is_some() {
|
let x = item.enclosure().map(|x| x.url().trim());
|
||||||
item.enclosure().map(|x| x.url().trim())
|
let uri = if x.is_some() {
|
||||||
|
x
|
||||||
} else if item.link().is_some() {
|
} else if item.link().is_some() {
|
||||||
item.link()
|
item.link()
|
||||||
} else {
|
} else {
|
||||||
|
|||||||
@ -62,7 +62,6 @@ pub fn latest_dl(connection: &SqliteConnection, limit: u32) -> Result<()> {
|
|||||||
let pds = dbqueries::get_podcasts(connection)?;
|
let pds = dbqueries::get_podcasts(connection)?;
|
||||||
|
|
||||||
let _: Vec<_> = pds.iter()
|
let _: Vec<_> = pds.iter()
|
||||||
// This could be for_each instead of map.
|
|
||||||
.map(|x| -> Result<()> {
|
.map(|x| -> Result<()> {
|
||||||
let mut eps = if limit == 0 {
|
let mut eps = if limit == 0 {
|
||||||
dbqueries::get_pd_episodes(connection, x)?
|
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())?;
|
let dl_fold = get_dl_folder(x.title())?;
|
||||||
|
|
||||||
// Download the episodes
|
// Download the episodes
|
||||||
let _ :Vec<_> = eps.iter_mut()
|
eps.iter_mut().for_each(|ep| {
|
||||||
.map(|ep| -> Result<()> {
|
let x = get_episode(connection, ep, &dl_fold);
|
||||||
// TODO: handle Result here and replace map with for_each
|
if let Err(err) = x {
|
||||||
get_episode(connection, ep, &dl_fold)
|
error!("An Error occured while downloading an episode.");
|
||||||
})
|
error!("Error: {}", err);
|
||||||
.collect();
|
};
|
||||||
|
});
|
||||||
|
|
||||||
Ok(())
|
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);
|
let dl_fold = format!("{}/{}", DL_DIR.to_str().unwrap(), pd_title);
|
||||||
|
|
||||||
// Create the folder
|
// Create the folder
|
||||||
// TODO: handle the unwrap properly
|
|
||||||
DirBuilder::new().recursive(true).create(&dl_fold)?;
|
DirBuilder::new().recursive(true).create(&dl_fold)?;
|
||||||
Ok(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)?;
|
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();
|
let ext = ep.uri().split('.').last().unwrap().to_owned();
|
||||||
|
|
||||||
// Construct the download path.
|
// Construct the download path.
|
||||||
@ -148,11 +147,11 @@ pub fn cache_image(title: &str, image_uri: Option<&str>) -> Option<String> {
|
|||||||
return None;
|
return None;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// FIXME:
|
||||||
let ext = url.split('.').last().unwrap();
|
let ext = url.split('.').last().unwrap();
|
||||||
|
|
||||||
let dl_fold = format!("{}{}", HAMMOND_CACHE.to_str().unwrap(), title);
|
let dl_fold = format!("{}{}", HAMMOND_CACHE.to_str().unwrap(), title);
|
||||||
DirBuilder::new().recursive(true).create(&dl_fold).unwrap();
|
DirBuilder::new().recursive(true).create(&dl_fold).unwrap();
|
||||||
|
|
||||||
let dlpath = format!("{}/{}.{}", dl_fold, title, ext);
|
let dlpath = format!("{}/{}.{}", dl_fold, title, ext);
|
||||||
|
|
||||||
if Path::new(&dlpath).exists() {
|
if Path::new(&dlpath).exists() {
|
||||||
|
|||||||
@ -65,7 +65,6 @@ pub fn get_headerbar(db: &Arc<Mutex<SqliteConnection>>, stack: >k::Stack) -> g
|
|||||||
let db_clone = db.clone();
|
let db_clone = db.clone();
|
||||||
// FIXME: There appears to be a memmory leak here.
|
// FIXME: There appears to be a memmory leak here.
|
||||||
refresh_button.connect_clicked(move |_| {
|
refresh_button.connect_clicked(move |_| {
|
||||||
// fsdaa, The things I do for the borrow checker.
|
|
||||||
utils::refresh_db(&db_clone, &stack_clone);
|
utils::refresh_db(&db_clone, &stack_clone);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
@ -95,8 +95,8 @@ pub fn setup_stack(db: &Arc<Mutex<SqliteConnection>>) -> gtk::Stack {
|
|||||||
// let _st_clone = stack.clone();
|
// let _st_clone = stack.clone();
|
||||||
setup_podcast_widget(&db, &stack);
|
setup_podcast_widget(&db, &stack);
|
||||||
setup_podcasts_grid(&db, &stack);
|
setup_podcasts_grid(&db, &stack);
|
||||||
// stack.connect("foo", true, move |_| {
|
// stack.connect("update_grid", true, move |_| {
|
||||||
// update_podcasts_view(db.clone(), st_clone.clone());
|
// update_podcasts_view(&db_clone, &st_clone);
|
||||||
// None
|
// None
|
||||||
// });
|
// });
|
||||||
stack
|
stack
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user