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

Does there exist any sort of module/code that will attempt to extract info (such as track, album, and artist) from an MP3? Specifically, I'm looking to clean up my iTunes database, and many of my MP3's are without full ID3 information. So, what I want to do is use Audiofile::Info to pull out the ID3 info, and then attempt to "wing it" by extracting that info from the filename if the ID3 info does not exist. Does anyone have any hints?

Replies are listed 'Best First'.
Re: MP3 Info from filename?
by PodMaster (Abbot) on Oct 21, 2003 at 15:53 UTC
    Look at MP3::Tag and especially MP3::Tag::File read_filename() tries to extract information about artist, song, song number and album from the filename..

    MJD says "you can't just make shit up and expect the computer to know what you mean, retardo!"
    I run a Win32 PPM repository for perl 5.6.x and 5.8.x -- I take requests (README).
    ** The third rule of perl club is a statement of fact: pod is sexy.

      Great, this is exactly what I was looking for! Thanks.
Re: MP3 Info from filename?
by jeffa (Bishop) on Oct 21, 2003 at 16:24 UTC
Re: MP3 Info from filename?
by hardburn (Abbot) on Oct 21, 2003 at 15:49 UTC

    Are the filenames of the collection in a consistant format? As in all the files are named something like "%track_num% - %album% - %artist% - %name%.mp3"? If so, you have some hope. If not, you probably don't.

    ----
    I wanted to explore how Perl's closures can be manipulated, and ended up creating an object system by accident.
    -- Schemer

    :(){ :|:&};:

    Note: All code is untested, unless otherwise stated

Re: MP3 Info from filename?
by meetraz (Hermit) on Oct 21, 2003 at 15:48 UTC
    If the files are missing ID3 tags, then there is really no way to get that data from the files themselves. If all the files use a common naming convention, you might be able to parse Artist & Track name from the file name and save that into the ID3 tag -- I assume that's what you're trying to do.

    my ($Artist, $Track) = $Filename =~ /(.*) +- +(.*)\.mp3/i;
      It need not be all doom and gloom if you don't have meaningful file names, but you can identify all the tracks in a particular album. Rocco Caputo suggests in his documentation for CDDB.pm that you can recreate a CD's table of contents from MP3 durations.

      MP3::Info should be able to tell you the track duration with enough accuracy.

      This is all untried. It looks like it might work, though.

      --
      bowling trophy thieves, die!

        I found mp3cddb, a Perl/shell program to do freedb queries based on MP3s. It's a little old — it only supports ID3v1 — but it's GPL, so we can fix it.

        --
        bowling trophy thieves, die!