initial commit
This commit is contained in:
47
src/main.rs
Normal file
47
src/main.rs
Normal file
@@ -0,0 +1,47 @@
|
||||
mod rss;
|
||||
mod input;
|
||||
mod download;
|
||||
|
||||
use std::fs;
|
||||
|
||||
use anyhow::Context;
|
||||
|
||||
fn main() -> anyhow::Result<()> {
|
||||
|
||||
let args = {
|
||||
use clap::Parser;
|
||||
input::Args::parse()
|
||||
};
|
||||
|
||||
let config : input::Config = {
|
||||
let config = fs::read_to_string(&args.config)
|
||||
.with_context(|| "failed to read in podcast configuration file")?;
|
||||
|
||||
toml::from_str(&config[..])?
|
||||
};
|
||||
|
||||
let config_path = args.config.canonicalize()?;
|
||||
let Some(root) = config_path.parent() else {
|
||||
anyhow::bail!("could not get parent of configuration path for root directory")
|
||||
};
|
||||
|
||||
// Updating single podcast
|
||||
if let Some(alias) = args.podcast {
|
||||
if let Some(feed_url) = config.podcasts.get(&alias) {
|
||||
download::update_podcast(&alias, root, feed_url)?;
|
||||
}
|
||||
else {
|
||||
anyhow::bail!(r#"podcast "{}" not found in configuration file"#, alias)
|
||||
}
|
||||
}
|
||||
// Updating all podcasts
|
||||
else {
|
||||
for (alias, feed_url) in config.podcasts {
|
||||
download::update_podcast(&alias, root, &feed_url)?;
|
||||
}
|
||||
}
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user