inline get_link function

This commit is contained in:
Paul Campbell 2023-07-25 10:50:31 +01:00
parent 0b6903404a
commit 05f7258978

View file

@ -2,7 +2,7 @@
use std::fs::File; use std::fs::File;
use atom_syndication::{Entry, Link}; use atom_syndication::Link;
mod errors; mod errors;
mod feed; mod feed;
@ -16,7 +16,7 @@ pub fn run(subscriptions: &str, history: &str, site: &str) -> Result<()> {
println!("Channel: {}", channel_name); println!("Channel: {}", channel_name);
let feed_url = feed::get_feed_url(site, &channel_name)?; let feed_url = feed::get_feed_url(site, &channel_name)?;
for entry in feed::get_feed(feed_url)?.entries() { for entry in feed::get_feed(feed_url)?.entries() {
if let Some(link) = get_link(entry) { if let Some(link) = entry.links().get(0).cloned() {
if !is_already_downloaded(&link, history)? { if !is_already_downloaded(&link, history)? {
println!("Downloading {}: {}", &channel_name, entry.title().as_str()); println!("Downloading {}: {}", &channel_name, entry.title().as_str());
download_audio(&link)?; download_audio(&link)?;
@ -28,10 +28,6 @@ pub fn run(subscriptions: &str, history: &str, site: &str) -> Result<()> {
Ok(()) Ok(())
} }
fn get_link(item: &Entry) -> Option<Link> {
item.links().get(0).cloned()
}
// read list of rss feed URLs from file 'feeds.txt' // read list of rss feed URLs from file 'feeds.txt'
fn lines_from(file_name: &str) -> Result<std::io::Lines<std::io::BufReader<std::fs::File>>> { fn lines_from(file_name: &str) -> Result<std::io::Lines<std::io::BufReader<std::fs::File>>> {
use std::io::{BufRead, BufReader}; use std::io::{BufRead, BufReader};