add {PROVIDER} macro support

This commit is contained in:
yggverse 2026-04-08 14:10:52 +03:00
parent a61f29de6d
commit 5fc73924df
2 changed files with 12 additions and 8 deletions

View file

@ -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]]

View file

@ -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() {