podal/src/lib.rs

37 lines
996 B
Rust
Raw Normal View History

use prelude::*;
2023-07-25 10:36:08 +01:00
mod errors;
pub mod feed;
pub mod file;
pub mod history;
pub mod network;
2023-07-25 10:46:47 +01:00
pub mod prelude;
2023-07-25 10:33:41 +01:00
#[cfg(test)]
mod test_utils;
use file::FileEnv;
use network::NetworkEnv;
2023-07-25 10:33:41 +01:00
pub struct Env {
pub network: NetworkEnv,
pub file: FileEnv,
}
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);
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() {
if !history::find(&link, history, &e.file)? {
2023-07-25 10:33:41 +01:00
println!("Downloading {}: {}", &channel_name, entry.title().as_str());
(e.network.download_as_mp3)(&link.href)?;
history::add(&link, history, &e.file)?;
2023-07-25 10:33:41 +01:00
}
}
}
}
Ok(())
}