#!/bin/bash
#
# This script is called from VDR to start MPlayer
#
# argument 1: the file to play
# argument 2: (optional) the phrase SLAVE if SlaveMode is enabled
# argument 3: (optional) the phrase AID x to select audio stream x


# Updated to accept playing of vdr files (useful in roaster menu)
#					11/03/2006   John Germs

# where to find mplayer
#MPLAYER="xineplayer"
MPLAYER="mplayer"


# mplayer options, -vc will be added below
# add "-lircconf <lircrc>" to enable LIRC support
OPTS="-vo mpegpes"

# mplayer options for SlaveMode
SLAVE="-slave -quiet -nolirc"

# random options
ropt="-framedrop -cache 4096"

#####################

FILE=$1
case "$FILE" in
*.pls | *.m3u)
  popt="-playlist"
  first=`grep -v -m1 "^#" $FILE`
  type=`file "$first"`
  ;;
*)
  type=`file "$FILE"`
  ;;
esac

while shift; do
  if [ "$1" = "SLAVE" ]; then
    sopt=$SLAVE
  elif [ "$1" = "AID" ]; then
    aopt="-aid $2"
    shift
  fi
done

case "$FILE" in
*.avi | *.wmv)
  VC="-vop lavc=0:30,expand=220:480:-1:-1:1,scale=220:383"
# VC="-vc ffdivx"
  ;;
*.mpg | *.vdr)
  VC="-vc mpegpes"
  ;;
*)
  echo "Unknown video file format $type"
  echo "Edit mplayer.sh to support this file type"
  exit 1
  ;;
esac

exec $MPLAYER $OPTS $VC $ropt $sopt $aopt $popt "$FILE"
