#!/bin/sh
set -e

FFMPEG=`which ffmpeg`

if test -z "$FFMPEG"; then
	echo "ffmpeg must be installed"
	exit 1
fi

SED=`which gsed`

if test -z "$SED"; then
  SED=`which sed`
fi

if test -z "$SED"; then
  echo "sed or gsed much be installed"
  exit 1
fi

$FFMPEG -i "$1" -vn -filter replaygain -f null /dev/null 2>&1 | $SED -n -r 's/.* track_gain = ([-+]?[0-9]+\.[0-9]+ dB).*/\1/p'

