#!/bin/bash

# Renames a wave file so that it contains no non-ASCII characters, throwing away
# any that do not have clear ASCII equivalents, then moves it (and its folder 
# tree) to /var/import/sanitize/.

# Designed for use with:
# find $1 -type f \! -newerat '30 minutes ago' -exec ./clean-filename.sh '{}' \;

FINISHED=`echo $1 | sed "s|/var/import/automatic/unsanitized/|/var/import/automatic/sanitized/|"`
FOLDER=`echo $1 | sed "s|/var/import/automatic/unsanitized/|/var/import/automatic/sanitized/|" |  sed "s|/[^/]*$||"`

WAV=`echo $1 | grep -E '\.(wav|wave)$'`

if [ "" != "$WAV" ]
then
	NEW=`echo $1 | iconv -c -t ASCII | sed "s|/var/import/automatic/unsanitized/|/var/import/automatic/sanitized/|"`
	mkdir -p "$FOLDER"
	mv "$1" "$NEW"
fi

