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;
2023-07-29 19:08:52 +01:00
pub mod file;
pub mod history;
2023-07-29 19:38:59 +01:00
pub mod network;
2023-07-25 10:46:47 +01:00
pub mod prelude;
2023-07-25 10:33:41 +01:00
2023-07-27 21:20:32 +01:00
#[cfg(test)]
mod test_utils;
2023-07-25 19:24:15 +01:00
use fetch::FetchEnv;
2023-07-29 19:08:52 +01:00
use file::FileEnv;
2023-07-29 19:38:59 +01:00
use network::NetworkEnv;
2023-07-25 10:46:47 +01:00
use prelude::*;
2023-07-25 10:33:41 +01:00
2023-07-25 19:24:15 +01:00
pub struct Env {
2023-07-29 19:38:59 +01:00
pub network: NetworkEnv,
2023-07-25 19:24:15 +01:00
pub fetch: FetchEnv,
2023-07-29 19:08:52 +01:00
pub file: FileEnv,
2023-07-25 19:24:15 +01:00
}
pub fn run(subscriptions: &str, history: &str, site: &str, e: Env) -> Result<()> {
for channel_name in file::read::lines_from(subscriptions, &e.file)? {
2023-07-25 10:33:41 +01:00
println!("Channel: {}", channel_name);
2023-07-29 19:59:16 +01:00
let feed_url = feed::find(site, &channel_name, &e.network)?;
for entry in feed::get(&feed_url, &e.network)?.entries() {
2023-07-25 10:50:31 +01:00
if let Some(link) = entry.links().get(0).cloned() {
2023-07-29 19:59:16 +01:00
if !history::find(&link, history, &e.file)? {
2023-07-25 10:33:41 +01:00
println!("Downloading {}: {}", &channel_name, entry.title().as_str());
2023-07-25 19:24:15 +01:00
(e.fetch.download)(&link)?;
2023-07-29 20:13:28 +01:00
history::add(&link, history, &e.file)?;
2023-07-25 10:33:41 +01:00
}
}
}
}
Ok(())
}