How to Watch YouTube Videos in the Linux Terminal With ytfzf

How to Watch YouTube Videos in the Linux Terminal With ytfzf

It’s no secret that Linux keyboard warriors spend their lives in the terminal, only surfacing to load a browser and watch their favorite Taylor Swift music video on YouTube.

With ytfzf, you can search YouTube videos from your terminal and stream them using a lightweight media player. You’d never need to open a browser to watch YouTube on Linux again!

What Is ytfzf?

ytfzf is a set of scripts that run in your terminal, and it doesn’t use the YouTube API. When ytfzf starts up, it fetches a list of the top 10 Invidious instances and selects one at random. Invidious is a web-based alternative front end for YouTube, and there are thousands of instances across the world.

With the Invidious API, ytfzf searches for the video you want. It then uses yt-dlp to download and stream the video to mpv.

YouTube won’t be able to set any cookies on your devices, and you won’t see any adverts or pre-roll videos, either.

How to Install ytfzf on Linux

Before you install ytfzf, you need to install its dependencies, including mpv—a free media player for the command line, with support for a wide variety of media file formats, audio and video codecs, and subtitle types.

sudo apt install jq curl mpv fzf

ytfzf uses yt-dlp to download YouTube videos you find, so you should install yt-dlp as well.

Clone the ytfzf repository, and cd into it:

git clone https:
cd ytfzf

Now compile ytfzf, install the documentation, and compile the add-ons:

sudo make install
sudo make install doc
sudo make addons

ytfzf is now installed on your Linux system, and you can start it by entering:


As ytfzf is a bit awkward to type or remember, you may want to create a memorable alias for the command.

How to Use ytfzf To Search for Videos on the Command Line

As ytfzf doesn’t connect directly to YouTube to search for videos, when you start the app, you’ll see “Fetching list of healthy invidious instances”.

At the search prompt, enter the name of the video you want to search for. This doesn’t need to be exact, and typing “swif” then hitting Enter will give you all the Taylor Swift music videos you could want. You can further refine these by inputting more text.

Use the arrow keys on your keyboard to navigate results, and hit Enter to stream the one you want.

mpv will open, and the video will play. You can pause the video with Space, and fast-forward or rewind with the arrow keys.

If you want to see thumbnails of the videos before you stream them, you need to add a switch before launching ytfzf:

ytfzf -t

Be aware this will not work in all terminals.

To create a playlist with ytfzf and mpv, simply press Tab when a video you want to watch is highlighted, then Enter to add it to the playlist.

Instead of launching ytfzf and then entering your search term, you can issue:

ytfzf linux

…to be given a list of Linux videos to select from. ytfzf accepts arguments to make your experience more precise. Here are some of them:

  1. -d: Starting ytfzf with this option will cause yt-dlp to download the video you select instead of streaming it to mpv
  2. -m: Only play audio
  3. -l: Reopen the menu when the video stops playing
  4. -L: Show the link of selected video(s)
  5. -a: Automatically select the first video
  6. -r: Automatically selects a random video

As an example, enter:

ytfzf -a taylor bejeweled

…and mpv will instantly start playing “Bejeweled” by Taylor Swift.

Searching YouTube From the Terminal Is Insanely Cool

Being able to search YouTube from the terminal without needing to open a browser and accept adverts, tracking, and cookie consent dialogs will make you the envy of your friends.

Why not impress them even more by reading out a Wikipedia summary of your favorite musical artist in the very same terminal window?


via MUO – Feed

November 23, 2022 at 07:06AM

Leave a Reply

%d bloggers like this: