#!/bin/sh

ARTIST=`metaflac "$1" --show-tag=ARTIST | sed s/.*=//g`
TITLE=`metaflac "$1" --show-tag=TITLE | sed s/.*=//g`
ALBUM=`metaflac "$1" --show-tag=ALBUM | sed s/.*=//g`
GENRE=`metaflac "$1" --show-tag=GENRE | sed s/.*=//g`
TRACKNUMBER=`metaflac "$1" --show-tag=TRACKNUMBER | sed s/.*=//g`
#echo
#echo "Launching: flac --silent -c -d $1 | lame -q 0 --quiet --preset 96 - $2"
#echo

flac --silent -c -d "$1" | lame -q 0 --quiet --preset 96 - "$2"

#echo
#echo "Setting id3 ($TITLE, $TRACKNUMBER, $ARTIST, $ALBUM, $GENRE)"
#echo

if test "x$TITLE" != "x"; then
id3 -t "$TITLE" "$2" > /dev/null
fi

if test "x$TRACKNUMBER" != "x"; then
id3 -T "$TRACKNUMBER" "$2" > /dev/null
fi

if test "x$ARTIST" != "x"; then
id3 -a "$ARTIST" "$2" > /dev/null
fi

if test "x$ALBUM" != "x"; then
id3 -A "$ALBUM" "$2" > /dev/null
fi

if test "x$GENRE" != "x"; then
id3 -g "$GENRE" "$2" > /dev/null
fi
