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