#
# Copyright (C) by Stefano Falsetto
# e-mail contact ....: mailto:stefko5@inwind.it
#
#    This program is free software; you can redistribute it and/or modify
#    it under the terms of the GNU General Public License as published by
#    the Free Software Foundation; either version 2 of the License, or
#    (at your option) any later version.
#
#    This program is distributed in the hope that it will be useful,
#    but WITHOUT ANY WARRANTY; without even the implied warranty of
#    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
#    GNU General Public License for more details.
#
#    You should have received a copy of the GNU General Public License
#    along with this program; if not, write to the Free Software
#    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
#
#
# Config plugin for mpg123
#

cat_variables_mpg123 () {

  cat <<EOF
# Complete path for mp3 decoder
mpg123_DECODER="$mpg123_DECODER"

# Parameters to only show a time line
EXTRACT_TIME="$EXTRACT_TIME"

# Parameters to output to stdout with buffered mode
BUFFERED_DECODE="$BUFFERED_DECODE"

# Parameters to output to stdout without buffer
DECODE_TO_STDOUT="$DECODE_TO_STDOUT"

# Parameters to simply decode
NORMALDECODE="$NORMALDECODE"

# Array of supported output format files
OUTPUT_FORMATS_mpg123=( $OUTPUT_FORMATS_mpg123 )

# Parameters to output to file in wav format
TO_wav="$TO_wav"

# Parameters to output to file in cdr format
TO_cdr="$TO_cdr"

# Parameters to output to file in au format
TO_au="$TO_au"

# default output file format
TOFMT="$TOFMT"

# Default conversion file extension
MPGCMD="$MPGCMD"

# Bound and criteria to check file type using magic file
# Layer 3
MPEGS1_1=$MPEGS1_1
MPEGS2_1=$MPEGS2_1
MPEGCRITERIA="$MPEGCRITERIA"
# Layer 2
MPEGS1_2=$MPEGS1_2
MPEGS2_2=$MPEGS2_2
MPEGCRITERIA_2="$MPEGCRITERIA_2"


EOF
}


. $PLUGINDIR/config/general/mp3funcs.inc

#############
# MAIN
#############

if [ $(expr "$SUPPORTED_FORMATS" : ".*mp3.*") -ne ${#SUPPORTED_FORMATS} ]; then
  begin_check mpg123
  find_prg mpg123
  mpg123_DECODER=$FOUND_PRG

  if [ -z $mpg123_DECODER ]; then
    missing mpg123 "http://www.mpg123.org"
  else
    QueryVersion $($mpg123_DECODER --help 2>&1|$GREP Version|cut -d' ' -f2) mpg123 "0.59r"
    shared_mp3_desc
    EXTENSIONS="mp3"
    SUPPORTED_FORMATS="$SUPPORTED_FORMATS $EXTENSIONS"
    OUTPUT_FORMATS_mpg123="wav cdr au"
    EXTRACT_TIME=" -t -q -v -n 0 "
    BUFFERED_DECODE=" -q -v -b 10000 -s "
    DECODE_TO_STDOUT=" --cdr - "
    NORMALDECODE=" -q -v "
    #OUTPUT_FORMATS=(wav cdr au)
    TO_wav="--wav"
    TO_cdr="--cdr"
    TO_au="--au"
    TOFMT=$TO_wav
    MPGCMD="wav"
    PLUGIN_MP3=mpg321
    AUDIO_PLUGINS="$AUDIO_PLUGINS mpg123"
    shared_summary_strings "$mpg123_DECODER"
    end_check
  fi
fi

