2024-01-11 17:30:55 +11:00
|
|
|
use std::path;
|
2025-09-21 09:07:18 +10:00
|
|
|
use std::collections::BTreeMap;
|
2024-01-11 17:30:55 +11:00
|
|
|
|
|
|
|
|
#[derive(clap::Parser)]
|
2025-08-29 21:46:22 +10:00
|
|
|
pub(crate) struct Args {
|
2024-01-11 17:30:55 +11:00
|
|
|
/// Path to the configuration file listing podcast RSS feeds.
|
|
|
|
|
#[arg(default_value = "./podcasts.toml")]
|
2025-08-29 21:46:22 +10:00
|
|
|
pub(crate) config: path::PathBuf,
|
2024-11-18 21:44:36 +11:00
|
|
|
#[command(subcommand)]
|
2025-08-29 21:46:22 +10:00
|
|
|
pub(crate) command: Command,
|
2024-11-18 21:44:36 +11:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#[derive(clap::ValueEnum, Copy, Clone, Debug,PartialEq, Eq, PartialOrd, Ord)]
|
2025-08-29 21:46:22 +10:00
|
|
|
pub(crate) enum ListenStatus {
|
2024-11-18 21:44:36 +11:00
|
|
|
Listened,
|
|
|
|
|
Unlistened,
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#[derive(clap::Subcommand)]
|
2025-08-29 21:46:22 +10:00
|
|
|
pub(crate) enum Command {
|
2024-11-18 21:44:36 +11:00
|
|
|
/// Updates feed and downloads latest episodes.
|
|
|
|
|
Download {
|
|
|
|
|
/// The podcast to update. Updates all in configuration file if unspecified.
|
|
|
|
|
#[arg(long, short)]
|
2025-08-29 21:46:22 +10:00
|
|
|
podcast: Option<String>,
|
2024-11-18 21:44:36 +11:00
|
|
|
},
|
|
|
|
|
/// Lists the episodes for a given podcast, filtered based on if it has been listened or not.
|
|
|
|
|
List {
|
|
|
|
|
/// Filter for if episodes have been listened to or not.
|
|
|
|
|
#[arg(long, short)]
|
2025-08-29 21:46:22 +10:00
|
|
|
status: Option<ListenStatus>,
|
2024-11-18 21:44:36 +11:00
|
|
|
/// The podcast to list episodes for.
|
|
|
|
|
#[arg(long, short)]
|
2025-08-29 21:46:22 +10:00
|
|
|
podcast: String,
|
2024-11-18 21:44:36 +11:00
|
|
|
},
|
|
|
|
|
/// Marks an entire podcast's history of episodes as played or unplayed.
|
|
|
|
|
Mark {
|
|
|
|
|
/// The new listen status for the episodes.
|
|
|
|
|
#[arg(long, short)]
|
2025-08-29 21:46:22 +10:00
|
|
|
status: ListenStatus,
|
2024-11-18 21:44:36 +11:00
|
|
|
/// The podcast to change the listen status of.
|
|
|
|
|
#[arg(long, short)]
|
2025-08-29 21:46:22 +10:00
|
|
|
podcast: String,
|
2024-11-18 21:44:36 +11:00
|
|
|
},
|
2025-09-01 09:42:15 +10:00
|
|
|
/// Generates playlist for use with an iPod.
|
|
|
|
|
Playlist {
|
|
|
|
|
/// The podcast to generate the playlist for.
|
2025-08-29 21:33:20 +10:00
|
|
|
#[arg(long, short)]
|
2025-08-29 21:46:22 +10:00
|
|
|
podcast: Option<String>,
|
2025-08-29 21:33:20 +10:00
|
|
|
},
|
2025-09-21 09:07:18 +10:00
|
|
|
/// Syncs local copy of podcasts to Rockbox iPod.
|
|
|
|
|
Sync {
|
|
|
|
|
/// Directory to the root of the iPod running Rockbox.
|
|
|
|
|
ipod_dir: path::PathBuf,
|
|
|
|
|
/// Download any new episodes before syncing.
|
|
|
|
|
#[clap(short, long)]
|
|
|
|
|
download: bool,
|
|
|
|
|
},
|
2024-01-11 17:30:55 +11:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// Struct modelling configuration file format.
|
|
|
|
|
#[derive(serde::Deserialize)]
|
2025-08-29 21:46:22 +10:00
|
|
|
pub(crate) struct Config {
|
2024-01-11 17:30:55 +11:00
|
|
|
/// Map from podcast alias to RSS feed either as a url (prefix: http) or file path.
|
2025-09-21 09:07:18 +10:00
|
|
|
pub(crate) podcasts: BTreeMap<String, Source>,
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#[derive(serde::Deserialize)]
|
|
|
|
|
#[serde(untagged)]
|
|
|
|
|
pub(crate) enum Source {
|
|
|
|
|
String(String),
|
|
|
|
|
Object {
|
|
|
|
|
source: String,
|
|
|
|
|
#[serde(rename = "skip-download")]
|
|
|
|
|
skip_download: bool,
|
|
|
|
|
},
|
2024-01-11 17:30:55 +11:00
|
|
|
}
|
|
|
|
|
|
2025-09-21 09:07:18 +10:00
|
|
|
impl Source {
|
|
|
|
|
pub(crate) fn source_raw(&self) -> &str {
|
|
|
|
|
match self {
|
|
|
|
|
Self::String(source) | Self::Object { source, .. } => source,
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
pub(crate) fn skip_download(&self) -> bool {
|
|
|
|
|
match self {
|
|
|
|
|
Self::String(_) => false,
|
|
|
|
|
Self::Object { skip_download, .. } => *skip_download,
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
fn is_url(&self) -> bool {
|
|
|
|
|
self.source_raw().starts_with("http")
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
pub(crate) fn source(&self) -> SourceKind<'_> {
|
|
|
|
|
if self.is_url() {
|
|
|
|
|
SourceKind::Url(self.source_raw())
|
|
|
|
|
} else {
|
|
|
|
|
SourceKind::Path(self.source_raw())
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
pub(crate) enum SourceKind<'a> {
|
|
|
|
|
Url(&'a str),
|
|
|
|
|
Path(&'a str),
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|