#!/bin/bash
#
ext=mp3
#
origem=/media/
#
destino=/tmp/novo_$ext/
#
source ./cores
#
if [[ -d ${destino} ]]; then
    echo -e "Diretorio$bverde ja Existe!$bbranco"$cfim
else
    echo -e "Diretorio$bvermelho Não Existe!$bbranco Criando.: $bverde$destino"$cfim
    mkdir -p $destino
fi
#
cd $origem
#
IFS=$(echo -en "\n\b")
#
sleep 2
#
clear
#
for f in *.mp2 *.mp3 *.aac *.ac3 *.m4a *.ogg *.wav; do
#
if [[ -f "$f" ]]; then
    out=$destino${f%.*}.$ext
#
    tmb=70
    msg1="Convertendo o Arquivo --> $bbranco$f"
    tmh1=$((${#msg1} - 6)) # seria -8 caracteres a cor mas temos + 2 ## assim -6
    if [[ $tmh1 -gt $tmb  ]]; then
       tmb=$(($tmh1 + 2))
    fi
    msi1_spaces=$(printf "%*s" $((($tmb - $tmh1)/2)) "")
    msf1_spaces=$(printf "%*s" $(($tmb - ($tmh1 + ($tmb - $tmh1)/2)))"")
#
    msg2="Para --> $bbranco$out"
    tmh2=$((${#msg2} - 6))
    msi2_spaces=$(printf "%*s" $((($tmb - $tmh2)/2)) "")
    msf2_spaces=$(printf "%*s" $(($tmb - ($tmh2 + ($tmb - $tmh2)/2)))"")
#
    repetec=$(printf '%.0s#' $(seq $tmb))
#
    echo -e $bverde"${repetec}"$cfim
    echo -e $bverde"#$msi1_spaces$bamarelo$msg1$msf1_spaces$bverde#$cfim"
    echo -e $bverde"#$msi2_spaces$bamarelo$msg2$msf2_spaces$bverde#$cfim"
    echo -e $bverde"${repetec}"$cfim
    #
    echo
    sleep 1
    #
#   madplay -b 16 -R 44100 -S -o raw:- $f | lame --preset cbr 128 -r -s 44.1 --bitwidth 16 - -o $out
#   lame $f --preset cbr 128 -r -s 44.1 --bitwidth 16 -o $out
#   ffmpeg -loglevel info -i $f -af "volume=0dB" -c:a libmp3lame -ac 2 -b:a 128k -ar 44100 $out
    #
fi
#
done
