From 5fc73924df6e57452dc99334d6732ab88e5fcf7d Mon Sep 17 00:00:00 2001 From: yggverse Date: Wed, 8 Apr 2026 14:10:52 +0300 Subject: [PATCH] add `{PROVIDER}` macro support --- example/config.toml | 5 +++-- src/main.rs | 15 +++++++++------ 2 files changed, 12 insertions(+), 8 deletions(-) diff --git a/example/config.toml b/example/config.toml index 0b46dca..9e0cedd 100644 --- a/example/config.toml +++ b/example/config.toml @@ -23,7 +23,7 @@ sleep = 1 # Invidious provider, Youtube by default -# provider = "https://tux.rs" +# provider = "https://inv.thepixora.com" # Channels queue config @@ -40,7 +40,8 @@ sleep = 1 [[channel.test.item]] exec = "/usr/bin/echo {ID}" # Supported macro replacements: # * {ID} - parsed item ID (e.g. `yt-dlp https://youtu.be/{ID}`) - # See also: https://codeberg.org/YGGverse/pidpilne/src/branch/main/usr/local/bin/aacp.m4a + # * {PROVIDER} - current `provider` URL if set (e.g. `https://inv.thepixora.com`) or `https://youtu.be` + # See also: https://codeberg.org/YGGverse/pidpilne/src/branch/main/usr/local/bin stdout_contains = ["\n"] # Check stdout for containing expected string, optional # [[channel.test.item]] diff --git a/src/main.rs b/src/main.rs index 2bf984c..5c30d55 100644 --- a/src/main.rs +++ b/src/main.rs @@ -35,15 +35,15 @@ async fn main() { let update = config.update.map(Duration::from_secs); let sleep = config.sleep.map(Duration::from_secs); let mut database = Database::new(&config.database).unwrap(); - let provider = match config.provider { + let (client, provider) = match config.provider { Some(invidious_url) => { - let url = invidious_url.to_string(); + let url = invidious_url.as_str().trim_end_matches('/').to_string(); debug!("Init Invidious {url} provider"); - Provider::invidious(Some(url)) + (Provider::invidious(Some(url.clone())), url) } None => { debug!("Init Youtube provider"); - Provider::youtube() + (Provider::youtube(), "https://youtu.be".into()) } }; let channel_item_id_regex = Regex::new(r"^[A-z0-9_-]{11}$").unwrap(); @@ -56,7 +56,7 @@ async fn main() { info!("begin {} channels update...", config.channel.len()); for (c, channel) in &config.channel { debug!("get `{c}` ({})...", channel.id); - match provider.videos(&channel.id).await { + match client.videos(&channel.id).await { Ok(items) => { debug!( "received {} items to handle, limit: {:?}...", @@ -139,7 +139,10 @@ async fn main() { continue; } for channel_item in &channel.item { - let cmd = channel_item.exec.replace("{ID}", &item.id); + let cmd = channel_item + .exec + .replace("{ID}", &item.id) + .replace("{PROVIDER}", &provider); match Command::new("sh").arg("-c").arg(&cmd).output() { Ok(response) => { if response.status.success() {