Skip to content

Instantly share code, notes, and snippets.

@uncomfyhalomacro
Created June 22, 2025 12:54
Show Gist options
  • Save uncomfyhalomacro/1674247c211f3ebcf5c102021be547aa to your computer and use it in GitHub Desktop.
Save uncomfyhalomacro/1674247c211f3ebcf5c102021be547aa to your computer and use it in GitHub Desktop.
yt-cli.nu
#!/usr/bin/nu
def MENU [
-p: string
] {
if $env.XDG_SESSION_TYPE == 'wayland' { fuzzel -d -p $p} else { bemenu -p $p}
}
let subbed_channels = [
# Add your favourite channels here
]
let channel = ($subbed_channels | to text | MENU -p "choose channel>" | str trim)
if ($channel | is-empty) {
exit 0
}
if $channel not-in $subbed_channels {
notify-send --icon dialog-error --app-name Error -u critical "Not in the list" $"($channel) channel is not in the list of your subs!"
exit 1
}
let titles = (http get $"(http get $"https://www.youtube.com/@($channel | to text | str trim)" | query web -q 'link' -a href | find feeds | get 0 | ansi strip)" --raw | query web -q 'title')
let channel_title = ($titles | get 0 | to text | str trim)
let video_titles = ($titles | skip 1 | str trim)
let chosen_video_title = ($titles | to text | MENU -p 'open link to>' | str trim)
if ($chosen_video_title | is-empty) {
exit 0
} else {
let video_hashes = (http get $"(http get $"https://www.youtube.com/@($channel | str trim)" | query web -q 'link' -a href | find feeds | get 0 | ansi strip)" --raw | query web -q 'yt\:videoId')
for $video_title in ($video_titles | enumerate) {
if $chosen_video_title == $channel_title {
notify-send --icon firefox --app-name firefox $"Opening Youtube channel - ($channel_title) - in default browser"
setsid /bin/sh -c $"xdg-open 'https://youtube.com/@($channel)'"
sleep 0.3sec
exit 0
} else {
if ($chosen_video_title in $video_title.item) {
notify-send --icon mpv --app-name mpv $"Opening '($video_title.item)' in mpv"
let ytflags = "(mp4,webm)[height<?1080]+bestaudio/best"
setsid /bin/sh -c $'mpv --slang=en --ytdl-raw-options=ignore-config=,sub-lang=en,write-auto-sub= --ytdl-format="($ytflags)" --no-fs "https://youtube.com/watch?v=($video_hashes | get $video_title.index | to text)"'
sleep 0.3sec
exit 0
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment