#!/bin/sh -e
#
# mpvl - starts a media file in mpv looped
# dependencies: mpv
#
# usage: mpvl [<start> <stop>] <file>
#
#   - if only `file` given, loops the whole file
#   - if `start` and `stop` given, loops the section between those timecodes

flags=
file=

if [ "$#" -eq 3 ]; then
  flags="--start=$1 --ab-loop-a=$1 --ab-loop-b=$2"
  file="$3"
elif [ "$#" -eq 1 ]; then
  flags=--loop
  file="$1"
else
  printf '%s\n' "Usage: mpvl [<start> <stop>] <file>"
  exit 1
fi

mpv "${flags}" "${file}"
