Microwave Biscuit

Converting flac files to ogg – 2

Posted in Linux, Music, ubuntu by microwavebiscuit on February 23, 2007

In the previous post I described “why” I convert legally obtained music to a lossy format. Here’s a “how-to” post. First and foremost, you need the “etree scripts” package. I have it listed in synaptic under multimedia but I’m not positive which repository it is from. If you don’t have it listed, here’s a link to the sourceforge site: http://etree-scripts.sourceforge.net/. This is a set of Perl scripts that makes living with flac and shn files way easy. There are a few dependencies that you need to get as well.

First: Shorten – This is necessary to deal with .shn files. You can get it here. You will need to build it from the sources.
Second: Lame – Used to encode to mp3. It may be in your repos or you can get it here
Third: Flac -Free Lossless Audio Codec – Also in your repos, if not go here.
Fourth: Ogg Vorbis – Again, in the repos or here.

You should also get a couple extra Perl Modules that aren’t required but make encoding easier.

Date::Parse – open a terminal and type cpan. Answer any questions that cpan has, then type: install Date::Parse. This should build and install Date::Parse which makes the parsing of date/time info easier for the scripts.

Audio::Wav – Used to deal with WAV files. Get it the same way as Date::Parse. You may already have it.

Now, all dependencies satisfied I’ve written the following script to do some magic:

# Purpose: Convert Downloaded Music
# Script written by Microwave Biscuit
# Script Name: converts
before="$(date +%s)"
for name in $(pwd | sed 's/ /____/g')
oldname="$(echo $name | sed 's/____/ /g')"
newname="$(echo $name | sed 's/____/_/g')"
if [ "$oldname" != "$newname" ] ; then
echo "renaming \"$oldname\" to $newname"
cp -r "$oldname" "$newname"
cd $newname
if [ $result -ne 0 ]; then
echo "Something is wrong with the MD5 Sums";
exit 1;
shn2mp3 `pwd`
after="$(date +%s)"
elapsed_seconds="$(expr $after - $before)"
elapsed_minutes="$(expr $elapsed_seconds / 60)"
echo "Conversion Time: " $elapsed_minutes " minutes for: " $newname | mailx -s "Conversion Finished" me@mypc

Save this script as converts and make it executable (chmod +x).

What this script does is:

1. Gets a starting time so that we can figure out how long the process took.
2. It figures out if there are any blank spaces in the name of the directory that contains the flac/shn files. The Etree script shn2mp3 doesn’t like folders with spaces.
3. If there are spaces, it creates a new directory that replaces the spaces with underscore characters and copies all of the files into it.
4. Runs the md5check script. This ensures that all of the files are complete and match their md5 signatures.
5. If it fails the check, it will exit the script and report the error to you.
6. Next, it runs the shn2mp3 Etree script which will encode all of the files to mp3 or ogg (your choice), parse the info file if it exists and update all of the tags on the newly created files.
7. Figures out how long the process took and emails me that it is complete and lets me know how long it took.

This process works for 99% of the files that I get from etree. There are a few files that don’t follow the etree info file conventions which means that they don’t get their tag data done correctly. I also occasionally get md5 check errors. This is almost always due to the person who created the md5 file having extra files in the directory, i.e. the original WAV files or something else unnecessary. If it fails the md5 check and reports that a wav file is missing or thumbs.db is missing, I just manually run the shn2mp3 script on the directory. If there are other errors in the md5 check then you likely have a problem with your download or the source flac/shn files.

Another very useful script in the etree scripts package is burn-shns. This script will take a directory of flac/shn files and create a CD from it. If your downloaded files have multiple disks in one directory (usually identified with filenames like d1t1, d2t1, etc) create a new directory for each disk and copy all of the d1 files to the new folder and then run burn-shns in each folder.

Some may have issues with using the mp3 format – feel free to use ogg. Also, I believe that shorten is a proprietary format but it’s free to use for non-commercial usage. Please respect copyrighted music and especially trade friendly artists. If there is an artist that you like who is trade friendly you should definitely buy their commercial releases so that you support their work.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: