#! /bin/bash

# draai123 - wrapper for ogg123 and mpg321.  See also music123.

#
# suggested usage:
#
#  ~$ cat <<EOT >muziekje
#   #!/bin/sh
#   find "$@" -type f | dr_permutate | while read t; do draai123 "$t"; done
#  EOT
#
#  ~$ muziekje [A-W]*
#  ~$ muziekje

#fixme: /bin/sh, use
#
#case $1 
#  *.ogg
#  ;;

if [[ "$1" == *.ogg ]]
then
    ogg123 -d alsa09 "$1"
    # ogg123 -d oss "$1"
    # 2>&1 | egrep -v '^Device|^Author|^Comments'
    # that would screw up the nice curses tricks...
    # it's NOT ogg123 which tries to be smart whether we have a tty.
    # it's probably grep screwing up.
    # | cat   works just fine.
elif [[ "$1" == *.mp3 ]]
then
    echo -n "Playing: "
    if command -v id3 >/dev/null
    then
        id3 -l "$1"
    elif command -v mp3info >/dev/null
    then
        echo
        mp3info "$1"
    else
        echo $1
    fi
    mpg321 -v -q "$1"
    # mpg321 "$1" 2>&1 | egrep -v '^High|^Version |^Uses |^THIS|^Directory'
elif [[ "$1" == *.flac ]]
then
    if command -v flac123 >/dev/null
    then
        flac123 "$1"
    else
        echo >&2 Skipping $1: no flac player found
    fi
else
    echo >&2 Skipping $1: .ogg nor .mp3 nor .flac
fi

echo '...........................................................................'

