Script That Bad Mamma Jamma

Script That Bad Mamma Jamma

Now come the shell scripts. We want a brief script that will mount a CD, take an inventory of all the MP3s on it, and then start freeamp. When the player exits, we want to unmount and eject the CD, and then hope the partygoers won't be too perturbed by the break in the music. So here it is:

#!/usr/bin/bash
# cdr.bash -- the mounting & playing & unmounting script
mount /cdrom && \
 find /cdrom -iname '*.mp3' > /tmp/songs.m3u && \
 freeamp -ui freeampcmd /tmp/songs.m3u
 rm /tmp/songs.m3u && \
 umount /cdrom && \
 eject /cdrom

That's a mouthful, eh? Now just make sure it's executable, and test it. Since it'll work if you typed it in just as seen here, I'll explain the logic.

·                 It declares what shell it's using. We use bash, because it's nice and consistent and is included in almost all distributions (I haven't seen a Linux without it, in fact).

·                 Mount the CD-ROM, and if that succeeds,

o               do a find command that will find anything ending with .mp3, .Mp3, .MP3, or .mP3 and then dumps all matching filenames into /tmp/songs.m3u. If that succeeds,

§                 Start a new copy of freeamp, using the new playlist as fodder. When that exits,

§                 Unmount the CD. If that's successful,

§                 Eject the CD.

This isn't a terribly advanced shell script ”I'm sure you'd be able to improve it with a little thought. Since it's executable, and in a logical place (you always put your shell scripts in a logical place, right?), we just need to define some aliases. I put my scripts in /home/jeremy/juke_scripts. And then I set up this alias:

alias m='/home/jeremy/juke_scripts/cdr.bash'

Voila! Now, during a party, you need only hit m to start the player. When the CD finishes, or you cancel freeamp by pressing q, the CD will eject. Then put in the fresh CD-R, and type m again ”the CD tray will close, and the music will start as soon as a playlist has been composed .

There you are. You've got yourself a pretty cool MP3 player that's the utmost in simplicity.

Here's the final piece of advice: Don't follow the directions in this chapter. Unless you've got a big spare hard drive and a relatively fast processor (at least a Pentium 90) sitting idle (not to mention a keyboard, a good soundcard, and some time to kill), this is going to cost you a good $200. Run, don't walk, to your nearest electronics retailer and buy yourself a piece of hardware like the Apex DVD player or the Rio Volt. Such a device will play CD-Rs burned with MP3s, and can almost completely substitute for the system we've spent the last few pages building.

 



Multitool Linux. Practical Uses for Open Source Software
Multitool Linux: Practical Uses for Open Source Software
ISBN: 0201734206
EAN: 2147483647
Year: 2002
Pages: 257

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net