Skip to content

Instantly share code, notes, and snippets.

@thingsiplay
Created May 19, 2024 13:07
Show Gist options
  • Save thingsiplay/bf0fb23ed62b9a2fb613c03fa6fe897d to your computer and use it in GitHub Desktop.
Save thingsiplay/bf0fb23ed62b9a2fb613c03fa6fe897d to your computer and use it in GitHub Desktop.
ytvideo - YouTube video downloader wrapper to yt-dlp
#!/bin/sh
# Default values.
quality='bestvideo[ext=mp4]+bestaudio[ext=m4a]/mp4'
limit='4.8'
metaextras='--add-metadata --write-description --write-info-json --write-sub'
OPTIND=1
while getopts ':hbp:s:M' OPTION; do
case "$OPTION" in
h)
echo 'ytvideo [-b] [-p HEIGHT] [-s LIMIT] [-o FILE] [-M]
options:
-b best quality (default)
-p HEIGHT max allowed pixel dimensions, example "480"
-s LIMIT download speed limit in MB, example "4.8"
-M no meta, description and extras files
2024 © Tuncay D.'
exit 0
;;
b)
quality='bestvideo[ext=mp4]+bestaudio[ext=m4a]/mp4'
;;
p)
quality="bestvideo[height<=${OPTARG}]+bestaudio/best[height<=${OPTARG}]"
;;
s)
limit="${OPTARG}"
;;
M)
metaextras=''
;;
?)
continue
;;
esac
done
shift "$((OPTIND - 1))"
for url in "${@}"; do
yt-dlp \
${metaextras} \
--ignore-errors \
--rate-limit "${limit}"M \
-f "${quality}" \
-o '%(title)s.%(ext)s' \
-- "${url}"
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment