Have you ever got issues with watching a YouTube video where the Wi-Fi coverage is spotty? Or you want to watch a 4k video but the download speeds are too slow? For whatever reasons, you can mitigate these issues by storing your favorite YouTube videos locally with the help of the terminal on your Mac. Here’s how to do it.
What is youtube-dl
You can easily archive all YouTube videos using youtube-dl. Youtube-dl (the dl stands for “download”) is open source that supports many platforms, including macOS. It’s simply a command line utility, which can be run in the terminal application.
How to install youtube-dl
There are a few ways to install youtube-dl on your Mac.
- First, you need to download the source code and then build it by using a compiler.
- You can also install Homebrew as a package manager and then you have the youtube-dl executable installed.
- Finally, install the pre-built app directly by entering the following commands in terminal.
- sudo curl -L https://yt-dl.org/downloads/latest/youtube-dl-o /usr/local/bin/youtube-dl
- sudo chmod a+rx /usr/local/bin/youtube-dl
How to use youtube-dl
Using youtube-dl is similar to copying the URL of your favorite video to archive and then append it to the youtube-dl command in your MacOS’s terminal. But there are also other nifty options to make sure that you get the desired video quality level.
For instance, if you simply want to download and watch a video on YouTube, just do the following steps
- Open terminal on your Mac
- Enter youtube-dl URL_OF_VIDEO
- Click on return >Done.
The app will automatically download the “best” version containing both video and audio. Once done, you can then use your video player to play the downloaded file.
But, if you want to download a specific resolution, you can download the video portion, or if you just want an audio-only portion, here’s how to do it.
- Open terminal app
- Type in youtube-dl -F URL_OF_VIDEO
- Click on return.
You’ll then see a list of formats to choose from. Some format codes come with both audio and video, while some only include video and some just have audio.
If you want to download the specific format, enter the following in the terminal:
- youtube-dl -f 313 URL_OF_VIDEO.
You will now download the 4K video only portion. But you need to download the audio separately. For example, if the audio-only version is format code 251, you simply enter the following in terminal.
- youtube-dl -f 251 URL_OF_VIDEO -o AUDIO_ONLY.output.
In order to play the two files simultaneously, you will need a compatible media player to synchronously mux the two files. VLC is a good choice for you. For example, if you’d like to install mplayer, you can type in the following in the terminal:
- mplayer -lavdopts threads=6 -audiofile AUDIO_ONLY.output DOWNLOADED_VIDEO_FILE_NAME.
You can now enjoy your locally stored video and audio without a good internet connection. If you need more information about using youtube-dl, then you can read the youtube-dl manual in the terminal by entering the command: man youtube-dl.