#!/usr/bin/env nu def parse_url [url: string] { let parsed_url = $url | url parse 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 } } } } 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) }