From e1ea5a81ecccba278d4bd8568be090f92304b1d8 Mon Sep 17 00:00:00 2001 From: Paul Campbell Date: Tue, 25 Jul 2023 10:58:56 +0100 Subject: [PATCH] extract fetch --- src/fetch.rs | 21 +++++++++++++++++++++ src/lib.rs | 25 ++----------------------- 2 files changed, 23 insertions(+), 23 deletions(-) create mode 100644 src/fetch.rs diff --git a/src/fetch.rs b/src/fetch.rs new file mode 100644 index 0000000..38fd8ff --- /dev/null +++ b/src/fetch.rs @@ -0,0 +1,21 @@ +use crate::prelude::*; + +use atom_syndication::Link; + +pub fn download_audio(link: &Link) -> Result<()> { + use std::process::Command; + + let cmd = "yt-dlp"; + // println!("{} --extract-audio --audio-format mp3 {}", cmd, &link.href); + let output = Command::new(cmd) + .arg("--extract-audio") + .arg("--audio-format") + .arg("mp3") + .arg(&link.href) + .output()?; + if !output.stderr.is_empty() { + eprintln!("Error: {}", String::from_utf8(output.stderr)?); + println!("{}", String::from_utf8(output.stdout)?); + } + Ok(()) +} diff --git a/src/lib.rs b/src/lib.rs index e698fa7..15b61f6 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -1,9 +1,6 @@ -// https://www.phind.com/agent?cache=clke9xk39001cmj085upzho1t - -use atom_syndication::Link; - mod errors; mod feed; +mod fetch; mod history; pub mod prelude; mod subscriptions; @@ -19,7 +16,7 @@ pub fn run(subscriptions: &str, history: &str, site: &str) -> Result<()> { if let Some(link) = entry.links().get(0).cloned() { if !history::is_already_downloaded(&link, history)? { println!("Downloading {}: {}", &channel_name, entry.title().as_str()); - download_audio(&link)?; + fetch::download_audio(&link)?; history::mark_as_downloaded(&link, history)?; } } @@ -27,21 +24,3 @@ pub fn run(subscriptions: &str, history: &str, site: &str) -> Result<()> { } Ok(()) } - -fn download_audio(link: &Link) -> Result<()> { - use std::process::Command; - - let cmd = "yt-dlp"; - // println!("{} --extract-audio --audio-format mp3 {}", cmd, &link.href); - let output = Command::new(cmd) - .arg("--extract-audio") - .arg("--audio-format") - .arg("mp3") - .arg(&link.href) - .output()?; - if !output.stderr.is_empty() { - eprintln!("Error: {}", String::from_utf8(output.stderr)?); - println!("{}", String::from_utf8(output.stdout)?); - } - Ok(()) -}