#!/usr/bin/env bash USAGE="./yt-dlp-best [options] \"URL\" Fetches the best format of a YT video (ideally in mp4) Options: -y skips the format check normally requiring user action to continue with download" SKIP_CHECK=0 if [ $# -eq 1 ]; then URL=$1 else if [ $# -eq 2 ]; then if [ "$1" == "-y" ]; then SKIP_CHECK=1 URL=$2 fi else echo "$USAGE" exit 1 fi fi DESIRED_FMT="mp4" FMT_LINE=$(yt-dlp -F "${URL}" | grep "${DESIRED_FMT}" | tail -n 1) FMT=$(echo ${FMT_LINE} | cut -d" " -f1) echo "${FMT_LINE}" echo "yt-dlp -f ${FMT}+m4a \"${URL}\"" if [ $SKIP_CHECK -eq 0 ]; then read -p "proceed (Y/N): " answer else # basically force a "yes" answer answer="y" fi if [[ "$answer" =~ ^[yY][eE]{0,1}[sS]{0,1}$ ]]; then yt-dlp -f ${FMT}+m4a "${URL}" exit 0 else echo "Okay, cancelling" exit 1 fi