aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorA Farzat <a@farzat.xyz>2025-11-21 12:26:34 +0300
committerA Farzat <a@farzat.xyz>2025-11-21 12:26:34 +0300
commit6227b533cebd6c54df183289f17ad380d9539106 (patch)
treef60fa91406cd15450065ed90ab6ab6e1c1e077a0
parent031011e3e21e680b3aa528825ba805407150ef05 (diff)
downloadsimple-rss-podcast-downloader-6227b533cebd6c54df183289f17ad380d9539106.tar.gz
simple-rss-podcast-downloader-6227b533cebd6c54df183289f17ad380d9539106.zip
Move functions to lib.rs
This should make testing easier later on.
-rw-r--r--src/lib.rs37
-rw-r--r--src/main.rs38
2 files changed, 38 insertions, 37 deletions
diff --git a/src/lib.rs b/src/lib.rs
new file mode 100644
index 0000000..0459161
--- /dev/null
+++ b/src/lib.rs
@@ -0,0 +1,37 @@
+use std::env;
+use rss::Channel;
+
+/// Parse CLI arguments and return (feed_url, output_dir)
+pub fn parse_args() -> (String, String) {
+ let mut args: Vec<String> = env::args().collect();
+ if args.len() < 2 {
+ eprintln!("Usage: {} <RSS_FEED_URL> [OUTPUT_DIR]", args[0]);
+ std::process::exit(1);
+ }
+
+ let feed_url = args.remove(1);
+ let output_dir = if args.len() > 1 { args.remove(1) } else { String::from(".") };
+
+ (feed_url, output_dir)
+}
+
+/// Fetch RSS feed content from a URL
+pub fn fetch_feed(url: &str) -> Result<String, reqwest::Error> {
+ reqwest::blocking::get(url)?.text()
+}
+
+/// Parse RSS XML into a Channel
+pub fn parse_feed(xml: &str) -> Result<Channel, rss::Error> {
+ Channel::read_from(xml.as_bytes())
+}
+
+/// Extract the audio URLs from the given channel
+pub fn get_audio_urls(channel: &Channel) -> Vec<&str> {
+ let mut audio_urls = Vec::new();
+ for item in channel.items() {
+ if let Some(enclosure) = item.enclosure() {
+ audio_urls.push(enclosure.url())
+ }
+ }
+ audio_urls
+}
diff --git a/src/main.rs b/src/main.rs
index c2a7dff..82fb97e 100644
--- a/src/main.rs
+++ b/src/main.rs
@@ -1,40 +1,4 @@
-use std::env;
-use rss::Channel;
-
-/// Parse CLI arguments and return (feed_url, output_dir)
-fn parse_args() -> (String, String) {
- let mut args: Vec<String> = env::args().collect();
- if args.len() < 2 {
- eprintln!("Usage: {} <RSS_FEED_URL> [OUTPUT_DIR]", args[0]);
- std::process::exit(1);
- }
-
- let feed_url = args.remove(1);
- let output_dir = if args.len() > 1 { args.remove(1) } else { String::from(".") };
-
- (feed_url, output_dir)
-}
-
-/// Fetch RSS feed content from a URL
-fn fetch_feed(url: &str) -> Result<String, reqwest::Error> {
- reqwest::blocking::get(url)?.text()
-}
-
-/// Parse RSS XML into a Channel
-fn parse_feed(xml: &str) -> Result<Channel, rss::Error> {
- Channel::read_from(xml.as_bytes())
-}
-
-// Extract the audio URLs from the given channel
-fn get_audio_urls(channel: &Channel) -> Vec<&str> {
- let mut audio_urls = Vec::new();
- for item in channel.items() {
- if let Some(enclosure) = item.enclosure() {
- audio_urls.push(enclosure.url())
- }
- }
- audio_urls
-}
+use simple_rss_podcast_downloader::*;
fn main() {
let (feed_url, output_dir) = parse_args();