123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156 |
- <?php
- /**
- * dolphin. Collection of useful PHP skeletons.
- * Copyright (C) 2009 Johannes 'Banana' Keßler
- *
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the COMMON DEVELOPMENT AND DISTRIBUTION LICENSE
- *
- * You should have received a copy of the
- * COMMON DEVELOPMENT AND DISTRIBUTION LICENSE (CDDL) Version 1.0
- * along with this program. If not, see http://www.sun.com/cddl/cddl.html
- */
- /**
- * read the id3 tags from a mp3 file
- * base on : http://www.script-tutorials.com/id3-tags-reader-with-php/
- */
- class ID3TagsReader {
- // variables
- var $aTV23 = array( // array of possible sys tags (for last version of ID3)
- 'TIT2',
- 'TALB',
- 'TPE1',
- 'TPE2',
- 'TRCK',
- 'TYER',
- 'TLEN',
- 'USLT',
- 'TPOS',
- 'TCON',
- 'TENC',
- 'TCOP',
- 'TPUB',
- 'TOPE',
- 'WXXX',
- 'COMM',
- 'TCOM'
- );
- var $aTV23t = array( // array of titles for sys tags
- 'Title',
- 'Album',
- 'Author',
- 'AlbumAuthor',
- 'Track',
- 'Year',
- 'Length', # Lenght
- 'Lyric',
- 'Desc',
- 'Genre',
- 'Encoded',
- 'Copyright',
- 'Publisher',
- 'OriginalArtist',
- 'URL',
- 'Comments',
- 'Composer'
- );
- var $aTV22 = array( // array of possible sys tags (for old version of ID3)
- 'TT2',
- 'TAL',
- 'TP1',
- 'TRK',
- 'TYE',
- 'TLE',
- 'ULT'
- );
- var $aTV22t = array( // array of titles for sys tags
- 'Title',
- 'Album',
- 'Author',
- 'Track',
- 'Year',
- 'Length', # Lenght
- 'Lyric'
- );
- // constructor
- function __construct() {
- }
- // functions
- function getTagsInfo($sFilepath) {
- // read source file
- $iFSize = filesize($sFilepath);
- $vFD = fopen($sFilepath,'r');
- $sSrc = fread($vFD,$iFSize);
- fclose($vFD);
- // obtain base info
- if (substr($sSrc,0,3) == 'ID3') {
- $aInfo['FileName'] = $sFilepath;
- $aInfo['Version'] = hexdec(bin2hex(substr($sSrc,3,1))).'.'.hexdec(bin2hex(substr($sSrc,4,1)));
- }
- // passing through possible tags of idv2 (v3 and v4)
- if ($aInfo['Version'] == '4.0' || $aInfo['Version'] == '3.0') {
- for ($i = 0; $i < count($this->aTV23); $i++) {
- if (strpos($sSrc, $this->aTV23[$i].chr(0)) != FALSE) {
- $s = '';
- $iPos = strpos($sSrc, $this->aTV23[$i].chr(0));
- $iLen = hexdec(bin2hex(substr($sSrc,($iPos + 5),3)));
- $data = substr($sSrc, $iPos, 9 + $iLen);
- for ($a = 0; $a < strlen($data); $a++) {
- $char = substr($data, $a, 1);
- if ($char >= ' ' && $char <= '~')
- $s .= $char;
- }
- if (substr($s, 0, 4) == $this->aTV23[$i]) {
- $iSL = 4;
- if ($this->aTV23[$i] == 'USLT') {
- $iSL = 7;
- } elseif ($this->aTV23[$i] == 'TALB') {
- $iSL = 5;
- } elseif ($this->aTV23[$i] == 'TENC') {
- $iSL = 6;
- }
- $aInfo[$this->aTV23t[$i]] = substr($s, $iSL);
- }
- }
- }
- }
- // passing through possible tags of idv2 (v2)
- if($aInfo['Version'] == '2.0') {
- for ($i = 0; $i < count($this->aTV22); $i++) {
- if (strpos($sSrc, $this->aTV22[$i].chr(0)) != FALSE) {
- $s = '';
- $iPos = strpos($sSrc, $this->aTV22[$i].chr(0));
- $iLen = hexdec(bin2hex(substr($sSrc,($iPos + 3),3)));
- $data = substr($sSrc, $iPos, 6 + $iLen);
- for ($a = 0; $a < strlen($data); $a++) {
- $char = substr($data, $a, 1);
- if ($char >= ' ' && $char <= '~')
- $s .= $char;
- }
- if (substr($s, 0, 3) == $this->aTV22[$i]) {
- $iSL = 3;
- if ($this->aTV22[$i] == 'ULT') {
- $iSL = 6;
- }
- $aInfo[$this->aTV22t[$i]] = substr($s, $iSL);
- }
- }
- }
- }
- return $aInfo;
- }
- }
- ?>
|