diebels
February 4th, 2006, 08:17 PM
Hi.
I usually backup my cd's in flac with sound-juicer. But not many portable players or standalone dvd-players play flac, so the files must be converted to ogg or mp3.
Just doing 'flac -d *.flac; oggenc *.wav' in a directory isn't nice since you loose tags. Also lame don't like globbing, and bash don't like spaces in filenames. So I have searched a bit for a program that can do this while keeping tags. Didn't find any, so made a little script. No gui yet, but it's quite easy to use.
Just run it without parameters to see usage.
#! /bin/sh
# music_convert, converts a couple music formats keeping tags
# Needs vorbis-tools, lame and flac installed
E_BADARGS=63
E_MISSING_PROGRAM=64
if [ ! -e /usr/bin/flac ] || [ ! -e /usr/bin/oggenc ] || [ ! -e /usr/bin/lame ]
then
if [ $LANG == nb_NO.UTF-8 ]
then
echo "Du trenger vorbis-tools, lame og flac installert"
else
echo "You need vorbis-tools, lame and flac installed"
fi
exit $E_MISSING_PROGRAM
fi
print_usage() {
if [ $LANG == nb_NO.UTF-8 ]
then
echo -e "$(basename $0) konverterer flac ogg og mp3 filer, beholder \
taggger\n"
echo "Bruk: $(basename $0) fra til kvalitet"
echo "der 'fra' kan være flac og ogg"
echo "'til' kan være ogg og mp3"
echo "'kvalitet' er standard, extreme eller insane for mp3 utputt"
echo -e "og mellom -1 og 10 for ogg-vorbis\n"
echo "eks: $(basename $0) flac ogg 7, $(basename $0) ogg mp3 extreme"
else
echo -e "$(basename $0) converts flac ogg and mp3 files, keeping tags\n"
echo "Usage: $(basename $0) from to quality"
echo "where 'from' can be flac and ogg"
echo "'to' can be ogg and mp3"
echo "'quality' is standard, extreme or insane for mp3 output"
echo -e "and between -1 and 10 for ogg-vorbis output\n"
echo "ex: $(basename $0) flac ogg 7, $(basename $0) ogg mp3 extreme"
fi
}
if [ -z $3 ]
then
print_usage
exit $E_BADARGS
fi
f=$1
t=$2
q=$3
get_tag() {
if [ $f == flac ]
then
metaflac --show-tag=$1 "$i" | sed "s/$1=//"
elif [ $f == ogg ]
then
ogginfo "$i" | sed -n "s/^.*$1=//p"
fi
}
wav_file() {
echo "$i" | sed "s/\.$f/\.wav/"
}
for i in *.$f
do
if [ $f == flac ]
then
flac -d "$i"
elif [ $f == ogg ]
then
oggdec "$i"
else
print_usage
exit $E_BADARGS
fi
if [ $t == ogg ]
then
oggenc -q $q -t "$(get_tag TITLE)" -a "$(get_tag ARTIST)" \
-l "$(get_tag ALBUM)" -d "$(get_tag DATE)" -N \
"$(get_tag TRACKNUMBER)" -G "$(get_tag GENRE)" "$(wav_file)"
rm "$(wav_file)"
elif [ $t == mp3 ]
then
lame --preset $q --tt "$(get_tag TITLE)" --ta "$(get_tag ARTIST)" \
--tl "$(get_tag ALBUM)" --ty "$(get_tag DATE)" --tn \
"$(get_tag TRACKNUMBER)" --tg "$(get_tag GENRE)" "$(wav_file)" \
"$(echo "$i" | sed "s/\.$f/\.mp3/")"
rm "$(wav_file)"
else
print_usage
exit $E_BADARGS
fi
done
exit 0
I usually backup my cd's in flac with sound-juicer. But not many portable players or standalone dvd-players play flac, so the files must be converted to ogg or mp3.
Just doing 'flac -d *.flac; oggenc *.wav' in a directory isn't nice since you loose tags. Also lame don't like globbing, and bash don't like spaces in filenames. So I have searched a bit for a program that can do this while keeping tags. Didn't find any, so made a little script. No gui yet, but it's quite easy to use.
Just run it without parameters to see usage.
#! /bin/sh
# music_convert, converts a couple music formats keeping tags
# Needs vorbis-tools, lame and flac installed
E_BADARGS=63
E_MISSING_PROGRAM=64
if [ ! -e /usr/bin/flac ] || [ ! -e /usr/bin/oggenc ] || [ ! -e /usr/bin/lame ]
then
if [ $LANG == nb_NO.UTF-8 ]
then
echo "Du trenger vorbis-tools, lame og flac installert"
else
echo "You need vorbis-tools, lame and flac installed"
fi
exit $E_MISSING_PROGRAM
fi
print_usage() {
if [ $LANG == nb_NO.UTF-8 ]
then
echo -e "$(basename $0) konverterer flac ogg og mp3 filer, beholder \
taggger\n"
echo "Bruk: $(basename $0) fra til kvalitet"
echo "der 'fra' kan være flac og ogg"
echo "'til' kan være ogg og mp3"
echo "'kvalitet' er standard, extreme eller insane for mp3 utputt"
echo -e "og mellom -1 og 10 for ogg-vorbis\n"
echo "eks: $(basename $0) flac ogg 7, $(basename $0) ogg mp3 extreme"
else
echo -e "$(basename $0) converts flac ogg and mp3 files, keeping tags\n"
echo "Usage: $(basename $0) from to quality"
echo "where 'from' can be flac and ogg"
echo "'to' can be ogg and mp3"
echo "'quality' is standard, extreme or insane for mp3 output"
echo -e "and between -1 and 10 for ogg-vorbis output\n"
echo "ex: $(basename $0) flac ogg 7, $(basename $0) ogg mp3 extreme"
fi
}
if [ -z $3 ]
then
print_usage
exit $E_BADARGS
fi
f=$1
t=$2
q=$3
get_tag() {
if [ $f == flac ]
then
metaflac --show-tag=$1 "$i" | sed "s/$1=//"
elif [ $f == ogg ]
then
ogginfo "$i" | sed -n "s/^.*$1=//p"
fi
}
wav_file() {
echo "$i" | sed "s/\.$f/\.wav/"
}
for i in *.$f
do
if [ $f == flac ]
then
flac -d "$i"
elif [ $f == ogg ]
then
oggdec "$i"
else
print_usage
exit $E_BADARGS
fi
if [ $t == ogg ]
then
oggenc -q $q -t "$(get_tag TITLE)" -a "$(get_tag ARTIST)" \
-l "$(get_tag ALBUM)" -d "$(get_tag DATE)" -N \
"$(get_tag TRACKNUMBER)" -G "$(get_tag GENRE)" "$(wav_file)"
rm "$(wav_file)"
elif [ $t == mp3 ]
then
lame --preset $q --tt "$(get_tag TITLE)" --ta "$(get_tag ARTIST)" \
--tl "$(get_tag ALBUM)" --ty "$(get_tag DATE)" --tn \
"$(get_tag TRACKNUMBER)" --tg "$(get_tag GENRE)" "$(wav_file)" \
"$(echo "$i" | sed "s/\.$f/\.mp3/")"
rm "$(wav_file)"
else
print_usage
exit $E_BADARGS
fi
done
exit 0