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.
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
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
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
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
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
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.
Hi, Marin. Thanks for your considerate sharing. But I have to admit that commands are too complicated for me to understand. I usually use an online program called 2conv and offline software called Joyoshare Screen Recorder.
2conv is more convenient, but when it comes to some YouTube videos that claim copyright protection, it won’t work. And it has few supported formats. Joyoshare program works with most formats and can record videos in 1080P with or without sound. Glad to share it for those beginners.
Didn’t work for me, no matter which links I pasted, it returns “YouTube said: This video is unavailable.”
Hello there. Don’t lose faith in Youtube-dl :)
You probably just need to update the program itself. try
youtube-dl -U
and if that doesn’t work, delete your current installation and reinstall it.youtube-dl doesn’t work when the video has age restriction, it doesn’t matter if you put your credentials, not a good tool
I am getting Http Error 429: Too Many Requests
Any solution?
Regards
You can use the
--batch-file FILE
option or-a
for short if you want to use the text file with multiple links. It is very much simpler than the loop.I get the same thing. Error: YouTube said: This video is unavailable“.
@Geroge,
It worked for me, I tried to download
https://www.youtube.com/watch?v=bqWDLQVpHzk
and it worked for me.I get the same thing
https://www.youtube.com/watch?v=bqWDLQVpHzk
.Hi! I started using youtube-dl for my raspberry pi. It was working fine yesterday (Dec 26th) but every attempt to download a video today returns “Error: YouTube said: This video is unavailable“.
Just update or reinstall again
Thank you. I have been using AudFree software to download and convert music to MP3 and other common formats. It is compatible with almost all kinds of music resources from Apple Music, Spotify, Tidal, YouTube, which completely fulfill my needs.
Thanks! I used DRmare software download audios from YouTube videos.