#!/bin/sh
# Converts all files in the current directory
# for an external mp3 (only) player.
#
# Autor Thorsten Gunkel <tgunkel@gmx.de>
#
# Usage: 2mp3 [path]
#
# --- 05.01.2003 Thorsten Gunkel <tgunkel@gmx.de> ---
# * Add optional parameter to use a different path
# --- Initial Release ---
#

# You need these programs
trash_dir="_non_mp3"
ogg2mp3="/usr/local/_tg_scripte/ogg2mp3"

oldpfd="`pwd`"
startpfd="$1"
if [ ! -z "$startpfd" ]; then
 cd "$startpfd"
fi

for ifilename in *
 do
  filetyp="`echo "$ifilename" | sed s/"^.*\."//`"
  case "$filetyp" in
    m3u)
      echo "[M3U] Ignore $ifilename"
    ;;
    mp3)
      echo "[MP3] Ignore $ifilename"
    ;;
    ogg)
       eval "$ogg2mp3 $ifilename"
       # Move source file away
       if [ ! -d "$trash_dir" ]; then
        mkdir "$trash_dir/"
       fi
       if [ -d "$trash_dir" ]; then
        mv -b "$ifilename" "$trash_dir/"
       fi
    ;;
    *)
      echo "[XXX] Ignore unknow filetype: $ifilename"
    ;;
  esac
 done

cd "$oldpfd"
