Skip to content

Instantly share code, notes, and snippets.

@masterflitzer
Last active August 15, 2025 09:35
Show Gist options
  • Select an option

  • Save masterflitzer/3ffc22dffe40ae533638e0f71dbf01d1 to your computer and use it in GitHub Desktop.

Select an option

Save masterflitzer/3ffc22dffe40ae533638e0f71dbf01d1 to your computer and use it in GitHub Desktop.
yt-dlp helper script
#!/usr/bin/env bash
set -o errexit
set -o nounset
set -o pipefail
shopt -s inherit_errexit
arg_count="${#@}"
# script assumes the url is passed as last argument
url="${!#}"
if test "${arg_count}" -eq 0
then
printf "Usage:\n\t%s\n\t%s\n\t%s\n\t%s\n\n%s\n" \
'yt-dlp.sh "https://youtu.be/xxx"' \
'yt-dlp.sh "https://youtube.com/watch?v=xxx"' \
'yt-dlp.sh "https://youtu.be/xxx?list=xxx"' \
'yt-dlp.sh "https://youtube.com/playlist?list=xxx"' \
"always pass the download url as the last argument"
exit 1
fi
if grep -Eiq "[?&]list=" <<< "${url}"
then
output_template="%(playlist)s/%(playlist_index)s-%(title)s.%(ext)s"
else
output_template="%(title)s.%(ext)s"
fi
yt-dlp \
--format-sort "quality, res, fps, hdr, vcodec:av1, channels, acodec" \
--merge-output-format "mkv" \
--no-overwrites \
--output "${output_template}" \
--prefer-free-formats \
--remux-video "mkv" \
--restrict-filenames \
"${@}"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment