aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorA Farzat <a@farzat.xyz>2025-11-21 13:30:02 +0300
committerA Farzat <a@farzat.xyz>2025-11-21 13:30:02 +0300
commit43c77ec47a0c950f86d799eb7f532b18c3c783da (patch)
treed968e14402588656ab4dbbcb51be81870c5deda6
parentd921818bbb7cbecc64864a07c0e3a4098d4c5435 (diff)
downloadsimple-rss-podcast-downloader-43c77ec47a0c950f86d799eb7f532b18c3c783da.tar.gz
simple-rss-podcast-downloader-43c77ec47a0c950f86d799eb7f532b18c3c783da.zip
Reverse order to start downloading from ep1
-rw-r--r--src/lib.rs21
1 files changed, 12 insertions, 9 deletions
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<Channel, rss::Error> {
/// 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