2023-07-25 10:36:08 +01:00
|
|
|
mod errors;
|
2023-07-25 14:47:33 +01:00
|
|
|
pub mod feed;
|
2023-07-25 14:56:59 +01:00
|
|
|
pub mod fetch;
|
2023-07-29 19:08:52 +01:00
|
|
|
pub mod file;
|
2023-07-25 14:56:59 +01:00
|
|
|
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 feed::FeedEnv;
|
|
|
|
use fetch::FetchEnv;
|
2023-07-29 19:08:52 +01:00
|
|
|
use file::FileEnv;
|
2023-07-25 19:24:15 +01:00
|
|
|
use history::HistoryEnv;
|
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 {
|
|
|
|
pub feed: FeedEnv,
|
2023-07-29 19:38:59 +01:00
|
|
|
pub network: NetworkEnv,
|
2023-07-25 19:24:15 +01:00
|
|
|
pub history: HistoryEnv,
|
|
|
|
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<()> {
|
2023-07-29 19:23:03 +01:00
|
|
|
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:38:59 +01:00
|
|
|
let feed_url = (e.feed.find)(site, &channel_name, &e.network)?;
|
2023-07-29 19:55:37 +01:00
|
|
|
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:08:52 +01:00
|
|
|
if !(e.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)?;
|
|
|
|
(e.history.add)(&link, history)?;
|
2023-07-25 10:33:41 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
Ok(())
|
|
|
|
}
|