From a60999785b5375b6302a313a8f872f122609ec29 Mon Sep 17 00:00:00 2001 From: Paul Campbell Date: Tue, 25 Jul 2023 10:55:02 +0100 Subject: [PATCH] extract history::add --- src/history/add.rs | 17 +++++++++++++++++ src/history/mod.rs | 2 ++ src/lib.rs | 17 +---------------- 3 files changed, 20 insertions(+), 16 deletions(-) create mode 100644 src/history/add.rs diff --git a/src/history/add.rs b/src/history/add.rs new file mode 100644 index 0000000..e186644 --- /dev/null +++ b/src/history/add.rs @@ -0,0 +1,17 @@ +use crate::prelude::*; + +use atom_syndication::Link; +use std::fs::OpenOptions; +use std::io::prelude::*; + +pub fn mark_as_downloaded(link: &Link, file_name: &str) -> Result<()> { + let mut file = OpenOptions::new() + .write(true) + .append(true) + .create(true) + .open(file_name) + .unwrap(); + + writeln!(file, "{}", link.href)?; + Ok(()) +} diff --git a/src/history/mod.rs b/src/history/mod.rs index 8bdd517..87d3186 100644 --- a/src/history/mod.rs +++ b/src/history/mod.rs @@ -1,3 +1,5 @@ +mod add; mod find; +pub use add::mark_as_downloaded; pub use find::is_already_downloaded; diff --git a/src/lib.rs b/src/lib.rs index 3f486ad..c98b471 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -21,7 +21,7 @@ pub fn run(subscriptions: &str, history: &str, site: &str) -> Result<()> { if !history::is_already_downloaded(&link, history)? { println!("Downloading {}: {}", &channel_name, entry.title().as_str()); download_audio(&link)?; - mark_as_downloaded(&link, history)?; + history::mark_as_downloaded(&link, history)?; } } } @@ -55,18 +55,3 @@ fn download_audio(link: &Link) -> Result<()> { } Ok(()) } - -fn mark_as_downloaded(link: &Link, file_name: &str) -> Result<()> { - use std::fs::OpenOptions; - use std::io::prelude::*; - - let mut file = OpenOptions::new() - .write(true) - .append(true) - .create(true) - .open(file_name) - .unwrap(); - - writeln!(file, "{}", link.href)?; - Ok(()) -}