Skip to content

Commit

Permalink
feature: yt-dlp configuration
Browse files Browse the repository at this point in the history
This lets `yt-watcher` use a configuration separate from the system
configuration. By default it will still use the system configuration.
  • Loading branch information
siph committed Feb 11, 2024
1 parent 4107c2f commit ed0dd61
Show file tree
Hide file tree
Showing 4 changed files with 44 additions and 8 deletions.
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,10 @@ query:
loop: true
verbose: true
output: /home/<user>/yt-watcher
yt-dlp:
config:
enable: false
path: /home/<user>/.config/yt-dlp/config
channels:
- UCaYhcUwRBNscFNUKTjgPFiA
- UCrW38UKhlPoApXiuKNghuig
Expand Down
8 changes: 7 additions & 1 deletion tests/config.nu
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down Expand Up @@ -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 ]
}

Expand Down
6 changes: 6 additions & 0 deletions yt-watcher/config.nu
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
34 changes: 27 additions & 7 deletions yt-watcher/mod.nu
Original file line number Diff line number Diff line change
Expand Up @@ -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 }

Expand All @@ -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
)
}
}

0 comments on commit ed0dd61

Please sign in to comment.