Menu

Stream Music from YouTube Using Terminal

Taufik Nurhidayat
3 min read
#linux #tutorial

Streaming music from YouTube using the terminal? Of course, it's possible, and easy to do.

social_cards/musik-thumb.png

Listening to music is a very common thing nowadays. Starting from radio and cassettes, the trend of listening to music has shifted to online streaming using music streaming platforms. In this article, we will learn how to stream music using only the terminal or console on Linux, Windows, and Mac operating systems.

Stream Music Using Yewtube

First, we can use yewtube, which is a fork of mps-youtube. With this tool, we can watch videos or listen to music from YouTube via the terminal.

Installing Yewtube

Make sure your operating system has python, python-pip or python-pipx installed, as well as a media player like VLC or MPV. To install, follow one of the commands below in the terminal.

# pip
pip install yewtube

# pipx (recommended)
pipx install yewtube

Running and Searching

If the installation process is successful, the next step is to run yewtube itself with the command yt, and a display like the following will appear.

Yewtube

To perform a search, use the / (slash) command followed by the query you want to search for, like this.

/lofi chill

Playing Media

If the search results appear, type and enter the number listed in the search results to play the media. Please note that search results with a None date usually indicate a live stream that cannot be played.

Yewtube Search Music from Youtube

Playing Audio Only

By default, yewtube will play media as video. To play only audio, configure it with the following command.

set show_video false

Changing Media Player

If your operating system has VLC and MPV, yewtube will by default use VLC to play media. Although it is not recommended to change to another media player, you can switch with the following command.

# mpv can be replaced with other players
set player mpv

Stream YouTube Using Ytfzf

Similar to yewtube, ytfzf is another tool that can stream YouTube through the terminal, but the difference is that ytfzf uses fzf as its interface.

Installing Ytfzf

Currently, ytfzf is only available on Linux operating systems. To install it, you can use your distro’s package manager or:

# Debian and Ubuntu
sudo apt-get install ytfzf

# Arch Linux
sudo pacman -S ytfzf

If it doesn’t work, you can directly clone the ytfzf repository and build it manually using make. Here’s the command:

git clone https://github.com/pystardust/ytfzf
cd ytfzf
sudo make install doc

Searching and Playing Media

To perform a search, we can use the following command.

ytfzf query to search

Or just play music media with the following command.

ytfzf -m query to search

Here’s the display of ytfzf. To select a list, you can use the arrow keys on your keyboard. Press enter to play the media.

Why Stream Using Terminal?

If you are not a Linux user, you might not like anything related to the terminal and prefer streaming through platforms that are easier to use.

Besides the lack of a GUI, the process is also quite complicated, especially for those who are not used to the CLI. However, there are several advantages to streaming music using the terminal, including:

  1. Free
  2. No ads
  3. Cannot play live streaming media.
  4. Does not consume much memory.

Final Words

Perhaps streaming music through the terminal is not the primary choice, but it can be an alternative for those who are used to and like the CLI/terminal interface. With several advantages such as no ads and being free, streaming music using the terminal is worth considering.