aboutsummaryrefslogtreecommitdiff
path: root/src/lib.rs
diff options
context:
space:
mode:
authorA Farzat <a@farzat.xyz>2025-11-21 13:00:21 +0300
committerA Farzat <a@farzat.xyz>2025-11-21 13:00:21 +0300
commitc41059e398f5499376e41b898aed35ed5054d50a (patch)
tree2644eed662d236bac6cbb99a9debb14dce577d30 /src/lib.rs
parent6227b533cebd6c54df183289f17ad380d9539106 (diff)
downloadsimple-rss-podcast-downloader-c41059e398f5499376e41b898aed35ed5054d50a.tar.gz
simple-rss-podcast-downloader-c41059e398f5499376e41b898aed35ed5054d50a.zip
Add file download functionality
Diffstat (limited to 'src/lib.rs')
-rw-r--r--src/lib.rs13
1 files changed, 13 insertions, 0 deletions
diff --git a/src/lib.rs b/src/lib.rs
index 0459161..d54d12e 100644
--- a/src/lib.rs
+++ b/src/lib.rs
@@ -1,4 +1,6 @@
use std::env;
+use std::fs::File;
+use std::path::PathBuf;
use rss::Channel;
/// Parse CLI arguments and return (feed_url, output_dir)
@@ -35,3 +37,14 @@ pub fn get_audio_urls(channel: &Channel) -> Vec<&str> {
}
audio_urls
}
+
+/// Download the given audio file to the supplied directory
+pub fn download_file(url: &str, output_dir: &str) -> Result<(), Box<dyn std::error::Error>> {
+ let mut response = reqwest::blocking::get(url)?;
+ let filename = url.split('/').next_back().unwrap_or("episode.mp3");
+ let mut path = PathBuf::from(output_dir);
+ path.push(filename);
+ let mut file = File::create(path)?;
+ std::io::copy(&mut response, &mut file)?;
+ Ok(())
+}