Deprecated: Non-static method DB::connect() should not be called statically, assuming $this from incompatible context in /home/fhazel/include/SNF/users.inc on line 1120

Deprecated: Non-static method DB::parseDSN() should not be called statically, assuming $this from incompatible context in /home/fhazel/pear/php/DB.php on line 520

Deprecated: Non-static method DB::isError() should not be called statically, assuming $this from incompatible context in /home/fhazel/pear/php/DB.php on line 551

Deprecated: Non-static method DB::isError() should not be called statically, assuming $this from incompatible context in /home/fhazel/pear/php/DB.php on line 557

Deprecated: Non-static method DB::isError() should not be called statically, assuming $this from incompatible context in /home/fhazel/include/SNF/users.inc on line 1122

Deprecated: Non-static method DB::isError() should not be called statically, assuming $this from incompatible context in /home/fhazel/pear/php/DB/common.php on line 1347

Deprecated: Non-static method DB::isError() should not be called statically, assuming $this from incompatible context in /home/fhazel/pear/php/DB/common.php on line 1009

Deprecated: Non-static method DB::isManip() should not be called statically, assuming $this from incompatible context in /home/fhazel/pear/php/DB/common.php on line 2195

Deprecated: Non-static method DB::isError() should not be called statically, assuming $this from incompatible context in /home/fhazel/pear/php/DB/common.php on line 1014

Deprecated: Non-static method DB::isError() should not be called statically, assuming $this from incompatible context in /home/fhazel/pear/php/DB/common.php on line 1356

Deprecated: Non-static method DB::isError() should not be called statically, assuming $this from incompatible context in /home/fhazel/pear/php/DB.php on line 1387

Deprecated: Non-static method DB::isError() should not be called statically, assuming $this from incompatible context in /home/fhazel/include/SNF/users.inc on line 1130

Deprecated: Non-static method DB::connect() should not be called statically, assuming $this from incompatible context in /home/fhazel/include/icky/wiki.inc on line 38

Deprecated: Non-static method DB::parseDSN() should not be called statically, assuming $this from incompatible context in /home/fhazel/pear/php/DB.php on line 520

Deprecated: Non-static method DB::isError() should not be called statically, assuming $this from incompatible context in /home/fhazel/pear/php/DB.php on line 551

Deprecated: Non-static method DB::isError() should not be called statically, assuming $this from incompatible context in /home/fhazel/pear/php/DB.php on line 557

Deprecated: Non-static method DB::isError() should not be called statically, assuming $this from incompatible context in /home/fhazel/include/icky/wiki.inc on line 40

Deprecated: Non-static method DB::isError() should not be called statically, assuming $this from incompatible context in /home/fhazel/pear/php/DB/common.php on line 1347

Deprecated: Non-static method DB::isError() should not be called statically, assuming $this from incompatible context in /home/fhazel/pear/php/DB/common.php on line 1009

Deprecated: Non-static method DB::isManip() should not be called statically, assuming $this from incompatible context in /home/fhazel/pear/php/DB/common.php on line 2195

Deprecated: Non-static method DB::isError() should not be called statically, assuming $this from incompatible context in /home/fhazel/pear/php/DB/common.php on line 1014

Deprecated: Non-static method DB::isError() should not be called statically, assuming $this from incompatible context in /home/fhazel/pear/php/DB/common.php on line 1356

Deprecated: Non-static method DB::isError() should not be called statically, assuming $this from incompatible context in /home/fhazel/pear/php/DB.php on line 1387

Deprecated: Non-static method DB::isError() should not be called statically, assuming $this from incompatible context in /home/fhazel/include/icky/wiki.inc on line 48

Deprecated: Non-static method DB::connect() should not be called statically, assuming $this from incompatible context in /home/fhazel/include/icky/article.inc on line 227

Deprecated: Non-static method DB::parseDSN() should not be called statically, assuming $this from incompatible context in /home/fhazel/pear/php/DB.php on line 520

Deprecated: Non-static method DB::isError() should not be called statically, assuming $this from incompatible context in /home/fhazel/pear/php/DB.php on line 551

Deprecated: Non-static method DB::isError() should not be called statically, assuming $this from incompatible context in /home/fhazel/pear/php/DB.php on line 557

Deprecated: Non-static method DB::isError() should not be called statically, assuming $this from incompatible context in /home/fhazel/include/icky/article.inc on line 229

Deprecated: Non-static method DB::isError() should not be called statically, assuming $this from incompatible context in /home/fhazel/pear/php/DB/common.php on line 1347

Deprecated: Non-static method DB::isError() should not be called statically, assuming $this from incompatible context in /home/fhazel/pear/php/DB/common.php on line 1009

Deprecated: Non-static method DB::isManip() should not be called statically, assuming $this from incompatible context in /home/fhazel/pear/php/DB/common.php on line 2195

Deprecated: Non-static method DB::isError() should not be called statically, assuming $this from incompatible context in /home/fhazel/pear/php/DB/common.php on line 1014

Deprecated: Non-static method DB::isError() should not be called statically, assuming $this from incompatible context in /home/fhazel/pear/php/DB/common.php on line 1356

Deprecated: Non-static method DB::isError() should not be called statically, assuming $this from incompatible context in /home/fhazel/pear/php/DB.php on line 1387

Deprecated: Non-static method DB::isError() should not be called statically, assuming $this from incompatible context in /home/fhazel/include/icky/article.inc on line 238

Deprecated: Non-static method DB::connect() should not be called statically, assuming $this from incompatible context in /home/fhazel/include/icky/article.inc on line 265

Deprecated: Non-static method DB::parseDSN() should not be called statically, assuming $this from incompatible context in /home/fhazel/pear/php/DB.php on line 520

Deprecated: Non-static method DB::isError() should not be called statically, assuming $this from incompatible context in /home/fhazel/pear/php/DB.php on line 551

Deprecated: Non-static method DB::isError() should not be called statically, assuming $this from incompatible context in /home/fhazel/pear/php/DB.php on line 557

Deprecated: Non-static method DB::isError() should not be called statically, assuming $this from incompatible context in /home/fhazel/include/icky/article.inc on line 267

Deprecated: Non-static method DB::isError() should not be called statically, assuming $this from incompatible context in /home/fhazel/pear/php/DB/common.php on line 1347

Deprecated: Non-static method DB::isError() should not be called statically, assuming $this from incompatible context in /home/fhazel/pear/php/DB/common.php on line 1009

Deprecated: Non-static method DB::isManip() should not be called statically, assuming $this from incompatible context in /home/fhazel/pear/php/DB/common.php on line 2195

Deprecated: Non-static method DB::isError() should not be called statically, assuming $this from incompatible context in /home/fhazel/pear/php/DB/common.php on line 1014

Deprecated: Non-static method DB::isError() should not be called statically, assuming $this from incompatible context in /home/fhazel/pear/php/DB/common.php on line 1356

Deprecated: Non-static method DB::isError() should not be called statically, assuming $this from incompatible context in /home/fhazel/pear/php/DB.php on line 1387

Deprecated: Non-static method DB::isError() should not be called statically, assuming $this from incompatible context in /home/fhazel/include/icky/article.inc on line 276

Deprecated: Non-static method DB::connect() should not be called statically, assuming $this from incompatible context in /home/fhazel/include/icky/article.inc on line 451

Deprecated: Non-static method DB::parseDSN() should not be called statically, assuming $this from incompatible context in /home/fhazel/pear/php/DB.php on line 520

Deprecated: Non-static method DB::isError() should not be called statically, assuming $this from incompatible context in /home/fhazel/pear/php/DB.php on line 551

Deprecated: Non-static method DB::isError() should not be called statically, assuming $this from incompatible context in /home/fhazel/pear/php/DB.php on line 557

Deprecated: Non-static method DB::isError() should not be called statically, assuming $this from incompatible context in /home/fhazel/include/icky/article.inc on line 453

Deprecated: Non-static method DB::isError() should not be called statically, assuming $this from incompatible context in /home/fhazel/pear/php/DB/common.php on line 1283

Deprecated: Non-static method DB::isError() should not be called statically, assuming $this from incompatible context in /home/fhazel/pear/php/DB/common.php on line 1009

Deprecated: Non-static method DB::isManip() should not be called statically, assuming $this from incompatible context in /home/fhazel/pear/php/DB/common.php on line 2195

Deprecated: Non-static method DB::isError() should not be called statically, assuming $this from incompatible context in /home/fhazel/pear/php/DB/common.php on line 1014

Deprecated: Non-static method DB::isError() should not be called statically, assuming $this from incompatible context in /home/fhazel/pear/php/DB/common.php on line 1292

Deprecated: Non-static method DB::isError() should not be called statically, assuming $this from incompatible context in /home/fhazel/pear/php/DB.php on line 1387

Deprecated: Non-static method DB::isError() should not be called statically, assuming $this from incompatible context in /home/fhazel/include/icky/article.inc on line 461
SNF wiki: GetID3

GetID3


Deprecated: preg_replace(): The /e modifier is deprecated, use preg_replace_callback instead in /home/fhazel/lib/php/markdown.101c.php on line 702

Deprecated: preg_replace(): The /e modifier is deprecated, use preg_replace_callback instead in /home/fhazel/lib/php/markdown.101c.php on line 702

Deprecated: preg_replace(): The /e modifier is deprecated, use preg_replace_callback instead in /home/fhazel/lib/php/markdown.101c.php on line 720

Deprecated: preg_replace(): The /e modifier is deprecated, use preg_replace_callback instead in /home/fhazel/lib/php/markdown.101c.php on line 1143

Deprecated: preg_replace(): The /e modifier is deprecated, use preg_replace_callback instead in /home/fhazel/lib/php/markdown.101c.php on line 1143

Deprecated: preg_replace(): The /e modifier is deprecated, use preg_replace_callback instead in /home/fhazel/lib/php/markdown.101c.php on line 1143

Deprecated: preg_replace(): The /e modifier is deprecated, use preg_replace_callback instead in /home/fhazel/lib/php/markdown.101c.php on line 1143

Deprecated: preg_replace(): The /e modifier is deprecated, use preg_replace_callback instead in /home/fhazel/lib/php/markdown.101c.php on line 1143

Deprecated: preg_replace(): The /e modifier is deprecated, use preg_replace_callback instead in /home/fhazel/lib/php/markdown.101c.php on line 1143

Deprecated: preg_replace(): The /e modifier is deprecated, use preg_replace_callback instead in /home/fhazel/lib/php/markdown.101c.php on line 1143

Deprecated: preg_replace(): The /e modifier is deprecated, use preg_replace_callback instead in /home/fhazel/lib/php/markdown.101c.php on line 1143

Deprecated: preg_replace(): The /e modifier is deprecated, use preg_replace_callback instead in /home/fhazel/lib/php/markdown.101c.php on line 1143

Deprecated: preg_replace(): The /e modifier is deprecated, use preg_replace_callback instead in /home/fhazel/lib/php/markdown.101c.php on line 1143

Deprecated: preg_replace(): The /e modifier is deprecated, use preg_replace_callback instead in /home/fhazel/lib/php/markdown.101c.php on line 1143

Deprecated: preg_replace(): The /e modifier is deprecated, use preg_replace_callback instead in /home/fhazel/lib/php/markdown.101c.php on line 1143

Deprecated: preg_replace(): The /e modifier is deprecated, use preg_replace_callback instead in /home/fhazel/lib/php/markdown.101c.php on line 1143

Deprecated: Non-static method PEAR::getStaticProperty() should not be called statically, assuming $this from incompatible context in /home/fhazel/pear/php/HTML/BBCodeParser.php on line 180

Deprecated: Non-static method PEAR::getStaticProperty() should not be called statically, assuming $this from incompatible context in /home/fhazel/pear/php/HTML/BBCodeParser.php on line 180

Deprecated: Non-static method PEAR::getStaticProperty() should not be called statically, assuming $this from incompatible context in /home/fhazel/pear/php/HTML/BBCodeParser.php on line 180

Deprecated: Non-static method PEAR::getStaticProperty() should not be called statically, assuming $this from incompatible context in /home/fhazel/pear/php/HTML/BBCodeParser.php on line 180

Deprecated: Non-static method PEAR::getStaticProperty() should not be called statically, assuming $this from incompatible context in /home/fhazel/pear/php/HTML/BBCodeParser.php on line 180

Deprecated: Non-static method PEAR::getStaticProperty() should not be called statically, assuming $this from incompatible context in /home/fhazel/pear/php/HTML/BBCodeParser.php on line 180

Deprecated: Non-static method PEAR::getStaticProperty() should not be called statically, assuming $this from incompatible context in /home/fhazel/pear/php/HTML/BBCodeParser.php on line 180

Deprecated: Non-static method PEAR::getStaticProperty() should not be called statically, assuming $this from incompatible context in /home/fhazel/pear/php/HTML/BBCodeParser/Filter/Links.php on line 69

Deprecated: Non-static method PEAR::getStaticProperty() should not be called statically, assuming $this from incompatible context in /home/fhazel/pear/php/HTML/BBCodeParser/Filter/Lists.php on line 80

Deprecated: Non-static method PEAR::getStaticProperty() should not be called statically, assuming $this from incompatible context in /home/fhazel/pear/php/HTML/BBCodeParser/Filter/Images.php on line 72

Deprecated: Non-static method PEAR::getStaticProperty() should not be called statically, assuming $this from incompatible context in /home/fhazel/pear/php/HTML/BBCodeParser/Filter/Email.php on line 69

GetID3 is a PHP library for parsing and manipulating ID3 tags in MP3 audio files. It is notable for its dearth of friendly documentation, though many useful tidbits can be found in the GetID3 forums.

Reading and writing artist, title, genre, etc. tags

A listing of the data structure returned by GetID3 is found in the structure.txt document.

Reading a track’s ID3 tags should be a matter of doing something like the following:

$getID3 = new getID3;
$getID3->analyze($filename);

And then looking at the contents of $getID3->info (detailed in the link above).

Writing ID3 tags seems a bit hazardous, because, evidently, any write operation rewrites all existing ID3 tags. So if you want to preserve any existing tags, you must read them first and then be careful to write them back along with any changes you’re trying to make.

Further documentation on this to be added later if I ever end up needing it.

Reading album cover art

Album cover art is stored in a tag field called APIC, or possibly PIC (not sure about this). The image type is stored in a subfield as a MIME type (e.g., “image/jpeg,” “image/png,” etc.).

Basic code for extracting cover art looks like this:

$getID3 = new getID3;
#$getID3->option_tag_id3v2 = true; # Don't know what this does yet
$getID3->analyze($filename);
if (isset($getID3->info['id3v2']['APIC'][0]['data'])) {
    $cover = $getID3->info['id3v2']['APIC'][0]['data'];
} elseif (isset($getID3->info['id3v2']['PIC'][0]['data'])) {
    $cover = $getID3->info['id3v2']['PIC'][0]['data'];
} else {
    $cover = null;
}
if (isset($getID3->info['id3v2']['APIC'][0]['image_mime'])) {
    $mimetype = $getID3->info['id3v2']['APIC'][0]['image_mime'];
} else {
    $mimetype = 'image/jpeg'; // or null; depends on your needs
}

Note that the variable $getID3->info['id3v2']['APIC'] in the above code sample is an array. The above code assumes that you only care about the first image in the array, but others could be present. iTunes, for example, allows multiple images to be embedded in a track.

The following code can be used to directly output the cover image stored in $cover:

if (!is_null($cover)) {
    // Send file
    header("Content-Type: " . $mimetype);
    if (isset($getID3->info['id3v2']['APIC'][0]['image_bytes'])) {
        header("Content-Length: " . $getID3->info['id3v2']['APIC'][0]['image_bytes']);
    }
    #header("Content-Transfer-Encoding: binary"); # Possibly unnecessary
    echo($cover);
}

For performance reasons, however, you’re usually better off extracting the image beforehand and saving it to a static image file rather than extracting and displaying it dynamically.

[ article last updated 2007-02-22 14:51:39 by cobra libre ]