From 22e3c301a2199857fd46babc401f7762944c1fdc Mon Sep 17 00:00:00 2001 From: yggverse Date: Wed, 8 Apr 2026 12:52:44 +0300 Subject: [PATCH] implement custom invidious instance support --- example/config.toml | 6 ++++-- src/config.rs | 2 +- src/main.rs | 2 +- src/provider.rs | 8 ++++++-- 4 files changed, 12 insertions(+), 6 deletions(-) diff --git a/example/config.toml b/example/config.toml index 8620bf6..f6d76c4 100644 --- a/example/config.toml +++ b/example/config.toml @@ -21,9 +21,11 @@ sleep = 1 # exec = "" # stdout_contains = [""] -# Supported values: youtube | invidious +# Video instance provider -provider = "youtube" +provider = "Youtube" +# provider = "Invidious" +# provider = { Invidious = "https://tux.rs" } # Channels queue config diff --git a/src/config.rs b/src/config.rs index 8a0f1ab..1e60a4d 100644 --- a/src/config.rs +++ b/src/config.rs @@ -7,7 +7,7 @@ use std::{collections::HashMap, path::PathBuf}; #[derive(Deserialize)] pub enum Provider { Youtube, - Invidious, + Invidious(Option), } #[derive(Deserialize)] diff --git a/src/main.rs b/src/main.rs index 9b2872e..02e6b5a 100644 --- a/src/main.rs +++ b/src/main.rs @@ -37,7 +37,7 @@ async fn main() { let mut database = Database::new(&config.database).unwrap(); let client = match config.provider { config::Provider::Youtube => Provider::youtube(), - config::Provider::Invidious => Provider::invidious(), + config::Provider::Invidious(instance) => Provider::invidious(instance), }; let channel_item_id_regex = Regex::new(r"^[A-z0-9_-]{11}$").unwrap(); diff --git a/src/provider.rs b/src/provider.rs index 6e1dcf9..1ff80aa 100644 --- a/src/provider.rs +++ b/src/provider.rs @@ -19,8 +19,12 @@ impl Provider { pub fn youtube() -> Self { Self::Youtube(RustyPipe::new()) } - pub fn invidious() -> Self { - Self::Invidious(ClientSync::default()) + pub fn invidious(instance: Option) -> Self { + let mut client = ClientSync::default(); + if let Some(i) = instance { + client.set_instance(i) + } + Self::Invidious(client) } pub async fn videos(&self, channel_id: &str) -> Result> { let mut videos = Vec::new();