#!/bin/sh -e
#
# yt-gum - download yt video from url
# dependencies: gum | ffmpeg | yt-dlp

if ! command -v gum >/dev/null 2>&1; then
  printf '%s' "${0##*/}: gum not found in PATH! Make sure you have it installed.\n" >&2
  exit 1
fi

input=$(gum input --placeholder "Video URL" --prompt.foreground 240)
time=$(gum input --placeholder "input time in seconds " --prompt.foreground 240)
runtime=$(gum input --placeholder "Enter how many seconds to download: " \
  --prompt.foreground 240)

printf '%s' "Input = " "${input}" "${time}"

gum spin --title "Downloading clip..." -- \
  yt-dlp --format "(bestvideo+bestaudio/best)[protocol!*=dash]" \
  --external-downloader ffmpeg \
  --external-downloader-args "ffmpeg_i:-ss ${time} -t ${runtime}" "${input}"
