mirror of
https://framagit.org/veretcle/tootube.git
synced 2025-07-20 12:31:19 +02:00
70 lines
1.7 KiB
Rust
70 lines
1.7 KiB
Rust
use serde::Deserialize;
|
|
use std::fs::read_to_string;
|
|
|
|
// General configuration Struct
|
|
#[derive(Debug, Deserialize)]
|
|
pub struct Config {
|
|
pub peertube: PeertubeConfig,
|
|
pub youtube: YoutubeConfig,
|
|
#[serde(default)]
|
|
pub tootube: TootubeConfig,
|
|
}
|
|
|
|
#[derive(Debug, Deserialize)]
|
|
pub struct PeertubeConfig {
|
|
pub base_url: String,
|
|
#[serde(default)]
|
|
pub delete_video_source_after_transfer: bool,
|
|
pub oauth2: Option<PeertubeConfigOauth2>,
|
|
}
|
|
|
|
impl Default for PeertubeConfig {
|
|
fn default() -> Self {
|
|
PeertubeConfig {
|
|
base_url: "".to_string(),
|
|
delete_video_source_after_transfer: false,
|
|
oauth2: None,
|
|
}
|
|
}
|
|
}
|
|
|
|
#[derive(Debug, Clone, Deserialize)]
|
|
pub struct PeertubeConfigOauth2 {
|
|
pub client_id: String,
|
|
pub client_secret: String,
|
|
pub refresh_token: String,
|
|
}
|
|
|
|
#[derive(Debug, Deserialize)]
|
|
pub struct YoutubeConfig {
|
|
pub refresh_token: String,
|
|
pub client_id: String,
|
|
pub client_secret: String,
|
|
}
|
|
|
|
#[derive(Debug, Deserialize)]
|
|
pub struct TootubeConfig {
|
|
pub progress_bar: String,
|
|
pub progress_chars: String,
|
|
}
|
|
|
|
impl Default for TootubeConfig {
|
|
fn default() -> Self {
|
|
TootubeConfig {
|
|
progress_bar: "{msg}\n{spinner:.green} [{elapsed_precise}] [{wide_bar:.cyan/blue}] {bytes}/{total_bytes} ({bytes_per_sec}, {eta})".to_string(),
|
|
progress_chars: "#>-".to_string(),
|
|
}
|
|
}
|
|
}
|
|
|
|
/// Parses the TOML file into a Config struct
|
|
pub fn parse_toml(toml_file: &str) -> Config {
|
|
let toml_config =
|
|
read_to_string(toml_file).unwrap_or_else(|e| panic!("Cannot open file {toml_file}: {e}"));
|
|
|
|
let config: Config = toml::from_str(&toml_config)
|
|
.unwrap_or_else(|e| panic!("Cannot parse TOML file {toml_file}: {e}"));
|
|
|
|
config
|
|
}
|