[Date Prev][Date Next][Thread Prev][Thread Next] [Search] [Date Index] [Thread Index]

Re: [MacPerl] /dev/cdrom



At 21.53 -0800 2000.03.21, Wu Kung Sun wrote:
>Hi, I'm brand new to macperl and completely foreign to MacOS as a
>programming platform.  I'd like to run on a Mac a program which makes cd
>covers by reading the cdrom drive and the querying FreeDB or CDDB (
>http://www.liacs.nl/~jvhemert/disc-cover/ ).  It uses the following:
>my ($config_tmp_dir) = '/tmp';
>my ($config_device) = "/dev/cdrom";
>>From what I understand about mac paths, I can make the first something like
>'HardDrive:Desktop' but how about the second?
>I appreciate any with this admittedly rudimentary question...

No, don't worry, it is not rudimentary.  Actually, maybe that should make
you worry.  In any event, in order to read the CD-ROM drive, you need to
consult a platform-specific API, something that is not built-in to Perl.  I
am not sure what you are using on Unix, but on the Mac you need to go
through the device manager and everything.

Luckily for you (:-), I have AudioCD::Mac on CPAN which is for controlling
Audio CDs (play, pause, volume, etc.), and also has a method for returning
the CDDB magic number.  With the CDDB module (also on CPAN) you can do the
whole thing from Perl.

#!perl -w
use CDDB;
use AudioCD::Mac;

my $cddb = new CDDB;
my $cd = new AudioCD::Mac;
my @cddb_info = $cddb->calculate_id( $cd->cddb_toc );
my @discs = $cddb->get_discs(@cddb_info[0, 3, 4]);
for (@discs) {
    print "$_->[2]\n";
    my $info = $cddb->get_disc_details(@{$_}[0, 1]);

    my $i;
    for (@{${$info}{ttitles}}) {
        printf "%4d.  %s\n", ++$i, $_;
    }
}
__END__

Returns:

# trying us.cddb.com:8880...
Foo Fighters / There is Nothing Left to Lose
   1.  Stacked Actors
   2.  Breakout
   3.  Learn to Fly
   4.  Gimme Stitches
   5.  Generator
   6.  Aurora
   7.  Live-In Skin
   8.  Next Year
   9.  Headwires
  10.  Ain't it the Life
  11.  M.I.A.


-- 
Chris Nandor       |     pudge@pobox.com      |     http://pudge.net/
Andover.Net        | chris.nandor@andover.net | http://slashcode.com/
                                -=-
  I put contact lenses in my dog's eyes.  They had little pictures of
  cats on them.  Then I took one out and he ran around in circles.
                --Steven Wright

# ===== Want to unsubscribe from this list?
# ===== Send mail with body "unsubscribe" to macperl-request@macperl.org