I've been rebuilding my command line YT client based on mpv, fzf, and yt-dlp (compatible with youtube-dl in all the ways that matter). Here's my search command:
ytsearch
========
#! /bin/bash
nresults=$1; shift
query="$@"
yt-dlp -j ytsearch${nresults}:"${query// /+}"
This will give back my results as JSON, which I can save to a file or pipe to `ytplaylist`: ytplaylist
==========
#! /bin/bash
jq -r '"\(.upload_date) \(.id) \(.duration)\t\(.title)"' "$@" \
| sort | uniq \
| fzf --bind "enter:execute(ytplay {+2})"
Note that, because of the layout of the lines, records get sorted based first on date.Streaming is done via mpv:
ytplay
======
#! /bin/bash
id=$1; shift
mpv "ytdl://$id" --ytdl-format='best[height<=720]' "$@"
Finally, since I often don't care about saving results, wanting instead to just view the playlist, yt
==
ytsearch "$@" | ytplaylist
So, if I want to search for videos on butchering cows, I might do $ yt 5 butcher cow
as a preliminary to make sure I'm getting the sorts of results I want, then do $ yt 50 butcher cow
and get myself a beer. I could also save the results $ ytsearch 50 butcher cow > deadbeef.json
and view the results at my leisure with $ ytplaylist deadbeef.json
`deadbeef.json` will have extensive metadata for each video found, including a channel URL. Suppose with a bit of jq I find the URL for a really good channel; I can then $ yt-dlp -j $CHANNEL_URL > cool-channel.json
to get a playlist for the entire channel, then operate on it like the results coming back from `ytsearch`.Happy Friday.