#!/usr/bin/env nu def parse_url [url: string] { let parsed_url = $url | url parse let correct_string = ($parsed_url.path | grep -E "(playlist|watch)" | complete).exit_code if ($correct_string == 0) { 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 } } } } def main [ url: string , --copy(-c) ] { let $url = parse_url $url match $copy { true => { $url | xclip -sel clip } false => $url } } def "main download" [url: string] { yt-dlp --embed-chapters --embed-metadata --embed-subs (parse_url $url) } def "main dl" [url: string] { yt-dlp --embed-chapters --embed-metadata --embed-subs (parse_url $url) }