First version of youtube-backup, a tool to backup your YouTube channel.
This commit is contained in:
parent
acf188738a
commit
abf3af5768
13 changed files with 1612 additions and 20 deletions
31
src/config.rs
Normal file
31
src/config.rs
Normal file
|
|
@ -0,0 +1,31 @@
|
|||
use serde::{Deserialize, Serialize};
|
||||
use std::path::{Path, PathBuf};
|
||||
|
||||
#[derive(Debug, Serialize, Deserialize, Clone)]
|
||||
pub struct Config {
|
||||
pub backup: BackupSection,
|
||||
#[serde(default)]
|
||||
pub player: PlayerSection,
|
||||
}
|
||||
|
||||
#[derive(Debug, Serialize, Deserialize, Clone)]
|
||||
pub struct BackupSection {
|
||||
pub directory: PathBuf,
|
||||
}
|
||||
|
||||
#[derive(Debug, Serialize, Deserialize, Clone, Default)]
|
||||
pub struct PlayerSection {
|
||||
#[serde(default = "default_player")]
|
||||
pub command: String,
|
||||
}
|
||||
|
||||
fn default_player() -> String {
|
||||
"mpv".to_string()
|
||||
}
|
||||
|
||||
impl Config {
|
||||
pub fn load(path: &Path) -> Result<Self, Box<dyn std::error::Error>> {
|
||||
let contents = std::fs::read_to_string(path)?;
|
||||
toml::from_str(&contents).map_err(|e| e.into())
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue