Chris Nizzardini, Salt Lake City Utah, Web Developer Specializing in LAMP+Ajax Since 2006

My Blog

Here is my awesome blog. You can find information on programming, linux, documentation, tips for code and database optimization, my thoughts and rants, and whatever else I feel like sharing. Feel free to contribute to the blog by posting comments and asking questions.
Programming

getID3 – read and write mp3 metadata (id3 tags) in php

So as of late I’ve been writing a lamp application. I’ll post some specifics on this webapp later. One of the things I needed it to do was read and write ID3 tags for MP3s. I exhausted google and phpfreaks for answers to this. At first the only thing I could find was some support within an obscure extension called PECL (pronounced pickle). Yah know I’m still a noob and didn’t want to mess with extensions just yet. So I found the getID3 project instead.

The demo pages make this all pretty easy. The only thing thats not documented is writing album and genre information.

require_once('/var/www/getid3/getid3/getid3.php');
// Initialize getID3 engine
$getID3 = new getID3;
$getID3->setOption(array('encoding'=>$TaggingFormat));

require_once('/var/www/getid3/getid3/write.php');
// Initialize getID3 tag-writing module
$tagwriter = new getid3_writetags;
//$tagwriter->filename = '/path/to/file.mp3';
$tagwriter->filename = $mp3file;
$tagwriter->tagformats = array('id3v1', 'id3v2.3');

// set various options (optional)
$tagwriter->overwrite_tags = true;
$tagwriter->tag_encoding = $TaggingFormat;
$tagwriter->remove_other_tags = true;

// populate data array
$TagData['title'][] = $_POST['songtitle'];
$TagData['artist'][] = $_POST['artist'];
$TagData['album'][] = $_POST['album'];
$TagData['genre'][] = $_POST['genre'];

$tagwriter->tag_data = $TagData;

No related posts.

One Response to “getID3 – read and write mp3 metadata (id3 tags) in php”

  1. epcmedia says:

    I came across the same problem. I started with getID3 before I knew about the PECL extension. It is a little cumbersome but provides all kind of information. Personally, it was a little too heavy for my application. (I have to index over 150,000 songs, and it was killing my server).

    More research yielded the id3 PECL extension. I am lightly testing it now and it appears to have the speed I require. Additionally, it is very simple to use and access the data it returns.

    It is easy to install on a UNIX / Linux system. on the command line just run:

    pecl install channel://pecl.php.net/id3-0.2

    the system will download, compile, and install everything automatically. Restart php / your webserver and you are on your way.

    Cheers

    EPCMEDIA

Leave a Reply