#!/usr/bin/env bash

####PROGRAM START####
echo "Path to playlist must be entered as /home/user/playlist.m3u"
echo -n "Enter path to playlist: "
read FILE

while read files; do
echo
if ${BB_MP3DEC} -w "${files}.wav" "${files}"; then
	echo "'${files}.wav' created..."
	mv "$files.wav" "${BBBURNDIR}"
	echo "'${files}.wav' moved to '${BBBURNDIR}', moving on..."
else
	echo "'${files}.wav' couldn't be created." 1>&2
	echo "Maybe you need to adjust some permissions?" 1>&2
	wait_for_enter
fi
	echo
	existing="yes"
done < <(grep -s [Mm][Pp]3 "${FILE}" | grep -v EXTINF)

if [[ "$existing" != "yes" ]]; then
	echo
	echo "Bad input file ('${FILE}')"
	echo "Maybe you entered the wrong path?" 1>&2
	wait_for_enter
	exit
fi

