vohzd.com

Ripping Audio and Video from YouTube

1 min read

A quick reference for downloading from YouTube with embedded metadata, thumbnails, subtitles, the lot.

The tool of choice is yt-dlp, a maintained fork of the now-abandoned youtube-dl.

Install

# Linux / macOS
pip install yt-dlp

# or grab the binary directly
curl -L https://github.com/yt-dlp/yt-dlp/releases/latest/download/yt-dlp -o /usr/local/bin/yt-dlp
chmod a+rx /usr/local/bin/yt-dlp

Download as audio (best quality)

yt-dlp --download-archive archive.txt \
  -o "%(title)s-----%(id)s.%(ext)s" \
  -i -w --write-info-json --write-description \
  --add-metadata --all-subs --embed-thumbnail \
  --playlist-reverse --geo-bypass --write-thumbnail \
  --extract-audio --audio-quality 0 \
  "https://www.youtube.com/watch?v=YOUR_VIDEO_ID"

Force to MP3

Same as above, but add --audio-format mp3:

yt-dlp --download-archive archive.txt \
  -o "%(title)s-----%(id)s.%(ext)s" \
  -i -w --write-info-json --write-description \
  --add-metadata --all-subs --embed-thumbnail \
  --playlist-reverse --geo-bypass --write-thumbnail \
  --extract-audio --audio-quality 0 --audio-format mp3 \
  "https://www.youtube.com/watch?v=YOUR_VIDEO_ID"

Download as video

yt-dlp --download-archive archive.txt \
  -o "%(title)s---%(id)s.%(ext)s" \
  -i -w --write-info-json --write-description \
  --add-metadata --all-subs --embed-subs --embed-thumbnail \
  --playlist-reverse --geo-bypass --write-thumbnail \
  "https://www.youtube.com/watch?v=YOUR_VIDEO_ID"

What the flags do

  • --download-archive archive.txt: keeps track of what's already downloaded so you don't re-download
  • --embed-thumbnail: shoves the thumbnail into the file metadata
  • --add-metadata: embeds all available metadata
  • --audio-quality 0: best quality available
  • --geo-bypass: bypasses geographic restrictions where possible

The archive.txt trick is particularly handy for playlists. Run the command again later and it'll only grab new additions.