{ datagubbe }

datagubbe.se » tube - youtube cli

tube - Youtube CLI

Update 2021-10-20: Tube 1.1.4 has been released, featuring support for invoking yt-dlp instead of opening a video URL directly with a video player. yt-dlp features some very fancy code indeed, which is capable of handling YouTube's new bandwidth throttling. This allows me to continue using tubeshell and my tube history file, which is very useful to me. If I do any more work on tube, I'm likely to remove the extraction portion of it completely and let it act as a CLI for yt-dlp, which is a great piece of software.


tube is a Python script for extracting video metadata (I.E. the actual video stream URL) from an arbitrary Youtube (youtube.com, youtu.be) URL and then launch a player of choice (such as MPV or VLC) to watch the video, or (which is now the recommended behavior) pipe the output from yt-dlp to said player.

In tube version 1.0.15, a rudimentary and experimental function for searching Youtube was added.

Together with tubeshell, a small bash script providing a readline-style shell for tube, it is an easy way of watching videos and handling tube's built-in history function, which stores previously watched videos.

tube does not handle Google accounts or API tokens, and it doesn't download the video stream - it simply facilitates viewing it. It is intended as a way of enjoying publicly available videos without the distraction of algorithmic content suggestions and autoplaying of suggested videos. A suitably pruned tube history will instead serve as a searchable library of interesting videos worth returning to and re-watching.

tube has been developed on and for Linux, but will probably work on other Unix-like systems as well. tube and tubeshell are both released under the MIT license. tube requires Python 3.5 to work and is linted with these settings. tubeshell is linted with shellcheck.

I surprised myself greatly with this little piece of software: since I wrote it, I have been using it (almost) every day, adding features and polishing the existing ones to my suit my personal preference. Perhaps someone else will find it useful, too.

Download / Source code

The latest release is v1.1.4 (2021-10-20)

Feature list

Simply pasting a video URL into tubeshell and hitting enter will suffice for watching it. Other than that, the following list of tubeshell commands should give a good overview of the features provided:

search <keyword1> [<keyword2> ... <keywordN>] (Alias: s)
Search Youtube for given keywords.
list [<string>] (Aliases: ls, l)
List the 100 latest viewed videos or, if supplied, search the complete history for <string>.
listall (Aliases: lsa, la)
List complete view history.
listl [<string>] (Aliases: lsl, ll)
List or search complete view history and display the result using less.
hist <index> (Aliases: view, v, h)
View video matching supplied history <index>.
nohist <url> (Alias: nh)
View video without writing to history, regardless of history settings.
delhist <index1> [<idx2> ... <idxN>] | <idx1>-<idx2> | last (Aliases: rm, del)
Delete videos matching indices or index range from history.
geturl <index> (Aliases: gurl, gu)
Recreate Youtube URL from video in history matching <index>.


Screenshot of tubeshell running inside xterm, showing a tube search for Keferens Desert Dream
Example tubeshell session, showing the search function.