#!/bin/sh

#set -x

HB="/usr/local/bin/HandBrakeCLI"

f_usage() {
    echo "Usage: $0 <HB|MI> <VIDEOFILE|VIDEODIR>"
}

if [ "$1" = "" ] || [ "$2" = "" ]; then
    f_usage
    exit 1
fi


if [ -f $2 ]; then
    case "$1" in
	HB)
	    $HB -i $2 -t 0 2>&1 | awk '/^\+/ { while ( /\+/ ) {printf("%s\n",$0); getline}}'
	    ;;
	MI)
	    mediainfo $2
	    ;;
	*)
	    f_usage
	    ;;
    esac
elif [ -d $2 ]; then
    if [ -e "$2/00001.ts" ]; then
	FILE="00001.ts"
    else
	FILE="001.vdr"
    fi
    case "$1" in
	HB)
	    $HB -i "$2/$FILE" -t 0 2>&1 | awk '/^\+/ { while ( /\+/ ) {printf("%s\n",$0); getline}}'
	    ;;
	MI)
	    mediainfo "$2/$FILE"
	    ;;
	*)
	    f_usage
	    ;;
    esac
else
    f_usage
    exit 1
fi

