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.
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