podal/src/lib.rs

39 lines
1 KiB
Rust
Raw Normal View History

2023-07-25 10:36:08 +01:00
mod errors;
pub mod feed;
pub mod fetch;
pub mod history;
2023-07-25 10:46:47 +01:00
pub mod prelude;
2023-07-25 10:57:19 +01:00
mod subscriptions;
2023-07-25 10:33:41 +01:00
use feed::{FeedFind, FeedGet};
use fetch::FetchDownload;
use history::{HistoryAdd, HistoryFind};
2023-07-25 10:46:47 +01:00
use prelude::*;
2023-07-25 10:33:41 +01:00
pub fn run(
subscriptions: &str,
history: &str,
site: &str,
feed_find: FeedFind,
feed_get: FeedGet,
history_find: HistoryFind,
history_add: HistoryAdd,
fetch_download: FetchDownload,
) -> Result<()> {
2023-07-25 10:57:19 +01:00
for channel_name in subscriptions::lines_from(subscriptions)? {
2023-07-25 10:33:41 +01:00
let channel_name = channel_name?;
println!("Channel: {}", channel_name);
let feed_url = feed_find(site, &channel_name)?;
for entry in feed_get(&feed_url)?.entries() {
2023-07-25 10:50:31 +01:00
if let Some(link) = entry.links().get(0).cloned() {
if !history_find(&link, history)? {
2023-07-25 10:33:41 +01:00
println!("Downloading {}: {}", &channel_name, entry.title().as_str());
fetch_download(&link)?;
history_add(&link, history)?;
2023-07-25 10:33:41 +01:00
}
}
}
}
Ok(())
}