Skip to content

Instantly share code, notes, and snippets.

@waynegraham
Last active October 29, 2021 14:05
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save waynegraham/c3c55969e97c39612c5fb686a1b49294 to your computer and use it in GitHub Desktop.
Save waynegraham/c3c55969e97c39612c5fb686a1b49294 to your computer and use it in GitHub Desktop.
Youtube-dl on macos

Youtube-dl is a popular commandline utility to download content from YouTube (among many other sites).

Install Youtube-dl

Open a termianl and type:

brew install youtube-dl ffmpeg

Examples

Download a video or playlist (just copy the URL from YouTube)

youtube-dl https://www.youtube.com/watch?v=d9_s8Bk_qcI

Download Multiple Videos

You can paste multiple video urls into the command and the utility will download them in order:

youtube-dl <url1> <url2>...

You can also create a text file (e.g. urls.txt) in the same directory and pass that with the -a flag:

youtube-dl -a urls.txt

Download audio-only

By default, audio extraction is done in ogg format. To get an mp3, pass the --audio-format flag:

youtube-dl -x --audio-format mp3 https://www.youtube.com/watch?v=dQw4w9WgXcQ

youtube-dl -x --audio-format mp3 -a urls.txt

Download video with description, metadata, annotations, subtitles, and thumbnail (e.g. everything)

youtube-dl --write-description --write-info-json --write-annotations --write-sub --write-thumbnail https://www.youtube.com/watch?v=d9_s8Bk_qcI

List all available formats of video or playlist

youtube-dl --list-formats https://www.youtube.com/watch?v=d9_s8Bk_qcI

Display the size of Youtube videos

youtube-dl -F https://www.youtube.com/watch?v=d9_s8Bk_qcI

Download videos in certain quality and/or format

y default, Youtube-dl will download the best available quality video. However, it is also possible to download a video or playlist at a specific quality or format.

YouTube is capable of downloading videos in the following qualities:

  • best - Select the best quality format of the given file with video and audio.
  • worst - Select the worst quality format (both video and audio).
  • bestvideo - Select the best quality video-only format (e.g. DASH video). Please note that it may not be available.
  • worstvideo - Select the worst quality video-only format. May not be available.
  • bestaudio - Select the best quality audio only-format. May not be available.
  • worstaudio - Select the worst quality audio only-format. May not be available.

For example, if you want to download best quality format (both audio and video), just use the following command:

youtube-dl -f best https://www.youtube.com/watch?v=d9_s8Bk_qcI

Similarly, to download audio-only with best quality:

youtube-dl -f bestaudio https://www.youtube.com/watch?v=d9_s8Bk_qcI

You also combine different format options like below.

youtube-dl -f bestvideo+bestaudio https://www.youtube.com/watch?v=d9_s8Bk_qcI

Download videos by file extension

youtube-dl --format mp4 https://www.youtube.com/watch?v=d9_s8Bk_qcI

If you want to download with custom filenames:

  youtube-dl -f mp4 -o '%(title)s.f%(format_id)s.%(ext)s' https://www.youtube.com/watch?v=d9_s8Bk_qcI

Set size limit for videos

  youtube-dl --min-filesize 100M <playlist_url>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment