caoydl
is a command-line interface to YouTube, written in C99.
It strives to be quick, portable, and as simple as possible.
The goal is to provide and efficient, portable and easily hackable tool, which feats with my workflow and has the following features:
What "features" I didn't wanted:
caoydl
stands for C "aoydl". It was originally a rewrite of
aoydl (now a dead link) in C.
"aoydl" itself stands for "Aczkolwiek's Own Youtube-DL". aoydl
was a
very simple (almost) fully POSIX compliant shell script.
The project is based on "frontend", which is written by Hiltjo Posthuma (hiltjo@codemadness.org).
It also took some inspiration from yt-dlp (a youtube-dl fork), and pipe-viewer.
You can find the repository here.
Liabilities (or dependencies, YMMV):
Then:
$ make
And optionally, as root:
$ make install
caoydl
supports the following arguments:
caoydl <url|id>
:
get video direct links
get channel's video urls
get playlist's video urlscaoydl -s <query>
:
search for videoscaoydl -S <query>
:
search for videos (long output)caoydl -c <query>
:
search for channelcaoydl -P <url|id>
:
get channel's playlistsAll of these options can be combined with the -r
flag which gives you
the raw json(s).
Make a video search and print information corresponding to the first result:
$ caoydl "$(caoydl -s 'cat video' | sed 1q | cut -f 1)"
Here is what I get (at the time of writing, with my specific location):
title: Videos for Cats to Watch - 8 Hour Birds Bonanza - Cat TV Bird Watch
url: https://youtube.com/embed/xbs7FT7dXYc
uploaded by: UCPJXfmxMYAoH02CFudZxmgg Paul Dinning
published at: 2018-02-13
duration: 8:05:42
description:
------------------------------
Videos for Cats to Watch Birds - Cat TV Bird Watch
Video Produced by Paul Dinning - Wildlife in Cornwall #PaulDinning
------------------------------
https://rr1---sn-n4g-jqbed.googlevideo.com/videoplayback?expire=1661195883&...tnkGfAupg%3D%3D 22 video/mp4; codecs="avc1.42001E, mp4a.40.2"
...
https://rr1---sn-n4g-jqbed.googlevideo.com/videoplayback?expire=1661195883&...tnkGfAupg%3D%3D 251 audio/webm; codecs="opus"
After the "uploaded by:" is the channel's id followed by the channel's title. The last lines follows the following format (TSV):
<URL> <ITAG> <MIMETYPE>
"URL" is a direct link to the content and can be read/downloaded directly.
Print video availability and if it is live content using jq(1) and dmenu(1):
$ id=$(caoydl -s 'cat video' | dmenu | cut -f 1)
$ caoydl -r "$id" |
jq -r '..|[.playabilityStatus?.status, .videoDetails?.isLiveContent] | join("\n")' |
sed '/null/d; /^$/d'
OK
false
Get video's keywords (not available everywhere):
$ caoydl -r "$id" | jq -r '..|.videoDetails?.keywords[]?' | grep -vxF 'null'
Pet awesome
animal reaction
...
funniest animals
Get video's thumbnails (direct links):
$ caoydl -r "$id" | jq -r '..|.thumbnail?.thumbnails[]?.url' | grep -vxF 'null'
{
"url": "https://i.ytimg.com/vi/T2zEmJFso6Q/hqdefault.jpg?sqp=-oaymwEiCKgBEF5IWvKriqkDFQgBFQAAAAAYASUAAMhCPQCAokN4AQ==&rs=AOn4CLDFOMmf5L7j8S_D9Yic9bNLcZsmaA",
"width": 168,
"height": 94
}
...
{
"url": "https://i.ytimg.com/vi/T2zEmJFso6Q/maxresdefault.jpg",
"width": 1280,
"height": 720
}
I like to use caoydl in combination with a "pager":
$ caoydl -S <query> | less
Here I'm using st (suckless or simple terminal), with a patch to plumb on right click.
You can take a look at the plumber right there. It can recognize a YouTube channel, playlist or video's identifier, each one being of a specific length:
^[-_a-zA-Z0-9]{11}$
matches a video id^[-_a-zA-Z0-9]{24}$
matches a channel id^[-_a-zA-Z0-9]{18}$
and ^[-_a-zA-Z0-9]{34}$
matches a playlist id