#!/bin/sh -e

flags=$(getopt -l "copy" -o "c" -a -- "$@")
eval set -- "${flags}"

other_options=""

for _ in ${flags}; do
  # shellcheck disable=SC2249
  case "$1" in
    -c | --clip)
      other_options="${other_options} --exec after_move:fcp"
      ;;

    --)
      shift
      break
      ;;
  esac
  shift
done

# shellcheck disable=2086
yt-dlp \
  --embed-metadata \
  -S "res:1080" \
  --exec before_dl:"notify-send 'Started download'" \
  --exec after_move:"notify-send 'Finished downloading'" \
  --sponsorblock-mark sponsor \
  --write-auto-subs \
  --embed-subs \
  --embed-thumbnail \
  --embed-chapters \
  --embed-info-json \
  ${other_options} \
  "$@"
