Skip to content

Instantly share code, notes, and snippets.

@marschr
Last active April 14, 2021 14:41
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save marschr/79104fb81a8b1674f3f77d4c7203a79b to your computer and use it in GitHub Desktop.
Save marschr/79104fb81a8b1674f3f77d4c7203a79b to your computer and use it in GitHub Desktop.
youtube-dl quick helper script (defaults to 1080p)
#!/bin/bash
GREEN='\033[0;32m'
RED='\033[0;31m'
NC='\033[0m' # No Color
DEFAULT_RES=1080
usage()
{
# Display Help
echo "Usage: ytdl [2160|1440|1080|720] YOUTUBE-URL [YOUTUBE-URL2]..."
echo " defaults to ${DEFAULT_RES}p"
}
YTDL_PATH=$HOME/Videos/ytdl
CHOSEN_RES=''
case $1 in
"" )
usage
exit ;;
2160 | 1440 | 1080 | 720 )
CHOSEN_RES=$1
shift ;;
-h|--help )
usage
exit ;;
* )
esac
shift
#check for ytdl dir
if [[ ! -d ${YTDL_PATH} ]]; then
echo -e "${RED}Temp dir not found, creating...${NC}"
mkdir -p $YTDL_PATH
fi
if [[ $CHOSEN_RES == '' ]]; then
VIDEO_RES=DEFAULT_RES
echo -e "${RED}No video resolution arg found, defaulting to ${VIDEO_RES}p.${NC}"
else
VIDEO_RES=$CHOSEN_RES
echo -e "${GREEN}Setting video resolution to ${VIDEO_RES}p.${NC}"
fi
echo -e "${GREEN}Downloading $1 at ${VIDEO_RES}p resolution.${NC}"
echo -e "${GREEN}===========================================================${NC}"
youtube-dl \
-f "bestvideo[height<=?$VIDEO_RES]+bestaudio/best" \
-o $YTDL_PATH'/%(uploader)s/%(playlist)s/%(playlist_index)s - %(title)s - %(upload_date)s - %(id)s.%(ext)s' \
--write-description --write-info-json --write-annotations \
--write-all-thumbnails --all-subs --embed-subs --merge-output-format mkv \
--retries 20 --download-archive archive.txt $@
#--limit-rate 12M
if [ $? -eq 0 ]; then
echo -e "${GREEN}youtube-dl done!${NC}"
else
echo -e "${RED}youtube-dl failed!${NC}"
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment