2024-04-03 15:43:39 +02:00
|
|
|
#!/usr/bin/env nu
|
|
|
|
|
2024-05-08 09:51:47 +02:00
|
|
|
def parse_url [url: string] {
|
2024-04-29 19:42:03 +02:00
|
|
|
let parsed_url = $url | url parse
|
2024-04-04 15:54:37 +02:00
|
|
|
|
2024-07-08 11:54:18 +02:00
|
|
|
let correct_string = ($parsed_url.path | grep -E "(playlist|watch)" | complete).exit_code
|
|
|
|
|
|
|
|
if ($correct_string == 0) {
|
2024-04-29 19:42:03 +02:00
|
|
|
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-05-08 09:51:47 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
def main [ url: string
|
|
|
|
, --copy(-c)
|
|
|
|
] {
|
2024-04-04 15:54:37 +02:00
|
|
|
|
2024-05-08 09:51:47 +02:00
|
|
|
let $url = parse_url $url
|
|
|
|
|
|
|
|
match $copy {
|
|
|
|
true => { $url | xclip -sel clip }
|
|
|
|
false => $url
|
2024-04-29 19:42:03 +02:00
|
|
|
}
|
2024-05-08 09:51:47 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
def "main download" [url: string] {
|
|
|
|
yt-dlp --embed-chapters --embed-metadata --embed-subs (parse_url $url)
|
|
|
|
}
|
2024-04-03 15:43:39 +02:00
|
|
|
|
2024-05-08 09:51:47 +02:00
|
|
|
def "main dl" [url: string] {
|
|
|
|
yt-dlp --embed-chapters --embed-metadata --embed-subs (parse_url $url)
|
2024-04-03 15:43:39 +02:00
|
|
|
}
|