podal/src/lib.rs

48 lines
1.2 KiB
Rust

use prelude::*;
mod errors;
pub mod feed;
pub mod file;
pub mod history;
pub mod network;
pub mod prelude;
#[cfg(test)]
mod test_utils;
use file::FileEnv;
use network::NetworkEnv;
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)? {
println!("Channel: {}", channel_name);
let feed_url = feed::find(site, &channel_name, &e.network)?;
for entry in feed::get(&feed_url, &e.network)?.entries() {
if let Some(link) = entry.links().get(0).cloned() {
if !history::find(&link, history, &e.file)? {
println!("Downloading {}: {}", &channel_name, entry.title().as_str());
(e.network.download_as_mp3)(&link.href)?;
history::add(&link, history, &e.file)?;
}
}
}
}
Ok(())
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn downloads_two_items_from_two_feeds_ignoring_existing_items_in_history() -> Result<()> {
//given
//when
//then
Ok(())
}
}