From ed0dd61dfc455ba76df38e16ab2c2d5e5862bb48 Mon Sep 17 00:00:00 2001 From: siph Date: Sat, 10 Feb 2024 19:11:15 -0700 Subject: [PATCH] feature: yt-dlp configuration This lets `yt-watcher` use a configuration separate from the system configuration. By default it will still use the system configuration. --- README.md | 4 ++++ tests/config.nu | 8 +++++++- yt-watcher/config.nu | 6 ++++++ yt-watcher/mod.nu | 34 +++++++++++++++++++++++++++------- 4 files changed, 44 insertions(+), 8 deletions(-) diff --git a/README.md b/README.md index bd8610f..05ef14a 100644 --- a/README.md +++ b/README.md @@ -25,6 +25,10 @@ query: loop: true verbose: true output: /home//yt-watcher +yt-dlp: + config: + enable: false + path: /home//.config/yt-dlp/config channels: - UCaYhcUwRBNscFNUKTjgPFiA - UCrW38UKhlPoApXiuKNghuig diff --git a/tests/config.nu b/tests/config.nu index 09b000f..996c2a7 100644 --- a/tests/config.nu +++ b/tests/config.nu @@ -2,7 +2,7 @@ use ../yt-watcher/config.nu [get_config] use std assert -export def test_missing_config_is_build [] { +export def test_missing_config_is_built [] { let dirname = "yt-watcher" let test_dir = ("/tmp" | path join (random chars)) @@ -34,6 +34,12 @@ export def test_present_config_is_fetched [] { loop:false verbose:true output:$"($env.HOME)/yt-watcher" + yt-dlp: { + config: { + enable: false + path:$"($env.XDG_CONFIG_HOME)/yt-dlp/config" + } + } channels:[ test ] } diff --git a/yt-watcher/config.nu b/yt-watcher/config.nu index 6813d1b..3ce6ffc 100644 --- a/yt-watcher/config.nu +++ b/yt-watcher/config.nu @@ -26,6 +26,12 @@ export def get_config [ loop:true verbose:true output:$"($env.HOME)/yt-watcher" + yt-dlp: { + config: { + enable: false + path:$"($env.XDG_CONFIG_HOME)/yt-dlp/config" + } + } channels:[ UCaYhcUwRBNscFNUKTjgPFiA UCrW38UKhlPoApXiuKNghuig diff --git a/yt-watcher/mod.nu b/yt-watcher/mod.nu index eccdcb0..11a4d15 100644 --- a/yt-watcher/mod.nu +++ b/yt-watcher/mod.nu @@ -37,13 +37,13 @@ export def main [ } $recent_videos - | each {|it| - if $config.query.use_invidious { - download ($it.videoId | to_url $config.query.invidious_host ) $config.output - } else { - download ($it.videoId | to_url "https://www.youtube.com") $config.output + | each {|it| + if $config.query.use_invidious { + download ($it.videoId | to_url $config.query.invidious_host) $config.output $config.yt-dlp + } else { + download ($it.videoId | to_url "https://www.youtube.com") $config.output $config.yt-dlp + } } - } if ($config.loop != true) { break } @@ -54,8 +54,28 @@ export def main [ def download [ url: string # Youtube url output_folder: string # File destination + yt_dlp: record # Yt-dlp configuration info ] { log info $"Download started for ($url) to ($output_folder)" - yt-dlp -q $url --paths $output_folder + if yt_dlp.config.enable { + ( + yt-dlp + --ignore-config + --config-locations + $yt_dlp.config.path + -q + $url + --paths + $output_folder + ) + } else { + ( + yt-dlp + -q + $url + --paths + $output_folder + ) + } }