Download Youtube videos on Linux & Macos

You can download easily with a command-line program called youtube-dl.
Link to site

For Macos goto:
Link to site

Install

Linux

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

Macos

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

Upgrade (always use the latest version!)

Linux

sudo -H pip install --upgrade youtube-dl

Macos

sudo yt-dlp -U

Download a single movie in mp4 format and best quality

Tip: create a video folder and open the terminal from this folder to execute the statements.

Linux

youtube-dl -f 'bestvideo[ext=mp4]+bestaudio[ext=m4a]/bestvideo+bestaudio' --merge-output-format mp4 <video-url>

Macos

yt-dlp -f 'bestvideo[ext=mp4]+bestaudio[ext=m4a]/bestvideo+bestaudio' --merge-output-format mp4 <video-url>

Everywhere below where you see youtube-dl as command, use yt-dlp when on Macos

Download all videos in a playlist at once

youtube-dl -f 'bestvideo[ext=mp4]+bestaudio[ext=m4a]/bestvideo+bestaudio' --merge-output-format mp4 --output "%(title)s.%(ext)s" --yes-playlist <url-playlist>

De url-playlist is only the playlist code! Like in:

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

and then only:

PLft3EoQOvsCC838k0rX3jZs6c740Li4yi

Download a batch of movies in mp4 format and best quality

First create a file named something like videos.batch and place on every line a video that you would like to download, like:

https://www.youtube.com/watch?v=I_izvAbhExY
https://www.youtube.com/watch?v=5uHityNBtFY

Now you can download everything at once with the following command:

youtube-dl -a videos.batch -f 'bestvideo[ext=mp4]+bestaudio[ext=m4a]/bestvideo+bestaudio' --merge-output-format mp4

Download just music in the best possible quality

youtube-dl -f bestaudio --extract-audio --audio-format mp3 --audio-quality 0 <Video-URL>
Last update: Mon, 15 May 2023 13:30:37