play status with corresponding commands
This commit is contained in:
69
src/main.rs
69
src/main.rs
@@ -2,9 +2,12 @@ mod rss;
|
||||
mod input;
|
||||
mod download;
|
||||
|
||||
use input::{Command, ListenStatus};
|
||||
|
||||
use std::fs;
|
||||
|
||||
use anyhow::Context;
|
||||
use sanitise_file_name::sanitise;
|
||||
|
||||
fn main() -> anyhow::Result<()> {
|
||||
|
||||
@@ -25,23 +28,59 @@ fn main() -> anyhow::Result<()> {
|
||||
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)?;
|
||||
}
|
||||
}
|
||||
|
||||
match args.command {
|
||||
Command::Download { podcast } => {
|
||||
// Updating single podcast
|
||||
if let Some(alias) = 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)?;
|
||||
}
|
||||
}
|
||||
},
|
||||
Command::List { status, podcast } => {
|
||||
let output = root.join(sanitise(&podcast));
|
||||
let spec_file = output.join("spec.toml");
|
||||
|
||||
let spec = download::Specification::read_from(&spec_file)?;
|
||||
|
||||
for (_, episodes) in spec.feed_iter() {
|
||||
for episode in episodes {
|
||||
if status.is_none()
|
||||
|| (episode.listened && status.is_some_and(|x| x == ListenStatus::Listened))
|
||||
|| (!episode.listened && status.is_some_and(|x| x == ListenStatus::Unlistened)) {
|
||||
println!("{}", episode.title())
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
Command::Mark { status, podcast } => {
|
||||
let output = root.join(sanitise(&podcast));
|
||||
let spec_file = output.join("spec.toml");
|
||||
|
||||
let mut spec = download::Specification::read_from(&spec_file)?;
|
||||
|
||||
for (_, episodes) in spec.feed_iter_mut() {
|
||||
for episode in episodes {
|
||||
episode.listened = status == ListenStatus::Listened;
|
||||
}
|
||||
}
|
||||
|
||||
spec.write_to(&spec_file)?;
|
||||
},
|
||||
};
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user