wiki/structured/cli.youtube-dl.org
Gabriel Arazas 92a8179dd0 Update formatting on the command line notes
Along with some extra updates for a note about GitHub Actions.
2021-07-10 22:20:08 +08:00

2.6 KiB

Command-line: youtube-dl

One of the archivists' best friends. At least you don't have to go to those shady YouTube conversion sites anymore when you have a complete list of other video sites you can download from.

Synopsis

youtube-dl [OPTIONS...] [URLS...]

Options

  • --add-metadata - add metadata to the resulting file
  • --audio-format [EXTENSION] - download the video with the select format of "opus", "mp3", "opus", and "vorbis"; but there is also the convenient "best" option
  • --audio-quality [QUALITY] - quality of the audio from 0 to 9, best to worst respectively; bitrates are also accepted (e.g., 320K, 1M)
  • --config-location [PATH] - set the config to be used; useful for local configs with specific options
  • -F, --list-format - prints a list of format available for downloading
  • --format [QUALITY] - download the video with the format shown in --list-format; there are convenient options such as bestaudio and bestvideo referring to the best quality it could find
  • -j, --dump-json - dry-run and prints in JSON format
  • --no-overwrite - error if the file already exists which is handy for scripts
  • --write-sub - writes the subtitle file into disk
  • -x, --extract-audio - extract only the audio track

Examples

Here is an entryway into your newfound archiving habit. Enjoy! :)

Download the thumbnail and the audio of the video

Very simple. Very useful as most of the thumbnails can go to high resolution and if you need them for some reason.

youtube-dl --write-thumbnail --extract-audio https://www.youtube.com/watch?v=wy9VvdaLuSs

Download an entire album

Though, you should look at the supported sites if it supports downloading an album out of the URL. In this example, we have Bandcamp.

youtube-dl --output '%(title)s.%(ext)s' --format bestaudio https://gametal.bandcamp.com/album/side-quests-vol-3

Specific video download requirements

In this example, I want to download a video with a width of 1080px and the best video and audio at 320Kbit/s. Oh, and the video should be in MP4 and the audio in Opus.

This is will only succeed if the format is available to download which you can do with --list-format.

youtube-dl --format 'bestvideo[width=1080,ext=mp4]+bestaudio[abr=320K,ext=opus]' https://www.youtube.com/watch?v=wy9VvdaLuSs