For those interested in either brushing up on their bash scripting
expertise, or learning about bash scripting, read on.

Since there have been several threads talking about bash(1) and
one-liners and what-not, I've decided to join in the fray. I'll
probably try doing several useful scripts every once in a while for
newbies (and interested oldbies) to dissect and discuss. :)

Attached is a simple* shell script to rip CDs and encode them to FLAC.
It depends on having cdparanoia(1), flac(1), and metaflac(1). It does
NOT query CDDB, and it depends on reading a "cue sheet" from stdin.

The script is invoked as (if the executable bit has been set):
$ cd-rip-flac.sh [-t | -n ] < cuesheet

where
     -t     Test that the cuesheet provided is read properly by dumping it
     -n     Encode only, skip ripping (assumes each track is saved as
tracknn.cdda.wav

Sample invocation:

$ /path/to/cd-rip-flac.sh < mycd.cuesheet

The script will then rip using cdparanoia(1) in one pass (batch mode),
then go through each file with flac(1) and metaflac(1)-- to encode at
maximum compression and then add metadata from the cuesheet,
respectively.

The cuesheet looks like this:
----Cut here----
Artist Name
Album Title
5
Track 1
Track 2
Track 3
Track 4
Track 5
----Cut here----

where the third line is the number of tracks on the CD, and the lines
after that the titles of each track starting from track 1.

The script demonstrates the following bash(1) features:
- IFS -- the internal field separator
- Reading into variables
- Single-dimension arrays
- getopts to read optional arguments
- functions
- for loops and arithmetic evaluation in bash
- "heredocs"

There are several places for improvement-- exercises left to the reader:
- The script relies on having the CD metadata provided by an external
file. One could, for example, somehow grab info via CDDB then massage
it to the format the script uses.
- The script does not check whether or not the components it depends
on are installed
- There is no way (yet) to control the arguments to cdparanoia and
flac -- it should be easy to provide options for doing so
- There is no way to 'resume' ripping or encoding (you can, however,
interrupt the script after ripping and before encoding, then tell the
script to only do encoding via the -n option

Comments?

===
* Okay, it's NOT that simple, but people experienced in shell
scripting should be able to get what it does.

--
JM Ibanez --

Book:   If you take sexual advantage of her, you're going to burn in a
        very special level of Hell, a level they reserve for child
        molesters and people who talk at the theater.
        (Firefly, "Our Mrs. Reynolds")
-----
http://www.livejournal.com/~jmibanez/
http://www.mycgiserver.com/~butiki/

Attachment: cd-rip-flac.sh
Description: Bourne shell script

_________________________________________________
Philippine Linux Users' Group (PLUG) Mailing List
[email protected] (#PLUG @ irc.free.net.ph)
Read the Guidelines: http://linux.org.ph/lists
Searchable Archives: http://archives.free.net.ph

Reply via email to