From 6227b533cebd6c54df183289f17ad380d9539106 Mon Sep 17 00:00:00 2001 From: A Farzat Date: Fri, 21 Nov 2025 12:26:34 +0300 Subject: Move functions to lib.rs This should make testing easier later on. --- src/lib.rs | 37 +++++++++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) create mode 100644 src/lib.rs (limited to 'src/lib.rs') 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 = env::args().collect(); + if args.len() < 2 { + eprintln!("Usage: {} [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 { + reqwest::blocking::get(url)?.text() +} + +/// Parse RSS XML into a Channel +pub fn parse_feed(xml: &str) -> Result { + 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 +} -- cgit v1.2.3-70-g09d2