aboutsummaryrefslogtreecommitdiff
path: root/src/lib.rs
diff options
context:
space:
mode:
authorA Farzat <a@farzat.xyz>2025-11-22 10:06:02 +0300
committerA Farzat <a@farzat.xyz>2025-11-22 10:06:02 +0300
commit53724caedc8d3d3783bb701f615afd3eb8298ebb (patch)
treeb2d5b1f81c88d6364b528b407078bb792cc1684d /src/lib.rs
parenta4836871247da314110d1e42344e3239eadbdd3e (diff)
downloadsimple-rss-podcast-downloader-53724caedc8d3d3783bb701f615afd3eb8298ebb.tar.gz
simple-rss-podcast-downloader-53724caedc8d3d3783bb701f615afd3eb8298ebb.zip
Add an order argument
Diffstat (limited to 'src/lib.rs')
-rw-r--r--src/lib.rs20
1 files changed, 12 insertions, 8 deletions
diff --git a/src/lib.rs b/src/lib.rs
index 74e37b2..bb9ebee 100644
--- a/src/lib.rs
+++ b/src/lib.rs
@@ -13,14 +13,18 @@ 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<(usize, &str)> {
- channel
- .items()
- .iter()
- .rev()
- .enumerate()
- .filter_map(|(i, item)| item.enclosure().map(|e| (i + 1, e.url())))
- .collect()
+pub fn get_audio_urls(channel: &Channel, newest_first: bool) -> Vec<(usize, &str)> {
+ let iter = channel.items().iter();
+ if newest_first {
+ iter.enumerate()
+ .filter_map(|(i, item)| item.enclosure().map(|e| (i + 1, e.url())))
+ .collect()
+ } else {
+ iter.rev()
+ .enumerate()
+ .filter_map(|(i, item)| item.enclosure().map(|e| (i + 1, e.url())))
+ .collect()
+ }
}
/// Download the given audio file to the supplied directory