A couple of threads ago someone posted a oneliner that pipes yt-dlp to fzf essentially making simple cli youtube browser. I decided to work on that idea a little bit as I know fzf has some features that could be useful here, like a preview or playlist creation (tab to mark videos to play).
#!/bin/bash
set -euo pipefail
[[ $# -eq 0 ]] || [[ "$1" == "--help" ]] && echo "Usage: ${0##*/} SEARCH" && exit
fn_preview () {
yt-dlp "$1" --simulate \
--print " Channel: %(uploader_url)s" \
--print " Video: %(webpage_url)l" \
--print " Uploaded: %(upload_date>%Y-%m-%d)s" \
--print "" \
--print "%(description)s" 2>/dev/null
}
export -f fn_preview
fn_exec_mpv () {
mpv "$@" --player-operation-mode=pseudo-gui --force-window=immediate &
}
export -f fn_exec_mpv
yt-dlp "ytsearch30:$*" --simulate --flat-playlist --print "%(webpage_url)s %(duration>%H:%M:%S|LIVE •)s %(title)s" 2>/dev/null \
| fzf \
--multi \
--info inline \
--no-mouse \
--layout reverse \
--with-nth 2.. \
--preview "fn_preview {1}" \
--preview-window wrap \
--bind "enter:execute:fn_exec_mpv {+1}"