How to Download Audio Only Using youtube-dl

You can use youtube-dl to download only audio files from the online videos. Here's how to download entire playlists in MP3 format.
Warp Terminal

youtube-dl is a versatile command line tool for downloading videos from YouTube and many other websites. I use it for making back up of my own YouTube videos.

By default, you use youtube-dl for downloading videos. How about extracting only the audio with youtube-dl? That’s very simple actually. Let me show you the steps.

🚧
Downloading videos from websites could be against their policies. It’s up to you if you choose to download videos or audio.

Install youtube-dl first

Please make sure that you have installed youtube-dl on your Linux distribution first.

Since 2021, the usual snap and default package manager installations of youtube-dl give a broken utility. So, you need to install the Nightly version of youtube-dl to make it work.

The Nightly release contains recent changes and fixes so that you can run it without any error. I will describe the easiest way to set it up. First go to the Nightly release GitHub page.

Here, you can get a python file, named youtube-dl. Just download it. Once downloaded, copy that file to /usr/local/bin/. For this, open a terminal where you downloaded the file and then run:

sudo cp youtube-dl /usr/local/bin/

Now, give the file execution permission using the chmod command.

sudo chmod a+rx /usr/local/bin/youtube-dl

You cannot just run youtube-dl now, because of issue with python naming. It uses python while in Ubuntu-based systems, it is python3.

Python: No such file or directory error, when try to rrun youtube-dl initially
Python: No such file or directory error

So, you can create an alias for youtube-dl in your .bashrc.

alias youtube-dl='python3 /usr/local/bin/youtube-dl'

That’s it. You have set up youtube-dl in your system.

πŸ“‹
Remember
In order to download audio using youtube-dl, you should have FFMPEG installed on your system.

Download only audio with youtube-dl

If you only want to download audio from a YouTube video, you can use the -x option with youtube-dl. This extract-audio option converts the video files to audio-only files.

youtube-dl -x video_URL

The file is saved in the same directory from where you ran the youtube-dl command.

Here’s an example where I downloaded the voice-over of our Install Google Chrome on Ubuntu 24.04 video.

Download only audio from a video using youtube-dl "-x" option
Download only audio from a video using youtube-dl

Did you notice the audio format? It is in .m4a format. You may specify the audio format to something of your choice.

Say you want to extract the audio in MP3 format. You can use it like this:

youtube-dl -x --audio-format mp3 video_URL

Here’s the same example I showed previously. You can see that it uses ffmpeg to convert the m4a file into MP3.

Download audio in a format specified, instead of the default m4a
Download MP3 File
πŸ’‘
By default, youtube-dl deletes the older file, if you downloaded it twice, even if it's in a different format. So, you can use the -k option to preserve the old file along with the new one.

Download entire YouTube playlist in MP3 format

Yes, you can totally do that. The main thing is to get the URL of the playlist here. It is typically in the following format:

https://www.youtube.com/playlist?list=XXXXXXXXXXXXXXXXXXX

To get the URL of a playlist, click on its name when the playlist is being displayed in the right sidebar.

Click on the title of the playlist, appears on the right side, while you play a video.
Click on the title of the playlist

It will take you to the playlist page, and you can copy the URL here.

Copy the URL of the playlist from the address bar of the browser
Copy the URL of the playlist

Now that you have the playlist URL, you can use it to download the audio files in MP3 format in the following fashion:

youtube-dl --extract-audio --audio-format mp3 -o "%(title)s.%(ext)s" playlist_URL

That scary looking -o "%(title)s.%(ext)s" specifies the output file (with option -o) and instructs it to use the title of the video and the extension (MP3 in this case) for naming the audio files.

Download audio from all the videos on a playlist
Download audio from all the videos on a playlist

I hope you find this quick tip helpful. Enjoy the audio files πŸ˜„

About the author
Abhishek Prakash

Abhishek Prakash

Created It's FOSS 11 years ago to share my Linux adventures. Have a Master's degree in Engineering and years of IT industry experience. Huge fan of Agatha Christie detective mysteries πŸ•΅οΈβ€β™‚οΈ

Become a Better Linux User

With the FOSS Weekly Newsletter, you learn useful Linux tips, discover applications, explore new distros and stay updated with the latest from Linux world

It's FOSS

Great! You’ve successfully signed up.

Welcome back! You've successfully signed in.

You've successfully subscribed to It's FOSS.

Success! Check your email for magic link to sign-in.

Success! Your billing info has been updated.

Your billing was not updated.