mirror of
https://codeberg.org/YGGverse/ytd.git
synced 2026-04-09 05:15:30 +00:00
add {PROVIDER} macro support
This commit is contained in:
parent
a61f29de6d
commit
5fc73924df
2 changed files with 12 additions and 8 deletions
|
|
@ -23,7 +23,7 @@ sleep = 1
|
||||||
|
|
||||||
# Invidious provider, Youtube by default
|
# Invidious provider, Youtube by default
|
||||||
|
|
||||||
# provider = "https://tux.rs"
|
# provider = "https://inv.thepixora.com"
|
||||||
|
|
||||||
# Channels queue config
|
# Channels queue config
|
||||||
|
|
||||||
|
|
@ -40,7 +40,8 @@ sleep = 1
|
||||||
[[channel.test.item]]
|
[[channel.test.item]]
|
||||||
exec = "/usr/bin/echo {ID}" # Supported macro replacements:
|
exec = "/usr/bin/echo {ID}" # Supported macro replacements:
|
||||||
# * {ID} - parsed item ID (e.g. `yt-dlp https://youtu.be/{ID}`)
|
# * {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
|
stdout_contains = ["\n"] # Check stdout for containing expected string, optional
|
||||||
|
|
||||||
# [[channel.test.item]]
|
# [[channel.test.item]]
|
||||||
|
|
|
||||||
15
src/main.rs
15
src/main.rs
|
|
@ -35,15 +35,15 @@ async fn main() {
|
||||||
let update = config.update.map(Duration::from_secs);
|
let update = config.update.map(Duration::from_secs);
|
||||||
let sleep = config.sleep.map(Duration::from_secs);
|
let sleep = config.sleep.map(Duration::from_secs);
|
||||||
let mut database = Database::new(&config.database).unwrap();
|
let mut database = Database::new(&config.database).unwrap();
|
||||||
let provider = match config.provider {
|
let (client, provider) = match config.provider {
|
||||||
Some(invidious_url) => {
|
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");
|
debug!("Init Invidious {url} provider");
|
||||||
Provider::invidious(Some(url))
|
(Provider::invidious(Some(url.clone())), url)
|
||||||
}
|
}
|
||||||
None => {
|
None => {
|
||||||
debug!("Init Youtube provider");
|
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();
|
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());
|
info!("begin {} channels update...", config.channel.len());
|
||||||
for (c, channel) in &config.channel {
|
for (c, channel) in &config.channel {
|
||||||
debug!("get `{c}` ({})...", channel.id);
|
debug!("get `{c}` ({})...", channel.id);
|
||||||
match provider.videos(&channel.id).await {
|
match client.videos(&channel.id).await {
|
||||||
Ok(items) => {
|
Ok(items) => {
|
||||||
debug!(
|
debug!(
|
||||||
"received {} items to handle, limit: {:?}...",
|
"received {} items to handle, limit: {:?}...",
|
||||||
|
|
@ -139,7 +139,10 @@ async fn main() {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
for channel_item in &channel.item {
|
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() {
|
match Command::new("sh").arg("-c").arg(&cmd).output() {
|
||||||
Ok(response) => {
|
Ok(response) => {
|
||||||
if response.status.success() {
|
if response.status.success() {
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue