#!/bin/bash

if [[ $1 == "-h" || $1 == "--help" || $@ == "" ]]; then
  echo "id3convert interface (C) 2005 by Georg Hennig"
  echo " - converting recursivly all mp3's in the current directory"
  echo " - passing all arguments to id3convert"
  echo ""
  echo "Usage: cd /your/desired/directory"
  echo "       id3convert_here [id3convert switches]"
  echo ""
  echo "id3convert help:"
  echo ""
  id3convert --help
  exit 0
fi

echo "Building index of current directory..."

find . -type f -regex ".*.*3" -printf "%h/%f\n" > convert_tmp 2>/dev/null
LINES=`(set \`wc -l convert_tmp\`; echo $1 )`

exec < convert_tmp

echo "Running id3convert $@ on $LINES files..."

for (( i=1; i<=LINES; i++ ))
{
  read FILE
  echo "Processing file #$i of $LINES..."
  id3convert $@ "$FILE" >/dev/null
}

rm convert_tmp

echo "id3convert_here $@ finished."

exit 0
