There have been many occasions in the past when I wanted to download and listen to the audio version of an online video to help save data while I was away from a WiFi connection. I looked into many different online converters, but all of them had some type of issue. These websites would contain either a lot of advertisements, malware, or they didn't work correctly. As a Software Engineer, I set out to find what technology was used for these websites in order to replicate my own tool to use. This led me into developing several advanced applications to use as multimedia tools.
In this guide, I am going to show you how to easily convert an online video to an offline MP3 file by using a free open-source tool that you can install on your own computer. In a future guide, I may expand on this and show you how to use this tool within a Python application for more advanced functionality.
The tool that we will be using is called YT-DLP and is available for Windows, macOS, Linux, and BSD. Using this tool is the same across all platforms but installing it will depend on the platform that you are using.
What is YT-DLP?
YT-DLP is a command-line program to download videos from online sites. It requires the Python interpreter, version 2.6, 2.7, or 3.2+. It is released to the public domain, which means you can modify it, redistribute it, or use it however you like.
How to Install
Installing YT-DLP is quite easy but depends on your operating system for which method of installation you will need to use.
Linux, macOS, and BSD
Both Linux and macOS can install YT-DLP with either cURL or wget. If you don't have cURL installed, you can use wget or aria2c.
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
sudo aria2c https://github.com/yt-dlp/yt-dlp/releases/latest/download/yt-dlp –dir /usr/local/bin -o yt-dlp
sudo chmod a+rx /usr/local/bin/yt-dlp
To update, run:sudo yt-dlp -U
With PIP
You can install the PyPI package with:
python3 -m pip install -U yt-dlp
You can install without any of the optional dependencies using:python3 -m pip install –no-deps -U yt-dlp
If you want to be on the cutting edge, you can also install the master branch with:python3 -m pip install -U pip setuptools wheel
python3 -m pip install –force-reinstall https://github.com/yt-dlp/yt-dlp/archive/master.tar.gz
On some systems, you may need to use py or python instead of python3.
To update, run:
python3 -m pip install -U yt-dlp
Windows
To install YT-DLP on Windows, you will need to download the executable file ( yt-dlp.exe ) and modify your system path to include the full location of the executable file.
Converting Videos to MP3
The YT-DLP application supports a wide range of video websites that you can use for your personal conversion needs. For this guide, I am going to use a video from Rumble as an example. I am going to convert a video titled “Cybersecurity for Beginners” to an MP3 file. Rumble is a little different from most video websites when it comes to converting videos. Normally, you would just need to pass the link to the video to the YT-DLP application, however, with Rumble you have to pass the embed link to YT-DLP.
This is the embed link that I will be using for this demonstration:
https://rumble.com/embed/vgpa8x/?pub=90mk9
All interaction with YT-DLP is done through the terminal or command prompt, so go ahead and launch an instance of it before we insert the command. Since we are only going to be extracting the audio from the video, we will be using the -x option with YT-DLP. This will convert the video to audio only.
yt-dlp -x https://rumble.com/embed/vgpa8x/?pub=90mk9
Terminal Output::~$ yt-dlp -x https://rumble.com/embed/vgpa8x/?pub=90mk9</p>
[RumbleEmbed] Extracting URL: https://rumble.com/embed/vgpa8x/?pub=90mk9
[RumbleEmbed] vgpa8x: Downloading JSON metadata
[info] vgpa8x: Downloading 1 format(s): mp4-1081p
[download] Destination: Cybersecurity for Beginners [vgpa8x].mp4
[download] 100% of 410.24MiB in 00:00:17 at 23.06MiB/s
[ExtractAudio] Destination: Cybersecurity for Beginners [vgpa8x].m4a
Deleting original file Cybersecurity for Beginners [vgpa8x].mp4 (pass -k to keep)
The file that you downloaded will be saved in the same directory from where you ran the YT-DLP command. The command above will not automatically convert the video into an MP3 file, instead, it will be downloaded as an M4A file. In order to convert the video into an MP3, we must pass the –audio-format option with the command and tell it to use the MP3 format.
yt-dlp -x –audio-format mp3 https://rumble.com/embed/vgpa8x/?pub=90mk9
Terminal Output::~$ yt-dlp -x –audio-format mp3 https://rumble.com/embed/vgpa8x/?pub=90mk9</p>
[RumbleEmbed] Extracting URL: https://rumble.com/embed/vgpa8x/?pub=90mk9
[RumbleEmbed] vgpa8x: Downloading JSON metadata
[info] vgpa8x: Downloading 1 format(s): mp4-1081p
[download] Destination: Cybersecurity for Beginners [vgpa8x].mp4
[download] 100% of 410.24MiB in 00:00:18 at 22.52MiB/s
[ExtractAudio] Destination: Cybersecurity for Beginners [vgpa8x].mp3
Deleting original file Cybersecurity for Beginners [vgpa8x].mp4 (pass -k to keep)
There are a lot of different options available that you can use with YT-DLP which can be found within the documentation. I have been able to convert and download anything from static videos to dynamic videos that use Blob. The uses for this application can be limitless and it all depends on the way you want to use it.