diff --git a/src/ID3v1.php b/src/ID3v1.php new file mode 100644 index 0000000..0cea261 --- /dev/null +++ b/src/ID3v1.php @@ -0,0 +1,181 @@ + + * @copyright 2008 BEHR Software Systems + * @license http://www.opensource.org/licenses/bsd-license.php New BSD License + * @version $Rev$ + */ +class ID3v1 +{ + /** @var string The title */ + private $_title; + + /** @var string The artist */ + private $_artist; + + /** @var string The album */ + private $_album; + + /** @var string The year */ + private $_year; + + /** @var string The comment */ + private $_comment; + + /** @var integer The track number */ + private $_track; + + /** @var integer The genre index */ + private $_genre = 128; + + /** @var Array The genre list */ + public static $genres = array + ("Blues", "Classic Rock", "Country", "Dance", "Disco", "Funk", "Grunge", + "Hip-Hop", "Jazz", "Metal", "New Age", "Oldies", "Other", "Pop", "R&B", + "Rap", "Reggae", "Rock", "Techno", "Industrial", "Alternative", "Ska", + "Death Metal", "Pranks", "Soundtrack", "Euro-Techno", "Ambient", + "Trip-Hop", "Vocal", "Jazz+Funk", "Fusion", "Trance", "Classical", + "Instrumental", "Acid", "House", "Game", "Sound Clip", "Gospel", "Noise", + "AlternRock", "Bass", "Soul", "Punk", "Space", "Meditative", + "Instrumental Pop", "Instrumental Rock", "Ethnic", "Gothic", "Darkwave", + "Techno-Industrial", "Electronic", "Pop-Folk", "Eurodance", "Dream", + "Southern Rock", "Comedy", "Cult", "Gangsta", "Top ", "Christian Rap", + "Pop/Funk", "Jungle", "Native American", "Cabaret", "New Wave", + "Psychadelic", "Rave", "Showtunes", "Trailer", "Lo-Fi", "Tribal", + "Acid Punk", "Acid Jazz", "Polka", "Retro", "Musical", "Rock & Roll", + "Hard Rock", "Folk", "Folk-Rock", "National Folk", "Swing", "Fast Fusion", + "Bebob", "Latin", "Revival", "Celtic", "Bluegrass", "Avantgarde", + "Gothic Rock", "Progressive Rock", "Psychedelic Rock", "Symphonic Rock", + "Slow Rock", "Big Band", "Chorus", "Easy Listening", "Acoustic", "Humour", + "Speech", "Chanson", "Opera", "Chamber Music", "Sonata", "Symphony", + "Booty Bass", "Primus", "Porn Groove", "Satire", "Slow Jam", "Club", + "Tango", "Samba", "Folklore", "Ballad", "Power Ballad", "Rhythmic Soul", + "Freestyle", "Duet", "Punk Rock", "Drum Solo", "A capella", "Euro-House", + "Dance Hall", "Unknown"); + + /** @var Reader The Reader object */ + private $_reader; + + /** + * The default constructor. Initiates the reader for the given file. + */ + public function __construct($filename) + { + $this->_reader = new Reader($filename); + $this->_reader->setOffset(-128); + if ($this->_reader->getString8(3) != "TAG") + throw new ID3_Exception("File does not contain ID3v1 tag: " . $filename); + + $this->_title = rtrim($this->_reader->getString8(30), " \0"); + $this->_artist = rtrim($this->_reader->getString8(30), " \0"); + $this->_album = rtrim($this->_reader->getString8(30), " \0"); + $this->_year = $this->_reader->getString8(4); + $this->_comment = rtrim($this->_reader->getString8(28), " \0"); + + /* ID3v1.1 support for tracks */ + $v11_null = $this->_reader->getInt8(); + $v11_track = $this->_reader->getInt8(); + if (ord($v11_null) == 0 && ord($v11_track) != 0) + $this->_track = ord($v11_track); + else + $this->_comment = rtrim($this->_comment . $v11_null . $v11_track, " \0"); + + $this->_genre = ord($this->_reader->getInt8()); + } + + /** + * Returns the title field. + * + * @return string Returns the title field. + */ + public function getTitle() { return $this->_title; } + + /** + * Returns the artist field. + * + * @return string Returns the artist field. + */ + public function getArtist() { return $this->_artist; } + + /** + * Returns the album field. + * + * @return string Returns the album field. + */ + public function getAlbum() { return $this->_album; } + + /** + * Returns the year field. + * + * @return string Returns the year field. + */ + public function getYear() { return $this->_year; } + + /** + * Returns the comment field. + * + * @return string Returns the comment field. + */ + public function getComment() { return $this->_comment; } + + /** + * Returns the track field. + * + * @note ID3v1.1 feature only + * @return integer Returns the track field. + */ + public function getTrack() { return $this->_track; } + + /** + * Returns the genre. + * + * @return string Returns the genre. + */ + public function getGenre() { + if (isset(self::$genres[$this->_genre])) + return self::$genres[$this->_genre]; + else + return self::$genres[128]; // unknown + } +}