Ever felt like wanting to complete most of your Linux computing tasks from the command-line environment without having to navigate to and from the GUI (Graphical User Interface)? A Linux operating system is an endless maze of rich computing knowledge and experience.
Most of the Linux materials either have technical documentation or none. Sometimes we might find the appropriate documentation that meets the objective we want to accomplish under a Linux environment but end up taking too much time consuming and implementing the retrieved material data.
The YouTube platform provides an easier way of understanding a Linux computing concept since video files are easier and faster to consume than documentation files.
[ You might also like: ytfzf – Find and Watch YouTube Videos in Linux Terminal ]
Therefore, if you are interested in learning how to implement a Linux application package for playing and downloading your favorite YouTube videos from the Linux terminal, this article guide is for you.
The mps-youtube application is an mps-based project that is effective in searching, streaming, and downloading YouTube-based video and audio files. This program perfectly interfaces with the YouTube platform as a result of the pafy library.
We can summarize the mps-youtube program features with the following bullet points:
- Requires Python 3.x, player, or mpv.
- Supports view of video comments.
- Supports download of audio and video files.
- With ffmpeg or avconv installed, users can convert video files to mp3 files.
- Users can create and save local playlists.
- YouTube playlists can be searched and imported.
- Album tracks can be searched via respective album titles.
- YouTube audio/video files can be searched and played.
Installing mps-youtube in Linux
To install mps-youtube, run the following command depending on the Linux distribution you are using.
$ sudo apt install mps-youtube [On Debian, Ubuntu and Mint] $ sudo pacman -S mps-youtube [On Arch Linux] $ sudo zypper install mps-youtube [On OpenSUSE]
Once installed, you can start the mps-youtube using the following command on your terminal.
To search for a video file with a key phrase like “nginx explained”, we would implement it in the following manner:
If you run into “Youtube Error 403”, consider setting your own Google API key.
Error fetching data. Possible network issue. Youtube Error 403: The request cannot be completed because you have exceeded your quota.
Create Google API Key for mps-youtube Tool
Firstly, create a Google developers account and then create a Google project of your choice from the CREATE PROJECT button after highlighting/selecting the No organization (or organization name if you have one).
Give your project a name, and the location
* field should be automatically populated.
Select your project and go to GoogleAPIs library, scroll down and click on YouTube Data API v3.
Ensure you have selected your project before clicking ENABLE to activate the API.
Click on CREDENTIALS and then CREATE CREDENTIALS.
Click on API KEY and copy the generated API key and save it somewhere.
Get rid of the mps-youtube cache file:
$ rm ~/.config/mps-youtube/cache_py_*
Implement the new API key into mps-youtube:
$ mpsyt set api_key YOUR_KEY_HERE
It should lead to the following interface:
Quit the mps-youtube app.
Open the file:
$ nano $HOME/.local/lib/python3.10/site-packages/pafy/backend_youtube_dl.py
Comment out the line…
self._dislikes = self._ydl_info['dislike_count']
and replace it with the line.
self._dislikes = self._ydl_info.get('dislike_count', 0)
Save and close the file.
Search and Download YouTube Video in Linux Command Line
Now start the mps-youtube and re-attempt our “nginx explained” search.
To play item number 1, key in:
To download a video, use
d <video number>, for example:
You will be redirected to another window to choose another item number based on the video/audio file size and quality you wish to download.
If the media file you choose has no audio, you will be allowed to choose one.
To view video information on video number 5:
More command usage on mps-youtube can be found by running the command:
$ mpsyt -h
We can now play and download video and audio files from the Linux terminal using the mps-youtube player.