diff options
| author | A Farzat <a@farzat.xyz> | 2025-11-22 07:52:55 +0300 |
|---|---|---|
| committer | A Farzat <a@farzat.xyz> | 2025-11-22 07:52:55 +0300 |
| commit | a4836871247da314110d1e42344e3239eadbdd3e (patch) | |
| tree | e304c645f23d3d34e5673794b160dabec7872050 /src/lib.rs | |
| parent | db713f8e215b2c349e4eaf0fa4791b876125148b (diff) | |
| download | simple-rss-podcast-downloader-a4836871247da314110d1e42344e3239eadbdd3e.tar.gz simple-rss-podcast-downloader-a4836871247da314110d1e42344e3239eadbdd3e.zip | |
Add optional numbering of downloaded episodes
Diffstat (limited to 'src/lib.rs')
| -rw-r--r-- | src/lib.rs | 16 |
1 files changed, 13 insertions, 3 deletions
@@ -13,19 +13,29 @@ 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> { +pub fn get_audio_urls(channel: &Channel) -> Vec<(usize, &str)> { channel .items() .iter() .rev() - .filter_map(|item| item.enclosure().map(|e| e.url())) + .enumerate() + .filter_map(|(i, item)| item.enclosure().map(|e| (i + 1, e.url()))) .collect() } /// Download the given audio file to the supplied directory -pub fn download_file(url: &str, output_dir: &str) -> Result<(), Box<dyn std::error::Error>> { +pub fn download_file( + url: &str, + output_dir: &str, + prefix: Option<&str>, +) -> Result<(), Box<dyn std::error::Error>> { let mut response = reqwest::blocking::get(url)?; let filename = url.split('/').next_back().unwrap_or("episode.mp3"); + let filename = if let Some(p) = prefix { + format!("{}-{}", p, filename) + } else { + filename.to_string() + }; let mut path = PathBuf::from(output_dir); path.push(filename); let mut file = File::create(path)?; |
