How to Download Songs from a YouTube Video Using YTP-DL

We all love listening to music whether it’s in the gym, at work, or outside, music is part of our life. Everyone has their own music collection and undoubtedly everyone likes to expand it.

While there are streaming services such as Spotify, many people still like downloading their own music and organizing their albums and playlists.

Today we are going to show you how to easily download mp3 songs from YouTube videos. To complete this, we will be using yt-dlp – a command line video download tool for Linux.

yt-dlp is an improved fork of youtube-dl, which is a popular command-line tool for downloading videos from various websites, including YouTube. yt-dlp offers the same functionality as youtube-dl, along with additional features and bug fixes.

youtube-dl is dead, the project was discontinued in December 2022 after receiving a DMCA takedown notice from Google.

In this tutorial, you will learn how to download mp3 tracks from Youtube using the yt-dlp tool. Of course, first, you will need to have it installed on your system.

If you haven’t checked the above article yet, here is how to install it:

Install yt-dlp – A Youtube Video Downloader for Linux

The package yt-dlp is available for RHEL-based and Debian-based distributions and it can be easily installed by using your favorite package manager.

$ sudo apt install yt-dlp [On Debian, Ubuntu and Mint]
$ sudo yum install yt-dlp [On RHEL/CentOS/Fedora and Rocky/AlmaLinux]
$ sudo emerge -a sys-apps/yt-dlp [On Gentoo Linux]
$ sudo apk add yt-dlp [On Alpine Linux]
$ sudo pacman -S yt-dlp [On Arch Linux]
$ sudo zypper install yt-dlp [On OpenSUSE] 

Alternatively, to install the most latest version of yt-dlp, use the following curl or wget to download the official binary file for your operating system.

$ sudo curl -L https://github.com/yt-dlp/yt-dlp/releases/latest/download/yt-dlp -o /usr/local/bin/yt-dlp
$ sudo chmod a+rx /usr/local/bin/yt-dlp
$ sudo wget https://github.com/yt-dlp/yt-dlp/releases/latest/download/yt-dlp -O /usr/local/bin/yt-dlp
$ sudo chmod a+rx /usr/local/bin/yt-dlp # Make executable

Download MP3 (Songs) from YouTube Video on Linux

The yt-dlp command has quite an extensive "help" page and if you want to review it, simply type:

$ yt-dlp --help
yt-dlp Help and Usage
yt-dlp Help and Usage

If you are looking for a specific option, I recommend using the grep command and searching for a specific word as shown.

$ yt-dlp --help | grep extract-audio
Use Grep to Search a Word in File
Use Grep to Search a Word in a File

Now to download a video as an mp3 track, we need the following two options:

  • --extract-audio (short option -x) – Convert video files to audio-only files.
  • --audio-format  – specifies the audio format in which the file will be downloaded.

The supported audio formats are “best“, “aac“, “vorbis“, “mp3“, “m4a“, “opus“, or “wav“; “best” is set by default.

Download YouTube Video as a Song

To download a video as a song file, you can use one of the following commands:

$ yt-dlp -x --audio-format mp3 https://www.youtube.com/watch?v=wp43OdtAAkM
Save YouTube Video as Song
Save YouTube Video as Song

If you want to have cover art for the song file, you can add the --embed-thumbnail option:

In that case, the command will look like this:

$ yt-dlp -x --embed-thumbnail --audio-format mp3 https://www.youtube.com/watch?v=MwpMEbgC7DA
Save YouTube Video as Song with Thumbnail
Save YouTube Video as Song with Thumbnail

Download All Songs from a YouTube Playlist

As you probably noticed, youtube playlists are getting more and more popular lately. So the chances are that you will want to download more than one track from a playlist. Luckily yt-dlp provides an option to download a whole playlist or just a range of songs within it.

For that purpose, you will need to use the following options:

  • --playlist-start NUMBER – Playlist video to start at (default is 1).
  • --playlist-end NUMBER – Playlist video to end at (default is last).

Where "NUMBER" is the starting and ending point of the playlist. The command below will download the first 5 songs from the given playlist:

$ yt-dlp -x --audio-format mp3 --playlist-start 1 --playlist-end 5 https://www.youtube.com/playlist?list=PL9LUD5Kp855InMnKTaRy3LH3kTIYJyBzs
Download Multiple MP3 from Youtube Playlist
Download Multiple MP3s from Youtube Playlist

If you prefer to download the whole playlist, don’t use the playlist-start and playlist-end parameters. Instead, simply pass the playlist URL.

Download All Songs from Multiple YouTube Playlists

First, you need to create a text file (e.g., playlists.txt) and paste the URLs of the YouTube playlists that contain the songs you want to download.

Open a terminal and run the following command to download all songs from the playlists:

$ yt-dlp -x --audio-format mp3 -i --batch-file='path/to/playlists.txt'

The above is a simple solution to download multiple songs from different Youtube URLs.

Update YTP-DL

ytp-dl itself can be updated to the latest version using the following command.

$ yt-dlp -U
Conclusion

yt-dlp is a simple, yet powerful tool that can help you to download music on your devices. You are now ready to expand your music libraries to a whole new level.

If you have any questions or comments, please do not hesitate to submit them in the comment section below.

Similar Posts