We are going to look at a little script that I threw together to convert our MP3 files to OGG files that maintains your tag info in the conversion. To use this script you'll need to have sox, mp3info and vorbiscomment installed. I don't guarantee this script against damaging your files, I've only done this as an example, but to the best of my knowledge it works fine. It's certainly small enough that you can look through the code to prove to yourself whether it's harmless or not. Here is a link to the actual file. Now let's look at the code.
#!/bin/bash
DELETE_ORIGINAL=true
# do some parameter checking
if [ -z "$1" ]
then
echo "usage: `basename $0` path_to_mp3_file"
exit 1
fi
ORIGINAL_FILENAME=$1
NEW_FILENAME=${ORIGINAL_FILENAME%.*}.ogg
# convert the file
sox $ORIGINAL_FILENAME $NEW_FILENAME
# convert the id3 info to ogg comments
ARTIST=`mp3info -p "%a" $ORIGINAL_FILENAME`
TITLE=`mp3info -p "%t" $ORIGINAL_FILENAME`
GENRE=`mp3info -p "%g" $ORIGINAL_FILENAME`
vorbiscomment -a -t "ARTIST=$ARTIST" -t "TITLE=$TITLE" -t "GENRE=$GENRE" $NEW_FILENAME
# remove the original file
if $DELETE_ORIGINAL
then
rm $ORIGINAL_FILENAME
fi
![[logo]](logo.png)