less than 1 minute read

yt-dlp can download videos from many websites. If the website offers multiple audio tracks for a video, here is how to download and integrate it into the video file.

The parameters for the script are

  1. The URL
  2. The expected file name
#!/bin/bash

set -eu -o pipefail

echo "Downloading ${1} as ${2}"

AUDIO=$(yt-dlp --dump-json "${1}" | jq -r '[[.formats[] | select(.vcodec == "none") | .language] | sort | unique[] | "+bestaudio[language=\(.)]"] | join("")')

yt-dlp --write-subs --sub-langs 'deu,eng,fra' --audio-multistreams --format "bestvideo${AUDIO}" --embed-metadata --merge-output-format 'mp4' --write-thumbnail --output "${2}.%(ext)s" "${1}"