ipod syncing; updated readme; rust 2024; version bump
This commit is contained in:
58
src/input.rs
58
src/input.rs
@@ -1,5 +1,5 @@
|
||||
use std::path;
|
||||
use std::collections::HashMap;
|
||||
use std::collections::BTreeMap;
|
||||
|
||||
#[derive(clap::Parser)]
|
||||
pub(crate) struct Args {
|
||||
@@ -48,12 +48,66 @@ pub(crate) enum Command {
|
||||
#[arg(long, short)]
|
||||
podcast: Option<String>,
|
||||
},
|
||||
/// 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,
|
||||
},
|
||||
}
|
||||
|
||||
/// Struct modelling configuration file format.
|
||||
#[derive(serde::Deserialize)]
|
||||
pub(crate) struct Config {
|
||||
/// Map from podcast alias to RSS feed either as a url (prefix: http) or file path.
|
||||
pub(crate) podcasts: HashMap<String, String>,
|
||||
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,
|
||||
},
|
||||
}
|
||||
|
||||
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),
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user