Beefy Boxes and Bandwidth Generously Provided by pair Networks
There's more than one way to do things
 
PerlMonks  

How do I get a CD's label?

by Viking (Beadle)
on Jul 05, 2000 at 10:21 UTC ( [id://21089]=perlquestion: print w/replies, xml ) Need Help??

Viking has asked for the wisdom of the Perl Monks concerning the following question:

I want to create a database for my mp3 collection that is on CD's. To make this useful I need to get the CD label. All of these CD's are Joliet. How can I do this? Thank you.

Replies are listed 'Best First'.
RE: How do I get a CD's label?
by gryng (Hermit) on Jul 05, 2000 at 16:27 UTC
    Viking,
    I suppose what you are asking is, how do I get the Artist and Album name from a CD? The short answer is that it's not contained on the CD, and what you have to do is ask a database for that information (called a CDDB database), using a value derived from the CD's tracks and lengths of tracks as the ID to that database (which can return the track names as well).

    There is a CDDB module available at CPAN, and there are many online CDDB databases you can access (such as cddb.cddb.com and freedb.freedb.com).

    Ciao (got to go to work, or I'd answer in more detail),
    Gryn
      I see now that Viking is asking for something different. However I've been grokking CPAN, but I can't find any module that provides that information. You'll probably have to use some other 3rd party utility to grep the information. (such as the cdrecord -V option you mentioned). I'm not at a Linux box, so I can't look very easily at what tools are available there.

      Good luck!
      Gryn
Re: How do I get a CD's label?
by Miker (Scribe) on Jul 05, 2000 at 22:28 UTC
    I hacked this out of CD::Info, you can find it at http://www.kudla.org/raindog/perl/
    open CD, "</dev/cdrom"; sysseek(CD, 32808, 0); read CD, $data, 32; print "cd label is $data\n";
    it only works on data cds though, but as you said this is for an mp3 collection that should be ok, right? :) Miker
      Thanks heaps Miker That worked perfectly, and also the guy who wrote that module had also written a CD catalog similar to what I am doing. So now I can use some of that code too. Or extend his program or something :) This is just too cool.
Re: How do I get a CD's label?
by j0hn (Initiate) on Jul 05, 2000 at 13:32 UTC
    I did something like this a while ago but I cheated myself around it. I had allready written the label of the CD with a pen on the disk so I just wrote a script that accepted the CD-label as an argument.

    very simple...like..

    "index.pl 34"

    and boom.. a few seconds later all the songs from that CD were in the database with "34" as their CD-label.

Re: How do I get a CD's label?
by paulbort (Hermit) on Jul 05, 2000 at 18:07 UTC
    If the Joliet format does this the same way that a DOS partition does it, then there's an entry in the root directory with the "V"olume Label flag set. It sounds like you need either a direct interface (below the filesystem level) to the CD-ROM, or a raw read of the root directory of the CD-ROM. I would suggest opening /dev/cdrom for read and dumping the result to screen. Hopefully this will get you things like the table of contents and maybe the root directory. Try it on lots of different CDs to make sure you have a handle on the data format. Play and Learn.
      cat the cd device through strings, grep for your label, note the offset. Continue this process until you're reasonably sure where to find it. Then write code to open the device, seek to that position, read the value, close the cd and mount it. Write a module, post it here, collect riches and fame.
Re: How do I get a CD's label?
by toadi (Chaplain) on Jul 05, 2000 at 12:33 UTC
    Wellll,

    Start programming *eh* maybe in perl ?? Oh no(mistake) try to analyze the problem first and think then of starting to code.

    When you got a specific problem post it here and we wil help you.

    This is the kind of question That's not specific enough to answer. Please post problems and not howto's. Tackle the problem yourself first and when you stumble on a problem post or post to see if someone has a better way to do it.

    --
    My opinions may have changed,
    but not the fact that I am right

      Sorry I did not make my self very clear. I can do all of it except get the the CD label from the CD. I don't even know if linux can recognize these anyway. The CD label I am referring to is what results from the -V option in cdrecord. Does that make sense. Recursively going thru the directorys on the CD and reading id3 tags from the files is not a problem :)
        Without knowing much about CD-ROM file systems (except that Joliet is the M$ 'extended' standard, as far as I know -- and is different from the ISO one), if you say that cdrecord -V gives you what you want, why don't you do:

        $cd_label = `cdrecord -V`;
        Obviously, this isn't very portable, and I try to steer clear of system calls unless they are absolutely essential, but if it's just a simple script for your own use, you may as well.....

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://21089]
Approved by root
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others meditating upon the Monastery: (5)
As of 2024-04-23 15:25 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found