From 43c77ec47a0c950f86d799eb7f532b18c3c783da Mon Sep 17 00:00:00 2001 From: A Farzat Date: Fri, 21 Nov 2025 13:30:02 +0300 Subject: Reverse order to start downloading from ep1 --- src/lib.rs | 21 ++++++++++++--------- 1 file changed, 12 insertions(+), 9 deletions(-) (limited to 'src') diff --git a/src/lib.rs b/src/lib.rs index d54d12e..12a27e6 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -1,7 +1,7 @@ +use rss::Channel; use std::env; use std::fs::File; use std::path::PathBuf; -use rss::Channel; /// Parse CLI arguments and return (feed_url, output_dir) pub fn parse_args() -> (String, String) { @@ -12,7 +12,11 @@ pub fn parse_args() -> (String, String) { } let feed_url = args.remove(1); - let output_dir = if args.len() > 1 { args.remove(1) } else { String::from(".") }; + let output_dir = if args.len() > 1 { + args.remove(1) + } else { + String::from(".") + }; (feed_url, output_dir) } @@ -29,13 +33,12 @@ pub fn parse_feed(xml: &str) -> Result { /// 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 + channel + .items() + .iter() + .rev() + .filter_map(|item| item.enclosure().map(|e| e.url())) + .collect() } /// Download the given audio file to the supplied directory -- cgit v1.2.3-70-g09d2