2 ms·
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:
by kmstout 4y ago
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.
- kmstout 4y agoFor anyone who finds this, here's a much faster ytsearch: ytsearch ======== #! /bin/bash nresults=$1; shift query="$@" yt-dlp -j --flat-playlist ytsearch${nresults}:"${query// /+}" I now also have ytgetlist ========= #! /bin/bash yt-dlp -j --flat-playlist "$@" which is handy for listing entire channels. The downside of using --flat-playlist is that the upload_date ends up null, so `ytplaylist` is modified to cope: ytplaylist ========== #! /bin/bash jq -r '"\(.upload_date // .playlist_index) \(.id) \(.duration)\t\(.title)"' "$@" \ | sort -k1n | uniq \ | fzf --bind "enter:execute(ytplay {+2})" The playlist indices so far reflect the order one would get by sorting on upload date.