This commit is contained in:
Nox Sluijtman 2024-04-29 19:42:03 +02:00
parent bc942a3432
commit 5d450a90da
3 changed files with 29 additions and 22 deletions

View file

@ -1,27 +1,29 @@
#!/usr/bin/env nu #!/usr/bin/env nu
def main [url: string, --return(-r)] { def main [url: string
let parsed_url = $url | url parse , --return(-r) # Returns given url as YouTube url
] {
let parsed_url = $url | url parse
let yt_url = if ($parsed_url.path | str contains '/watch') { let yt_url = if ($parsed_url.path | str contains '/watch') {
if $parsed_url.host != "youtube.com" { if $parsed_url.host != "youtube.com" {
$url | str replace $parsed_url.host "youtube.com" $url | str replace $parsed_url.host "youtube.com"
} else { } else {
$url $url
} }
} else { } else {
error make { error make {
msg: "Not a YouTube/Invidious/Piped URL" msg: "Not a YouTube/Invidious/Piped URL"
label: { label: {
text: "Expects a YouTube/Invidious/Piped URL" text: "Expects a YouTube/Invidious/Piped URL"
span: (metadata $url).span span: (metadata $url).span
} }
} }
} }
match $return { match $return {
true => $yt_url true => $yt_url
false => { yt-dlp --embed-chapters --embed-metadata --embed-subs $yt_url } false => { yt-dlp --embed-chapters --embed-metadata --embed-subs $yt_url }
} }
} }

5
port.nu Executable file
View file

@ -0,0 +1,5 @@
#!/usr/bin/env nu
def main [] {
random int 0..65535
}