initial commit

This commit is contained in:
aaron-jack-manning
2024-01-11 17:30:55 +11:00
commit dd04b9f29f
9 changed files with 1849 additions and 0 deletions

47
src/main.rs Normal file
View 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(())
}