
![]() |
thedarkness
Found it Perk.
<?
php// Class to read id3v2 tags class id3v2 { var $m_fd, $m_artists, $m_name, $m_track, $m_tag, $m_bad_format = false; // Constructor function id3v2( $mp3_file ) { $fd = fopen( $mp3_file, 'r' ); // Open MP3 file $header = fread( $fd, 10 ); // Read 10 byte header if( !stristr( $header, "ID3" ) ) { $this->m_bad_format = true; // Not MP3 or not V2 or corrupted header return; } $this->m_tag["version"] = (int)bin2hex( $header[3] ); // Fourth byte gives major version number $this->m_tag["revision"] = (int)bin2hex( $header[4] ); // Fifth byte gives revision number $this->m_tag["flag"] = (int)bin2hex( $header[5] ); // Sixth byte holds ID3v2 flag (if present) // The last four bytes represent the size of the tag in bytes, only the 7 least significant bits count // and the combination of the 28 bits is a binary representation of the size. $this->m_tag["size"] = $this->size( $header[6].$header[7].$header[8].$header[9] ); // Read in the entire tag $this->m_tag["tag_body"] = fread( $fd, $this->get_tag_size() ); fclose( $fd ); } // Do this better **************************************** function error() { return $this->m_bad_format; } // Calculates size in decimal bytes from 28 bit binary string function size( $four_bytes ) { // The following is an ugly kludge but.... return bindec( sprintf( "%07b%07b%07b%07b", hexdec( bin2hex( $four_bytes[0] ) ), hexdec( bin2hex( $four_bytes[1] ) ), hexdec( bin2hex( $four_bytes[2] ) ), hexdec( bin2hex( $four_bytes[3] ) ) ) ); } // Returns major version number function get_version() { return $this->m_tag["version"]; } // Returns revision (minor version?) number function get_revision() { return $this->m_tag["revision"]; } // Returns size of ID3 tag - 10 byte header function get_tag_size() { return $this->m_tag["size"]; } function get_frame( $frame_id ) { $holds_frame = stristr( $this->m_tag["tag_body"], $frame_id ); if( !$holds_frame ) return false; $frame_header = substr( $holds_frame, 0, 10 ); // Read the frame skipping the encoding byte (I don't support unicode.... anybody?) $frame = substr( $holds_frame, 11, $this->size( $frame_header[4].$frame_header[5].$frame_header[6]. $frame_header[7] )-1 ); return $frame; } function get_artist() { $artist = $this->get_frame( "TPE1" ); return $artist; } function get_album() { $album = $this->get_frame( "TALB" ); return $album; } function get_track() { $track = $this->get_frame( "TRCK" ); return $track; } function get_title() { $title = $this->get_frame( "TIT2" ); return $title; } function get_bpm() { $beats_per_minute = $this->get_frame( "TBPM" ); return $beats_per_minute; } } // End id3v2 declaration ?> perkiset
That's pretty cool TD ... I've not seen this done before with
PHP- it's a great example as well as functional.Thanks dude! /p |

Thread Categories

![]() |
![]() |
Best of The Cache Home |
![]() |
![]() |
Search The Cache |
- Ajax
- Apache & mod_rewrite
- BlackHat SEO & Web Stuff
- C/++/#, Pascal etc.
- Database Stuff
- General & Non-Technical Discussion
- General programming, learning to code
- Javascript Discussions & Code
- Linux Related
- Mac, iPhone & OS-X Stuff
- Miscellaneous
- MS Windows Related
- PERL & Python Related
- PHP: Questions & Discussion
- PHP: Techniques, Classes & Examples
- Regular Expressions
- Uncategorized Threads