diff --git a/Cargo.lock b/Cargo.lock index 35d5fe6..93f88c0 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2029,6 +2029,7 @@ dependencies = [ "idna", "percent-encoding", "serde", + "serde_derive", ] [[package]] @@ -2501,6 +2502,7 @@ dependencies = [ "tokio", "toml", "tracing-subscriber", + "url", ] [[package]] diff --git a/Cargo.toml b/Cargo.toml index e309bc4..0f3c1ac 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -24,3 +24,4 @@ serde_regex = "1.1.0" tokio = { version = "1.51.0", features = ["rt-multi-thread"] } toml = "1.1.2" tracing-subscriber = { version = "0.3.23", features = ["env-filter"] } +url = { version = "2.5.8", features = ["serde"] } diff --git a/example/config.toml b/example/config.toml index 767c918..0b46dca 100644 --- a/example/config.toml +++ b/example/config.toml @@ -21,11 +21,9 @@ sleep = 1 # exec = "" # stdout_contains = [""] -# Video instance provider, Youtube by default +# Invidious provider, Youtube by default -# provider = "Youtube" -# provider = "Invidious" -# provider = { Invidious = "https://tux.rs" } +# provider = "https://tux.rs" # Channels queue config diff --git a/src/config.rs b/src/config.rs index 13cf3b4..d38364b 100644 --- a/src/config.rs +++ b/src/config.rs @@ -3,13 +3,7 @@ mod channel; use channel::Channel; use serde::Deserialize; use std::{collections::HashMap, path::PathBuf}; - -#[derive(Deserialize, Default)] -pub enum Provider { - #[default] - Youtube, - Invidious(Option), -} +use url::Url; #[derive(Deserialize)] pub struct Command { @@ -19,10 +13,8 @@ pub struct Command { #[derive(Deserialize)] pub struct Config { - /// Supported values: - /// * youtube - /// * invidious - pub provider: Provider, + /// Invidious provider, Youtube by default + pub provider: Option, /// Channels parsed from the config file pub channel: HashMap, /// Persist processed entries between sessions diff --git a/src/main.rs b/src/main.rs index 3411254..2bf984c 100644 --- a/src/main.rs +++ b/src/main.rs @@ -36,14 +36,15 @@ async fn main() { let sleep = config.sleep.map(Duration::from_secs); let mut database = Database::new(&config.database).unwrap(); let provider = match config.provider { - config::Provider::Youtube => { + Some(invidious_url) => { + let url = invidious_url.to_string(); + debug!("Init Invidious {url} provider"); + Provider::invidious(Some(url)) + } + None => { debug!("Init Youtube provider"); Provider::youtube() } - config::Provider::Invidious(instance) => { - debug!("Init Invidious {instance:?} provider"); - Provider::invidious(instance) - } }; let channel_item_id_regex = Regex::new(r"^[A-z0-9_-]{11}$").unwrap();