PageRenderTime 76ms CodeModel.GetById 20ms RepoModel.GetById 1ms app.codeStats 0ms

/player/flashmp3player.php

https://gitlab.com/tutaalexandr/urthecast.local
PHP | 1729 lines | 1561 code | 150 blank | 18 comment | 234 complexity | a33043e3845ff73300c805d466879eac MD5 | raw file
  1. <?php
  2. $exclude_files = array(
  3. "_derived",
  4. "_private",
  5. "_vti_cnf",
  6. "_vti_pvt",
  7. "vti_script",
  8. "_vti_txt"
  9. ); // add any other folders or files you wish to exclude from the player.
  10. //READING ID3 TAGS
  11. // id3 tags converting to utf-8
  12. function conv($str) {
  13. for ( $i = 0, $length = strlen($str); $i < $length; $i++ ) {
  14. if((ord($str[$i])=='0'||ord($str[$i])=='4')){
  15. $str1 = $str1;
  16. }else{ $str1 = $str1.$str[$i];}
  17. }
  18. if( ( strpos($str1,chr(209).chr(143).chr(209).chr(142)) === 0) )
  19. { $str2 = substr($str1, 4); $str1 = $str2;}else{$str1 = $str1;}
  20. return $str1;
  21. }
  22. function detectUTF8($string)
  23. {
  24. return preg_match('%(?:
  25. [\xC2-\xDF][\x80-\xBF] # non-overlong 2-byte
  26. |\xE0[\xA0-\xBF][\x80-\xBF] # excluding overlongs
  27. |[\xE1-\xEC\xEE\xEF][\x80-\xBF]{2} # straight 3-byte
  28. |\xED[\x80-\x9F][\x80-\xBF] # excluding surrogates
  29. |\xF0[\x90-\xBF][\x80-\xBF]{2} # planes 1-3
  30. |[\xF1-\xF3][\x80-\xBF]{3} # planes 4-15
  31. |\xF4[\x80-\x8F][\x80-\xBF]{2} # plane 16
  32. )+%xs', $string);
  33. }
  34. function cp1251_utf8( $sInput )
  35. {
  36. $sOutput = "";
  37. for ( $i = 0; $i < strlen( $sInput ); $i++ )
  38. {
  39. $iAscii = ord( $sInput[$i] );
  40. if ( $iAscii >= 192 && $iAscii <= 255 )
  41. $sOutput .= "&#".( 1040 + ( $iAscii - 192 ) ).";";
  42. else if ( $iAscii == 168 )
  43. $sOutput .= "&#".( 1025 ).";";
  44. else if ( $iAscii == 184 )
  45. $sOutput .= "&#".( 1105 ).";";
  46. else
  47. $sOutput .= $sInput[$i];
  48. }
  49. return $sOutput;
  50. }
  51. function encoding($string){
  52. if (function_exists('iconv') && false) {
  53. if (@!iconv('utf-8', 'cp1251', $string)) {
  54. $string = iconv('cp1251', 'utf-8', $string);
  55. }
  56. return $string;
  57. } else {
  58. if (detectUTF8($string)) {
  59. return $string;
  60. } else {
  61. return cp1251_utf8($string);
  62. }
  63. }
  64. }
  65. error_reporting(0);
  66. //errors
  67. $errors[0] = '';//means no error. (Change it and things can become very strange)
  68. $errors[1] = 'File Name not set';
  69. $errors[2] = 'Unable to open MP3 file';
  70. $errors[3] = 'ID3v2 Tag not found on this file';
  71. $errors[4] = 'TAG not Supported';
  72. $errors[5] = 'Tag not found(maybe you need to call getInfo() first?)';
  73. //pear
  74. define('PEAR_ERROR_RETURN', 1);
  75. define('PEAR_ERROR_PRINT', 2);
  76. define('PEAR_ERROR_TRIGGER', 4);
  77. define('PEAR_ERROR_DIE', 8);
  78. define('PEAR_ERROR_CALLBACK', 16);
  79. define('PEAR_ERROR_EXCEPTION', 32);
  80. define('PEAR_ZE2', (function_exists('version_compare') &&
  81. version_compare(zend_version(), "2-dev", "ge")));
  82. if (substr(PHP_OS, 0, 3) == 'WIN') {
  83. define('OS_WINDOWS', true);
  84. define('OS_UNIX', false);
  85. define('PEAR_OS', 'Windows');
  86. } else {
  87. define('OS_WINDOWS', false);
  88. define('OS_UNIX', true);
  89. define('PEAR_OS', 'Unix');
  90. }
  91. if (!defined('PATH_SEPARATOR')) {
  92. if (OS_WINDOWS) {
  93. define('PATH_SEPARATOR', ';');
  94. } else {
  95. define('PATH_SEPARATOR', ':');
  96. }
  97. }
  98. $GLOBALS['_PEAR_default_error_mode'] = PEAR_ERROR_RETURN;
  99. $GLOBALS['_PEAR_default_error_options'] = E_USER_NOTICE;
  100. $GLOBALS['_PEAR_destructor_object_list'] = array();
  101. $GLOBALS['_PEAR_shutdown_funcs'] = array();
  102. $GLOBALS['_PEAR_error_handler_stack'] = array();
  103. @ini_set('track_errors', true);
  104. class PEAR
  105. {
  106. var $_debug = false;
  107. var $_default_error_mode = null;
  108. var $_default_error_options = null;
  109. var $_default_error_handler = '';
  110. var $_error_class = 'PEAR_Error';
  111. var $_expected_errors = array();
  112. function PEAR($error_class = null)
  113. {
  114. $classname = strtolower(get_class($this));
  115. if ($this->_debug) {
  116. print "PEAR constructor called, class=$classname\n";
  117. }
  118. if ($error_class !== null) {
  119. $this->_error_class = $error_class;
  120. }
  121. while ($classname && strcasecmp($classname, "pear")) {
  122. $destructor = "_$classname";
  123. if (method_exists($this, $destructor)) {
  124. global $_PEAR_destructor_object_list;
  125. $_PEAR_destructor_object_list[] = &$this;
  126. if (!isset($GLOBALS['_PEAR_SHUTDOWN_REGISTERED'])) {
  127. register_shutdown_function("_PEAR_call_destructors");
  128. $GLOBALS['_PEAR_SHUTDOWN_REGISTERED'] = true;
  129. }
  130. break;
  131. } else {
  132. $classname = get_parent_class($classname);
  133. }
  134. }
  135. }
  136. function _PEAR() {
  137. if ($this->_debug) {
  138. printf("PEAR destructor called, class=%s\n", strtolower(get_class($this)));
  139. }
  140. }
  141. function &getStaticProperty($class, $var)
  142. {
  143. static $properties;
  144. return $properties[$class][$var];
  145. }
  146. function registerShutdownFunc($func, $args = array())
  147. {
  148. if (!isset($GLOBALS['_PEAR_SHUTDOWN_REGISTERED'])) {
  149. register_shutdown_function("_PEAR_call_destructors");
  150. $GLOBALS['_PEAR_SHUTDOWN_REGISTERED'] = true;
  151. }
  152. $GLOBALS['_PEAR_shutdown_funcs'][] = array($func, $args);
  153. }
  154. function isError($data, $code = null)
  155. {
  156. if (is_a($data, 'PEAR_Error')) {
  157. if (is_null($code)) {
  158. return true;
  159. } elseif (is_string($code)) {
  160. return $data->getMessage() == $code;
  161. } else {
  162. return $data->getCode() == $code;
  163. }
  164. }
  165. return false;
  166. }
  167. function setErrorHandling($mode = null, $options = null)
  168. {
  169. if (isset($this) && is_a($this, 'PEAR')) {
  170. $setmode = &$this->_default_error_mode;
  171. $setoptions = &$this->_default_error_options;
  172. } else {
  173. $setmode = &$GLOBALS['_PEAR_default_error_mode'];
  174. $setoptions = &$GLOBALS['_PEAR_default_error_options'];
  175. }
  176. switch ($mode) {
  177. case PEAR_ERROR_EXCEPTION:
  178. case PEAR_ERROR_RETURN:
  179. case PEAR_ERROR_PRINT:
  180. case PEAR_ERROR_TRIGGER:
  181. case PEAR_ERROR_DIE:
  182. case null:
  183. $setmode = $mode;
  184. $setoptions = $options;
  185. break;
  186. case PEAR_ERROR_CALLBACK:
  187. $setmode = $mode;
  188. if (is_callable($options)) {
  189. $setoptions = $options;
  190. } else {
  191. trigger_error("invalid error callback", E_USER_WARNING);
  192. }
  193. break;
  194. default:
  195. trigger_error("invalid error mode", E_USER_WARNING);
  196. break;
  197. }
  198. }
  199. function expectError($code = '*')
  200. {
  201. if (is_array($code)) {
  202. array_push($this->_expected_errors, $code);
  203. } else {
  204. array_push($this->_expected_errors, array($code));
  205. }
  206. return sizeof($this->_expected_errors);
  207. }
  208. function popExpect()
  209. {
  210. return array_pop($this->_expected_errors);
  211. }
  212. function _checkDelExpect($error_code)
  213. {
  214. $deleted = false;
  215. foreach ($this->_expected_errors AS $key => $error_array) {
  216. if (in_array($error_code, $error_array)) {
  217. unset($this->_expected_errors[$key][array_search($error_code, $error_array)]);
  218. $deleted = true;
  219. }
  220. if (0 == count($this->_expected_errors[$key])) {
  221. unset($this->_expected_errors[$key]);
  222. }
  223. }
  224. return $deleted;
  225. }
  226. function delExpect($error_code)
  227. {
  228. $deleted = false;
  229. if ((is_array($error_code) && (0 != count($error_code)))) {
  230. foreach($error_code as $key => $error) {
  231. if ($this->_checkDelExpect($error)) {
  232. $deleted = true;
  233. } else {
  234. $deleted = false;
  235. }
  236. }
  237. return $deleted ? true : PEAR::raiseError("The expected error you submitted does not exist"); // IMPROVE ME
  238. } elseif (!empty($error_code)) {
  239. if ($this->_checkDelExpect($error_code)) {
  240. return true;
  241. } else {
  242. return PEAR::raiseError("The expected error you submitted does not exist"); // IMPROVE ME
  243. }
  244. } else {
  245. return PEAR::raiseError("The expected error you submitted is empty"); // IMPROVE ME
  246. }
  247. }
  248. function &raiseError($message = null,
  249. $code = null,
  250. $mode = null,
  251. $options = null,
  252. $userinfo = null,
  253. $error_class = null,
  254. $skipmsg = false)
  255. {
  256. if (is_object($message)) {
  257. $code = $message->getCode();
  258. $userinfo = $message->getUserInfo();
  259. $error_class = $message->getType();
  260. $message->error_message_prefix = '';
  261. $message = $message->getMessage();
  262. }
  263. if (isset($this) && isset($this->_expected_errors) && sizeof($this->_expected_errors) > 0 && sizeof($exp = end($this->_expected_errors))) {
  264. if ($exp[0] == "*" ||
  265. (is_int(reset($exp)) && in_array($code, $exp)) ||
  266. (is_string(reset($exp)) && in_array($message, $exp))) {
  267. $mode = PEAR_ERROR_RETURN;
  268. }
  269. }
  270. if ($mode === null) {
  271. if (isset($this) && isset($this->_default_error_mode)) {
  272. $mode = $this->_default_error_mode;
  273. $options = $this->_default_error_options;
  274. } elseif (isset($GLOBALS['_PEAR_default_error_mode'])) {
  275. $mode = $GLOBALS['_PEAR_default_error_mode'];
  276. $options = $GLOBALS['_PEAR_default_error_options'];
  277. }
  278. }
  279. if ($error_class !== null) {
  280. $ec = $error_class;
  281. } elseif (isset($this) && isset($this->_error_class)) {
  282. $ec = $this->_error_class;
  283. } else {
  284. $ec = 'PEAR_Error';
  285. }
  286. if ($skipmsg) {
  287. $a = new $ec($code, $mode, $options, $userinfo);
  288. return $a;
  289. } else {
  290. $a = new $ec($message, $code, $mode, $options, $userinfo);
  291. return $a;
  292. }
  293. }
  294. function &throwError($message = null,
  295. $code = null,
  296. $userinfo = null)
  297. {
  298. if (isset($this) && is_a($this, 'PEAR')) {
  299. $a = &$this->raiseError($message, $code, null, null, $userinfo);
  300. return $a;
  301. } else {
  302. $a = &PEAR::raiseError($message, $code, null, null, $userinfo);
  303. return $a;
  304. }
  305. }
  306. function staticPushErrorHandling($mode, $options = null)
  307. {
  308. $stack = &$GLOBALS['_PEAR_error_handler_stack'];
  309. $def_mode = &$GLOBALS['_PEAR_default_error_mode'];
  310. $def_options = &$GLOBALS['_PEAR_default_error_options'];
  311. $stack[] = array($def_mode, $def_options);
  312. switch ($mode) {
  313. case PEAR_ERROR_EXCEPTION:
  314. case PEAR_ERROR_RETURN:
  315. case PEAR_ERROR_PRINT:
  316. case PEAR_ERROR_TRIGGER:
  317. case PEAR_ERROR_DIE:
  318. case null:
  319. $def_mode = $mode;
  320. $def_options = $options;
  321. break;
  322. case PEAR_ERROR_CALLBACK:
  323. $def_mode = $mode;
  324. if (is_callable($options)) {
  325. $def_options = $options;
  326. } else {
  327. trigger_error("invalid error callback", E_USER_WARNING);
  328. }
  329. break;
  330. default:
  331. trigger_error("invalid error mode", E_USER_WARNING);
  332. break;
  333. }
  334. $stack[] = array($mode, $options);
  335. return true;
  336. }
  337. function staticPopErrorHandling()
  338. {
  339. $stack = &$GLOBALS['_PEAR_error_handler_stack'];
  340. $setmode = &$GLOBALS['_PEAR_default_error_mode'];
  341. $setoptions = &$GLOBALS['_PEAR_default_error_options'];
  342. array_pop($stack);
  343. list($mode, $options) = $stack[sizeof($stack) - 1];
  344. array_pop($stack);
  345. switch ($mode) {
  346. case PEAR_ERROR_EXCEPTION:
  347. case PEAR_ERROR_RETURN:
  348. case PEAR_ERROR_PRINT:
  349. case PEAR_ERROR_TRIGGER:
  350. case PEAR_ERROR_DIE:
  351. case null:
  352. $setmode = $mode;
  353. $setoptions = $options;
  354. break;
  355. case PEAR_ERROR_CALLBACK:
  356. $setmode = $mode;
  357. if (is_callable($options)) {
  358. $setoptions = $options;
  359. } else {
  360. trigger_error("invalid error callback", E_USER_WARNING);
  361. }
  362. break;
  363. default:
  364. trigger_error("invalid error mode", E_USER_WARNING);
  365. break;
  366. }
  367. return true;
  368. }
  369. function pushErrorHandling($mode, $options = null)
  370. {
  371. $stack = &$GLOBALS['_PEAR_error_handler_stack'];
  372. if (isset($this) && is_a($this, 'PEAR')) {
  373. $def_mode = &$this->_default_error_mode;
  374. $def_options = &$this->_default_error_options;
  375. } else {
  376. $def_mode = &$GLOBALS['_PEAR_default_error_mode'];
  377. $def_options = &$GLOBALS['_PEAR_default_error_options'];
  378. }
  379. $stack[] = array($def_mode, $def_options);
  380. if (isset($this) && is_a($this, 'PEAR')) {
  381. $this->setErrorHandling($mode, $options);
  382. } else {
  383. PEAR::setErrorHandling($mode, $options);
  384. }
  385. $stack[] = array($mode, $options);
  386. return true;
  387. }
  388. function popErrorHandling()
  389. {
  390. $stack = &$GLOBALS['_PEAR_error_handler_stack'];
  391. array_pop($stack);
  392. list($mode, $options) = $stack[sizeof($stack) - 1];
  393. array_pop($stack);
  394. if (isset($this) && is_a($this, 'PEAR')) {
  395. $this->setErrorHandling($mode, $options);
  396. } else {
  397. PEAR::setErrorHandling($mode, $options);
  398. }
  399. return true;
  400. }
  401. function loadExtension($ext)
  402. {
  403. if (!extension_loaded($ext)) {
  404. if ((ini_get('enable_dl') != 1) || (ini_get('safe_mode') == 1)) {
  405. return false;
  406. }
  407. if (OS_WINDOWS) {
  408. $suffix = '.dll';
  409. } elseif (PHP_OS == 'HP-UX') {
  410. $suffix = '.sl';
  411. } elseif (PHP_OS == 'AIX') {
  412. $suffix = '.a';
  413. } elseif (PHP_OS == 'OSX') {
  414. $suffix = '.bundle';
  415. } else {
  416. $suffix = '.so';
  417. }
  418. return @dl('php_'.$ext.$suffix) || @dl($ext.$suffix);
  419. }
  420. return true;
  421. }
  422. }
  423. function _PEAR_call_destructors()
  424. {
  425. global $_PEAR_destructor_object_list;
  426. if (is_array($_PEAR_destructor_object_list) &&
  427. sizeof($_PEAR_destructor_object_list))
  428. {
  429. reset($_PEAR_destructor_object_list);
  430. if (@PEAR::getStaticProperty('PEAR', 'destructlifo')) {
  431. $_PEAR_destructor_object_list = array_reverse($_PEAR_destructor_object_list);
  432. }
  433. while (list($k, $objref) = each($_PEAR_destructor_object_list)) {
  434. $classname = get_class($objref);
  435. while ($classname) {
  436. $destructor = "_$classname";
  437. if (method_exists($objref, $destructor)) {
  438. $objref->$destructor();
  439. break;
  440. } else {
  441. $classname = get_parent_class($classname);
  442. }
  443. }
  444. }
  445. $_PEAR_destructor_object_list = array();
  446. }
  447. if (is_array($GLOBALS['_PEAR_shutdown_funcs']) AND !empty($GLOBALS['_PEAR_shutdown_funcs'])) {
  448. foreach ($GLOBALS['_PEAR_shutdown_funcs'] as $value) {
  449. call_user_func_array($value[0], $value[1]);
  450. }
  451. }
  452. }
  453. class PEAR_Error
  454. {
  455. var $error_message_prefix = '';
  456. var $mode = PEAR_ERROR_RETURN;
  457. var $level = E_USER_NOTICE;
  458. var $code = -1;
  459. var $message = '';
  460. var $userinfo = '';
  461. var $backtrace = null;
  462. function PEAR_Error($message = 'unknown error', $code = null,
  463. $mode = null, $options = null, $userinfo = null)
  464. {
  465. if ($mode === null) {
  466. $mode = PEAR_ERROR_RETURN;
  467. }
  468. $this->message = $message;
  469. $this->code = $code;
  470. $this->mode = $mode;
  471. $this->userinfo = $userinfo;
  472. if (function_exists("debug_backtrace")) {
  473. if (@!PEAR::getStaticProperty('PEAR_Error', 'skiptrace')) {
  474. $this->backtrace = debug_backtrace();
  475. }
  476. }
  477. if ($mode & PEAR_ERROR_CALLBACK) {
  478. $this->level = E_USER_NOTICE;
  479. $this->callback = $options;
  480. } else {
  481. if ($options === null) {
  482. $options = E_USER_NOTICE;
  483. }
  484. $this->level = $options;
  485. $this->callback = null;
  486. }
  487. if ($this->mode & PEAR_ERROR_PRINT) {
  488. if (is_null($options) || is_int($options)) {
  489. $format = "%s";
  490. } else {
  491. $format = $options;
  492. }
  493. printf($format, $this->getMessage());
  494. }
  495. if ($this->mode & PEAR_ERROR_TRIGGER) {
  496. trigger_error($this->getMessage(), $this->level);
  497. }
  498. if ($this->mode & PEAR_ERROR_DIE) {
  499. $msg = $this->getMessage();
  500. if (is_null($options) || is_int($options)) {
  501. $format = "%s";
  502. if (substr($msg, -1) != "\n") {
  503. $msg .= "\n";
  504. }
  505. } else {
  506. $format = $options;
  507. }
  508. die(sprintf($format, $msg));
  509. }
  510. if ($this->mode & PEAR_ERROR_CALLBACK) {
  511. if (is_callable($this->callback)) {
  512. call_user_func($this->callback, $this);
  513. }
  514. }
  515. if ($this->mode & PEAR_ERROR_EXCEPTION) {
  516. trigger_error("PEAR_ERROR_EXCEPTION is obsolete, use class PEAR_Exception for exceptions", E_USER_WARNING);
  517. eval('$e = new Exception($this->message, $this->code);throw($e);');
  518. }
  519. }
  520. function getMode() {
  521. return $this->mode;
  522. }
  523. function getCallback() {
  524. return $this->callback;
  525. }
  526. function getMessage()
  527. {
  528. return ($this->error_message_prefix . $this->message);
  529. }
  530. function getCode()
  531. {
  532. return $this->code;
  533. }
  534. function getType()
  535. {
  536. return get_class($this);
  537. }
  538. function getUserInfo()
  539. {
  540. return $this->userinfo;
  541. }
  542. function getDebugInfo()
  543. {
  544. return $this->getUserInfo();
  545. }
  546. function getBacktrace($frame = null)
  547. {
  548. if (defined('PEAR_IGNORE_BACKTRACE')) {
  549. return null;
  550. }
  551. if ($frame === null) {
  552. return $this->backtrace;
  553. }
  554. return $this->backtrace[$frame];
  555. }
  556. function addUserInfo($info)
  557. {
  558. if (empty($this->userinfo)) {
  559. $this->userinfo = $info;
  560. } else {
  561. $this->userinfo .= " ** $info";
  562. }
  563. }
  564. function toString() {
  565. $modes = array();
  566. $levels = array(E_USER_NOTICE => 'notice',
  567. E_USER_WARNING => 'warning',
  568. E_USER_ERROR => 'error');
  569. if ($this->mode & PEAR_ERROR_CALLBACK) {
  570. if (is_array($this->callback)) {
  571. $callback = (is_object($this->callback[0]) ?
  572. strtolower(get_class($this->callback[0])) :
  573. $this->callback[0]) . '::' .
  574. $this->callback[1];
  575. } else {
  576. $callback = $this->callback;
  577. }
  578. return sprintf('[%s: message="%s" code=%d mode=callback '.
  579. 'callback=%s prefix="%s" info="%s"]',
  580. strtolower(get_class($this)), $this->message, $this->code,
  581. $callback, $this->error_message_prefix,
  582. $this->userinfo);
  583. }
  584. if ($this->mode & PEAR_ERROR_PRINT) {
  585. $modes[] = 'print';
  586. }
  587. if ($this->mode & PEAR_ERROR_TRIGGER) {
  588. $modes[] = 'trigger';
  589. }
  590. if ($this->mode & PEAR_ERROR_DIE) {
  591. $modes[] = 'die';
  592. }
  593. if ($this->mode & PEAR_ERROR_RETURN) {
  594. $modes[] = 'return';
  595. }
  596. return sprintf('[%s: message="%s" code=%d mode=%s level=%s '.
  597. 'prefix="%s" info="%s"]',
  598. strtolower(get_class($this)), $this->message, $this->code,
  599. implode("|", $modes), $levels[$this->level],
  600. $this->error_message_prefix,
  601. $this->userinfo);
  602. }
  603. }
  604. //id3 v1
  605. define('PEAR_MP3_ID_FNO', 1);
  606. define('PEAR_MP3_ID_RE', 2);
  607. define('PEAR_MP3_ID_TNF', 3);
  608. define('PEAR_MP3_ID_NOMP3', 4);
  609. class MP3_Id {
  610. var $file = false;
  611. var $id3v1 = false;
  612. var $id3v11 = false;
  613. var $id3v2 = false;
  614. var $name = '';
  615. var $artists = '';
  616. var $album = '';
  617. var $year = '';
  618. var $comment = '';
  619. var $track = 0;
  620. var $genre = '';
  621. var $genreno = 255;
  622. var $studied = false;
  623. var $mpeg_ver = 0;
  624. var $layer = 0;
  625. var $bitrate = 0;
  626. var $crc = false;
  627. var $frequency = 0;
  628. var $encoding_type = 0;
  629. var $samples_per_frame = 0;
  630. var $samples = 0;
  631. var $musicsize = -1;
  632. var $frames = 0;
  633. var $quality = 0;
  634. var $padding = false;
  635. var $private = false;
  636. var $mode = '';
  637. var $copyright = false;
  638. var $original = false;
  639. var $emphasis = '';
  640. var $filesize = -1;
  641. var $frameoffset = -1;
  642. var $lengthh = false;
  643. var $length = false;
  644. var $lengths = false;
  645. var $error = false;
  646. var $debug = false;
  647. var $debugbeg = '<DIV STYLE="margin: 0.5 em; padding: 0.5 em; border-width: thin; border-color: black; border-style: solid">';
  648. var $debugend = '</DIV>';
  649. //////////////////////////////////////////////////
  650. function MP3_Id($study = false)
  651. {
  652. if(defined('ID3_SHOW_DEBUG')) $this->debug = true;
  653. $this->study=($study || defined('ID3_AUTO_STUDY'));
  654. }
  655. /////////////////////////////////////////////////
  656. function read( $file="")
  657. {
  658. if ($this->debug) print($this->debugbeg . "id3('$file')<HR>\n");
  659. if(!empty($file))$this->file = $file;
  660. if ($this->debug) print($this->debugend);
  661. return $this->_read_v1();
  662. }
  663. /////////////////////////////////////////////////
  664. function setTag($name, $value)
  665. {
  666. if( is_array($name))
  667. {
  668. foreach( $name as $n => $v)
  669. {
  670. $this -> $n = $v ;
  671. }
  672. }
  673. else
  674. {
  675. $this -> $name = $value ;
  676. }
  677. }
  678. /////////////////////////////////////////////////
  679. function getTag($name, $default = 0)
  680. {
  681. if(empty($this -> $name))
  682. {
  683. return $default ;
  684. }
  685. else
  686. {
  687. return $this -> $name ;
  688. }
  689. }
  690. //////////////////////////////////////////////////
  691. function write($v1 = true)
  692. {
  693. if ($this->debug) print($this->debugbeg . "write()<HR>\n");
  694. if ($v1)
  695. {
  696. $this->_write_v1();
  697. }
  698. if ($this->debug) print($this->debugend);
  699. }
  700. function study()
  701. {
  702. $this->studied = true;
  703. $this->_readframe();
  704. }
  705. /////////////////////////////////////////////////////
  706. function copy($from)
  707. {
  708. if ($this->debug) print($this->debugbeg . "copy(\$from)<HR>\n");
  709. $this->name = $from->name;
  710. $this->artists = $from->artists;
  711. $this->album = $from->album;
  712. $this->year = $from->year;
  713. $this->comment = $from->comment;
  714. $this->track = $from->track;
  715. $this->genre = $from->genre;
  716. $this->genreno = $from->genreno;
  717. if ($this->debug) print($this->debugend);
  718. }
  719. ///////////////////////////////////////////////////
  720. function remove($id3v1 = true, $id3v2 = true)
  721. {
  722. if ($this->debug) print($this->debugbeg . "remove()<HR>\n");
  723. if ($id3v1)
  724. {
  725. $this->_remove_v1();
  726. }
  727. if ($id3v2)
  728. {
  729. }
  730. if ($this->debug) print($this->debugend);
  731. }
  732. //////////////////////////////////////////////////
  733. function _read_v1()
  734. {
  735. if ($this->debug) print($this->debugbeg . "_read_v1()<HR>\n");
  736. $mqr = get_magic_quotes_runtime();
  737. set_magic_quotes_runtime(0);
  738. if (! ($f = @fopen($this->file, 'rb')) ) {
  739. return PEAR::raiseError( "Unable to open " . $this->file, PEAR_MP3_ID_FNO);
  740. }
  741. if (fseek($f, -128, SEEK_END) == -1) {
  742. return PEAR::raiseError( 'Unable to see to end - 128 of ' . $this->file, PEAR_MP3_ID_RE);
  743. }
  744. $r = fread($f, 128);
  745. fclose($f);
  746. set_magic_quotes_runtime($mqr);
  747. if ($this->debug) {
  748. $unp = unpack('H*raw', $r);
  749. print_r($unp);
  750. }
  751. $id3tag = $this->_decode_v1($r);
  752. if(!PEAR::isError( $id3tag)) {
  753. $this->id3v1 = true;
  754. $tmp = explode(Chr(0), $id3tag['NAME']);
  755. $this->name = $tmp[0];
  756. $tmp = explode(Chr(0), $id3tag['ARTISTS']);
  757. $this->artists = $tmp[0];
  758. $tmp = explode(Chr(0), $id3tag['ALBUM']);
  759. $this->album = $tmp[0];
  760. $tmp = explode(Chr(0), $id3tag['YEAR']);
  761. $this->year = $tmp[0];
  762. $tmp = explode(Chr(0), $id3tag['COMMENT']);
  763. $this->comment = $tmp[0];
  764. if (isset($id3tag['TRACK'])) {
  765. $this->id3v11 = true;
  766. $this->track = $id3tag['TRACK'];
  767. }
  768. $this->genreno = $id3tag['GENRENO'];
  769. $this->genre = $id3tag['GENRE'];
  770. } else {
  771. return $id3tag ;
  772. }
  773. if ($this->debug) print($this->debugend);
  774. }
  775. ///////////////////////////////////////////////
  776. function _decode_v1($rawtag) {
  777. if ($this->debug) print($this->debugbeg . "_decode_v1(\$rawtag)<HR>\n");
  778. if ($rawtag[125] == Chr(0) and $rawtag[126] != Chr(0)) {
  779. $format = 'a3TAG/a30NAME/a30ARTISTS/a30ALBUM/a4YEAR/a28COMMENT/x1/C1TRACK/C1GENRENO';
  780. } else {
  781. $format = 'a3TAG/a30NAME/a30ARTISTS/a30ALBUM/a4YEAR/a30COMMENT/C1GENRENO';
  782. }
  783. $id3tag = unpack($format, $rawtag);
  784. if ($this->debug) print_r($id3tag);
  785. if ($id3tag['TAG'] == 'TAG') {
  786. $id3tag['GENRE'] = $this->getgenre($id3tag['GENRENO']);
  787. } else {
  788. $id3tag = PEAR::raiseError( 'TAG not found', PEAR_MP3_ID_TNF);
  789. }
  790. if ($this->debug) print($this->debugend);
  791. return $id3tag;
  792. }
  793. //////////////////////////////////////
  794. function _write_v1() {
  795. if ($this->debug) print($this->debugbeg . "_write_v1()<HR>\n");
  796. $file = $this->file;
  797. if (! ($f = @fopen($file, 'r+b')) ) {
  798. return PEAR::raiseError( "Unable to open " . $file, PEAR_MP3_ID_FNO);
  799. }
  800. if (fseek($f, -128, SEEK_END) == -1) {
  801. return PEAR::raiseError( "Unable to see to end - 128 of " . $file, PEAR_MP3_ID_RE);
  802. }
  803. $this->genreno = $this->getgenreno($this->genre, $this->genreno);
  804. $newtag = $this->_encode_v1();
  805. $mqr = get_magic_quotes_runtime();
  806. set_magic_quotes_runtime(0);
  807. $r = fread($f, 128);
  808. if ( !PEAR::isError( $this->_decode_v1($r))) {
  809. if (fseek($f, -128, SEEK_END) == -1) {
  810. return PEAR::raiseError( "Unable to see to end - 128 of " . $file, PEAR_MP3_ID_RE);
  811. }
  812. fwrite($f, $newtag);
  813. } else {
  814. if (fseek($f, 0, SEEK_END) == -1) {
  815. return PEAR::raiseError( "Unable to see to end of " . $file, PEAR_MP3_ID_RE);
  816. }
  817. fwrite($f, $newtag);
  818. }
  819. fclose($f);
  820. set_magic_quotes_runtime($mqr);
  821. if ($this->debug) print($this->debugend);
  822. }
  823. //////////////////////////////////////////////////
  824. function _encode_v1() {
  825. if ($this->debug) print($this->debugbeg . "_encode_v1()<HR>\n");
  826. if ($this->track) {
  827. $id3pack = 'a3a30a30a30a4a28x1C1C1';
  828. $newtag = pack($id3pack,
  829. 'TAG',
  830. $this->name,
  831. $this->artists,
  832. $this->album,
  833. $this->year,
  834. $this->comment,
  835. $this->track,
  836. $this->genreno
  837. );
  838. } else {
  839. $id3pack = 'a3a30a30a30a4a30C1';
  840. $newtag = pack($id3pack,
  841. 'TAG',
  842. $this->name,
  843. $this->artists,
  844. $this->album,
  845. $this->year,
  846. $this->comment,
  847. $this->genreno
  848. );
  849. }
  850. if ($this->debug) {
  851. print('id3pack: ' . $id3pack . "\n");
  852. $unp = unpack('H*new', $newtag);
  853. print_r($unp);
  854. }
  855. if ($this->debug) print($this->debugend);
  856. return $newtag;
  857. }
  858. ///////////////////////////////////////////////
  859. function _remove_v1() {
  860. if ($this->debug) print($this->debugbeg . "_remove_v1()<HR>\n");
  861. $file = $this->file;
  862. if (! ($f = fopen($file, 'r+b')) ) {
  863. return PEAR::raiseError( "Unable to open " . $file, PEAR_MP3_ID_FNO);
  864. }
  865. if (fseek($f, -128, SEEK_END) == -1) {
  866. return PEAR::raiseError( 'Unable to see to end - 128 of ' . $file, PEAR_MP3_ID_RE);
  867. }
  868. $mqr = get_magic_quotes_runtime();
  869. set_magic_quotes_runtime(0);
  870. $r = fread($f, 128);
  871. $success = false;
  872. if ( !PEAR::isError( $this->_decode_v1($r))) {
  873. $size = filesize($this->file) - 128;
  874. if ($this->debug) print('size: old: ' . filesize($this->file));
  875. $success = ftruncate($f, $size);
  876. clearstatcache();
  877. if ($this->debug) print(' new: ' . filesize($this->file));
  878. }
  879. fclose($f);
  880. set_magic_quotes_runtime($mqr);
  881. if ($this->debug) print($this->debugend);
  882. return $success;
  883. }
  884. //////////////////////////////////////////////////
  885. function _readframe() {
  886. if ($this->debug) print($this->debugbeg . "_readframe()<HR>\n");
  887. $file = $this->file;
  888. $mqr = get_magic_quotes_runtime();
  889. set_magic_quotes_runtime(0);
  890. if (! ($f = fopen($file, 'rb')) ) {
  891. if ($this->debug) print($this->debugend);
  892. return PEAR::raiseError( "Unable to open " . $file, PEAR_MP3_ID_FNO) ;
  893. }
  894. $this->filesize = filesize($file);
  895. do {
  896. while (fread($f,1) != Chr(255)) {
  897. if ($this->debug) echo "Find...\n";
  898. if (feof($f)) {
  899. if ($this->debug) print($this->debugend);
  900. return PEAR::raiseError( "No mpeg frame found", PEAR_MP3_ID_NOMP3) ;
  901. }
  902. }
  903. fseek($f, ftell($f) - 1);
  904. $frameoffset = ftell($f);
  905. $r = fread($f, 4);
  906. $bits = sprintf("%'08b%'08b%'08b%'08b", ord($r{0}), ord($r{1}), ord($r{2}), ord($r{3}));
  907. } while (!$bits[8] and !$bits[9] and !$bits[10]);
  908. if ($this->debug) print('Bits: ' . $bits . "\n");
  909. $this->frameoffset = $frameoffset;
  910. if ($bits[11] == 0) {
  911. if (($bits[24] == 1) && ($bits[25] == 1)) {
  912. $vbroffset = 9;
  913. } else {
  914. $vbroffset = 17;
  915. }
  916. } else if ($bits[12] == 0) {
  917. if (($bits[24] == 1) && ($bits[25] == 1)) {
  918. $vbroffset = 9;
  919. } else {
  920. $vbroffset = 17;
  921. }
  922. } else {
  923. if (($bits[24] == 1) && ($bits[25] == 1)) {
  924. $vbroffset = 17;
  925. } else {
  926. $vbroffset = 32;
  927. }
  928. }
  929. fseek($f, ftell($f) + $vbroffset);
  930. $r = fread($f, 4);
  931. switch ($r) {
  932. case 'Xing':
  933. $this->encoding_type = 'VBR';
  934. case 'Info':
  935. if ($this->debug) print('Encoding Header: ' . $r . "\n");
  936. $r = fread($f, 4);
  937. $vbrbits = sprintf("%'08b", ord($r{3}));
  938. if ($this->debug) print('XING Header Bits: ' . $vbrbits . "\n");
  939. if ($vbrbits[7] == 1) {
  940. $r = fread($f, 4);
  941. $this->frames = unpack('N', $r);
  942. $this->frames = $this->frames[1];
  943. }
  944. if ($vbrbits[6] == 1) {
  945. $r = fread($f, 4);
  946. $this->musicsize = unpack('N', $r);
  947. $this->musicsize = $this->musicsize[1];
  948. }
  949. if ($vbrbits[5] == 1) {
  950. fseek($f, ftell($f) + 100);
  951. }
  952. if ($vbrbits[4] == 1) {
  953. $r = fread($f, 4);
  954. $this->quality = unpack('N', $r);
  955. $this->quality = $this->quality[1];
  956. }
  957. break;
  958. case 'VBRI':
  959. default:
  960. if ($vbroffset != 32) {
  961. fseek($f, ftell($f) + 32 - $vbroffset);
  962. $r = fread($f, 4);
  963. if ($r != 'VBRI') {
  964. $this->encoding_type = 'CBR';
  965. break;
  966. }
  967. } else {
  968. $this->encoding_type = 'CBR';
  969. break;
  970. }
  971. if ($this->debug) print('Encoding Header: ' . $r . "\n");
  972. $this->encoding_type = 'VBR';
  973. fseek($f, ftell($f) + 2);
  974. fseek($f, ftell($f) + 2);
  975. $r = fread($f, 2);
  976. $this->quality = unpack('n', $r);
  977. $this->quality = $this->quality[1];
  978. $r = fread($f, 4);
  979. $this->musicsize = unpack('N', $r);
  980. $this->musicsize = $this->musicsize[1];
  981. $r = fread($f, 4);
  982. $this->frames = unpack('N', $r);
  983. $this->frames = $this->frames[1];
  984. }
  985. fclose($f);
  986. set_magic_quotes_runtime($mqr);
  987. if ($bits[11] == 0) {
  988. $this->mpeg_ver = "2.5";
  989. $bitrates = array(
  990. '1' => array(0, 32, 48, 56, 64, 80, 96, 112, 128, 144, 160, 176, 192, 224, 256, 0),
  991. '2' => array(0, 8, 16, 24, 32, 40, 48, 56, 64, 80, 96, 112, 128, 144, 160, 0),
  992. '3' => array(0, 8, 16, 24, 32, 40, 48, 56, 64, 80, 96, 112, 128, 144, 160, 0),
  993. );
  994. } else if ($bits[12] == 0) {
  995. $this->mpeg_ver = "2";
  996. $bitrates = array(
  997. '1' => array(0, 32, 48, 56, 64, 80, 96, 112, 128, 144, 160, 176, 192, 224, 256, 0),
  998. '2' => array(0, 8, 16, 24, 32, 40, 48, 56, 64, 80, 96, 112, 128, 144, 160, 0),
  999. '3' => array(0, 8, 16, 24, 32, 40, 48, 56, 64, 80, 96, 112, 128, 144, 160, 0),
  1000. );
  1001. } else {
  1002. $this->mpeg_ver = "1";
  1003. $bitrates = array(
  1004. '1' => array(0, 32, 64, 96, 128, 160, 192, 224, 256, 288, 320, 352, 384, 416, 448, 0),
  1005. '2' => array(0, 32, 48, 56, 64, 80, 96, 112, 128, 160, 192, 224, 256, 320, 384, 0),
  1006. '3' => array(0, 32, 40, 48, 56, 64, 80, 96, 112, 128, 160, 192, 224, 256, 320, 0),
  1007. );
  1008. }
  1009. if ($this->debug) print('MPEG' . $this->mpeg_ver . "\n");
  1010. $layer = array(
  1011. array(0,3),
  1012. array(2,1),
  1013. );
  1014. $this->layer = $layer[$bits[13]][$bits[14]];
  1015. if ($this->debug) print('layer: ' . $this->layer . "\n");
  1016. if ($bits[15] == 0) {
  1017. if ($this->debug) print("protected (crc)\n");
  1018. $this->crc = true;
  1019. }
  1020. $bitrate = 0;
  1021. if ($bits[16] == 1) $bitrate += 8;
  1022. if ($bits[17] == 1) $bitrate += 4;
  1023. if ($bits[18] == 1) $bitrate += 2;
  1024. if ($bits[19] == 1) $bitrate += 1;
  1025. $this->bitrate = $bitrates[$this->layer][$bitrate];
  1026. $frequency = array(
  1027. '1' => array(
  1028. '0' => array(44100, 48000),
  1029. '1' => array(32000, 0),
  1030. ),
  1031. '2' => array(
  1032. '0' => array(22050, 24000),
  1033. '1' => array(16000, 0),
  1034. ),
  1035. '2.5' => array(
  1036. '0' => array(11025, 12000),
  1037. '1' => array(8000, 0),
  1038. ),
  1039. );
  1040. $this->frequency = $frequency[$this->mpeg_ver][$bits[20]][$bits[21]];
  1041. $this->padding = $bits[22];
  1042. $this->private = $bits[23];
  1043. $mode = array(
  1044. array('Stereo', 'Joint Stereo'),
  1045. array('Dual Channel', 'Mono'),
  1046. );
  1047. $this->mode = $mode[$bits[24]][$bits[25]];
  1048. $this->copyright = $bits[28];
  1049. $this->original = $bits[29];
  1050. $emphasis = array(
  1051. array('none', '50/15ms'),
  1052. array('', 'CCITT j.17'),
  1053. );
  1054. $this->emphasis = $emphasis[$bits[30]][$bits[31]];
  1055. $samplesperframe = array(
  1056. '1' => array(
  1057. '1' => 384,
  1058. '2' => 1152,
  1059. '3' => 1152
  1060. ),
  1061. '2' => array(
  1062. '1' => 384,
  1063. '2' => 1152,
  1064. '3' => 576
  1065. ),
  1066. '2.5' => array(
  1067. '1' => 384,
  1068. '2' => 1152,
  1069. '3' => 576
  1070. ),
  1071. );
  1072. $this->samples_per_frame = $samplesperframe[$this->mpeg_ver][$this->layer];
  1073. if ($this->encoding_type != 'VBR') {
  1074. if ($this->bitrate == 0) {
  1075. $s = -1;
  1076. } else {
  1077. $s = ((8*filesize($this->file))/1000) / $this->bitrate;
  1078. }
  1079. $this->length = sprintf('%02d:%02d',floor($s/60),floor($s-(floor($s/60)*60)));
  1080. $this->lengthh = sprintf('%02d:%02d:%02d',floor($s/3600),floor($s/60),floor($s-(floor($s/60)*60)));
  1081. $this->lengths = (int)$s;
  1082. $this->samples = ceil($this->lengths * $this->frequency);
  1083. if(0 != $this->samples_per_frame) {
  1084. $this->frames = ceil($this->samples / $this->samples_per_frame);
  1085. } else {
  1086. $this->frames = 0;
  1087. }
  1088. $this->musicsize = ceil($this->lengths * $this->bitrate * 1000 / 8);
  1089. } else {
  1090. $this->samples = $this->samples_per_frame * $this->frames;
  1091. $s = $this->samples / $this->frequency;
  1092. $this->length = sprintf('%02d:%02d',floor($s/60),floor($s-(floor($s/60)*60)));
  1093. $this->lengthh = sprintf('%02d:%02d:%02d',floor($s/3600),floor($s/60),floor($s-(floor($s/60)*60)));
  1094. $this->lengths = (int)$s;
  1095. $this->bitrate = (int)(($this->musicsize / $s) * 8 / 1000);
  1096. }
  1097. if ($this->debug) print($this->debugend);
  1098. }
  1099. ////////////////////////////////////////////
  1100. function getGenre($genreno) {
  1101. if ($this->debug) print($this->debugbeg . "getgenre($genreno)<HR>\n");
  1102. $genres = $this->genres();
  1103. if (isset($genres[$genreno])) {
  1104. $genre = $genres[$genreno];
  1105. if ($this->debug) print($genre . "\n");
  1106. } else {
  1107. $genre = '';
  1108. }
  1109. if ($this->debug) print($this->debugend);
  1110. return $genre;
  1111. }
  1112. ////////////////////////////////////////////
  1113. function getGenreNo($genre, $default = 0xff) {
  1114. if ($this->debug) print($this->debugbeg . "getgenreno('$genre',$default)<HR>\n");
  1115. $genres = $this->genres();
  1116. $genreno = false;
  1117. if ($genre) {
  1118. foreach ($genres as $no => $name) {
  1119. if (strtolower($genre) == strtolower($name)) {
  1120. if ($this->debug) print("$no:'$name' == '$genre'");
  1121. $genreno = $no;
  1122. }
  1123. }
  1124. }
  1125. if ($genreno === false) $genreno = $default;
  1126. if ($this->debug) print($this->debugend);
  1127. return $genreno;
  1128. }
  1129. ////////////////////////////////////////////
  1130. function genres() {
  1131. return array(
  1132. 0 => 'Blues',
  1133. 1 => 'Classic Rock',
  1134. 2 => 'Country',
  1135. 3 => 'Dance',
  1136. 4 => 'Disco',
  1137. 5 => 'Funk',
  1138. 6 => 'Grunge',
  1139. 7 => 'Hip-Hop',
  1140. 8 => 'Jazz',
  1141. 9 => 'Metal',
  1142. 10 => 'New Age',
  1143. 11 => 'Oldies',
  1144. 12 => 'Other',
  1145. 13 => 'Pop',
  1146. 14 => 'R&B',
  1147. 15 => 'Rap',
  1148. 16 => 'Reggae',
  1149. 17 => 'Rock',
  1150. 18 => 'Techno',
  1151. 19 => 'Industrial',
  1152. 20 => 'Alternative',
  1153. 21 => 'Ska',
  1154. 22 => 'Death Metal',
  1155. 23 => 'Pranks',
  1156. 24 => 'Soundtrack',
  1157. 25 => 'Euro-Techno',
  1158. 26 => 'Ambient',
  1159. 27 => 'Trip-Hop',
  1160. 28 => 'Vocal',
  1161. 29 => 'Jazz+Funk',
  1162. 30 => 'Fusion',
  1163. 31 => 'Trance',
  1164. 32 => 'Classical',
  1165. 33 => 'Instrumental',
  1166. 34 => 'Acid',
  1167. 35 => 'House',
  1168. 36 => 'Game',
  1169. 37 => 'Sound Clip',
  1170. 38 => 'Gospel',
  1171. 39 => 'Noise',
  1172. 40 => 'Alternative Rock',
  1173. 41 => 'Bass',
  1174. 42 => 'Soul',
  1175. 43 => 'Punk',
  1176. 44 => 'Space',
  1177. 45 => 'Meditative',
  1178. 46 => 'Instrumental Pop',
  1179. 47 => 'Instrumental Rock',
  1180. 48 => 'Ethnic',
  1181. 49 => 'Gothic',
  1182. 50 => 'Darkwave',
  1183. 51 => 'Techno-Industrial',
  1184. 52 => 'Electronic',
  1185. 53 => 'Pop-Folk',
  1186. 54 => 'Eurodance',
  1187. 55 => 'Dream',
  1188. 56 => 'Southern Rock',
  1189. 57 => 'Comedy',
  1190. 58 => 'Cult',
  1191. 59 => 'Gangsta',
  1192. 60 => 'Top 40',
  1193. 61 => 'Christian Rap',
  1194. 62 => 'Pop/Funk',
  1195. 63 => 'Jungle',
  1196. 64 => 'Native US',
  1197. 65 => 'Cabaret',
  1198. 66 => 'New Wave',
  1199. 67 => 'Psychadelic',
  1200. 68 => 'Rave',
  1201. 69 => 'Showtunes',
  1202. 70 => 'Trailer',
  1203. 71 => 'Lo-Fi',
  1204. 72 => 'Tribal',
  1205. 73 => 'Acid Punk',
  1206. 74 => 'Acid Jazz',
  1207. 75 => 'Polka',
  1208. 76 => 'Retro',
  1209. 77 => 'Musical',
  1210. 78 => 'Rock & Roll',
  1211. 79 => 'Hard Rock',
  1212. 80 => 'Folk',
  1213. 81 => 'Folk-Rock',
  1214. 82 => 'National Folk',
  1215. 83 => 'Swing',
  1216. 84 => 'Fast Fusion',
  1217. 85 => 'Bebob',
  1218. 86 => 'Latin',
  1219. 87 => 'Revival',
  1220. 88 => 'Celtic',
  1221. 89 => 'Bluegrass',
  1222. 90 => 'Avantgarde',
  1223. 91 => 'Gothic Rock',
  1224. 92 => 'Progressive Rock',
  1225. 93 => 'Psychedelic Rock',
  1226. 94 => 'Symphonic Rock',
  1227. 95 => 'Slow Rock',
  1228. 96 => 'Big Band',
  1229. 97 => 'Chorus',
  1230. 98 => 'Easy Listening',
  1231. 99 => 'Acoustic',
  1232. 100 => 'Humour',
  1233. 101 => 'Speech',
  1234. 102 => 'Chanson',
  1235. 103 => 'Opera',
  1236. 104 => 'Chamber Music',
  1237. 105 => 'Sonata',
  1238. 106 => 'Symphony',
  1239. 107 => 'Booty Bass',
  1240. 108 => 'Primus',
  1241. 109 => 'Porn Groove',
  1242. 110 => 'Satire',
  1243. 111 => 'Slow Jam',
  1244. 112 => 'Club',
  1245. 113 => 'Tango',
  1246. 114 => 'Samba',
  1247. 115 => 'Folklore',
  1248. 116 => 'Ballad',
  1249. 117 => 'Power Ballad',
  1250. 118 => 'Rhytmic Soul',
  1251. 119 => 'Freestyle',
  1252. 120 => 'Duet',
  1253. 121 => 'Punk Rock',
  1254. 122 => 'Drum Solo',
  1255. 123 => 'Acapella',
  1256. 124 => 'Euro-House',
  1257. 125 => 'Dance Hall',
  1258. 126 => 'Goa',
  1259. 127 => 'Drum & Bass',
  1260. 128 => 'Club-House',
  1261. 129 => 'Hardcore',
  1262. 130 => 'Terror',
  1263. 131 => 'Indie',
  1264. 132 => 'BritPop',
  1265. 133 => 'Negerpunk',
  1266. 134 => 'Polsk Punk',
  1267. 135 => 'Beat',
  1268. 136 => 'Christian Gangsta Rap',
  1269. 137 => 'Heavy Metal',
  1270. 138 => 'Black Metal',
  1271. 139 => 'Crossover',
  1272. 140 => 'Contemporary Christian',
  1273. 141 => 'Christian Rock',
  1274. 142 => 'Merengue',
  1275. 143 => 'Salsa',
  1276. 144 => 'Trash Metal',
  1277. 145 => 'Anime',
  1278. 146 => 'Jpop',
  1279. 147 => 'Synthpop'
  1280. );
  1281. }
  1282. }
  1283. //id3 v2
  1284. class ID3{
  1285. var $file_name=''; //full path to the file
  1286. //the sugestion is that this path should be a
  1287. //relative path
  1288. var $tags; //array with ID3 tags extracted from the file
  1289. var $last_error_num=0; //keep the number of the last error ocurred
  1290. var $tags_count = 0; // the number of elements at the tags array
  1291. /*********************/
  1292. /**private functions**/
  1293. /*********************/
  1294. function hex2bin($data) {
  1295. //thankz for the one who wrote this function
  1296. //If iknew your name I would say it here
  1297. $len = strlen($data);
  1298. for($i=0;$i<$len;$i+=2) {
  1299. $newdata .= pack("C",hexdec(substr($data,$i,2)));
  1300. }
  1301. return $newdata;
  1302. }
  1303. function get_frame_size($fourBytes){
  1304. $tamanho[0] = str_pad(base_convert(substr($fourBytes,0,2),16,2),7,0,STR_PAD_LEFT);
  1305. $tamanho[1] = str_pad(base_convert(substr($fourBytes,2,2),16,2),7,0,STR_PAD_LEFT);
  1306. $tamanho[2] = str_pad(base_convert(substr($fourBytes,4,2),16,2),7,0,STR_PAD_LEFT);
  1307. $tamanho[3] = str_pad(base_convert(substr($fourBytes,6,2),16,2),7,0,STR_PAD_LEFT);
  1308. $total = $tamanho[0].$tamanho[1].$tamanho[2].$tamanho[3];
  1309. $tamanho[0] = substr($total,0,8);
  1310. $tamanho[1] = substr($total,8,8);
  1311. $tamanho[2] = substr($total,16,8);
  1312. $tamanho[3] = substr($total,24,8);
  1313. $total = $tamanho[0].$tamanho[1].$tamanho[2].$tamanho[3];
  1314. $total = base_convert($total,2,10);
  1315. return $total;
  1316. }
  1317. function extractTags($text,&$tags){
  1318. $size = -1;//inicializando diferente de zero para nгo sair do while
  1319. while ((strlen($text) != 0) and ($size != 0)){
  1320. //while there are tags to read and they have a meaning
  1321. //while existem tags a serem tratadas e essas tags tem conteudo
  1322. $ID = substr($text,0,4);
  1323. $aux = substr($text,4,4);
  1324. $aux = bin2hex($aux);
  1325. $size = $this->get_frame_size($aux);
  1326. $flags = substr($text,8,2);
  1327. $info = substr($text,11,$size-1);
  1328. if ($size != 0){
  1329. $tags[$ID] = $info;
  1330. $this->tags_count++;
  1331. }
  1332. $text = substr($text,10+$size,strlen($text));
  1333. }
  1334. }
  1335. /********************/
  1336. /**public functions**/
  1337. /********************/
  1338. /**Constructor**/
  1339. function ID3($file_name){
  1340. $this->file_name = $file_name;
  1341. $this->last_error_num = 0;
  1342. }
  1343. /**Read the file and put the TAGS
  1344. content on $this->tags array**/
  1345. function getInfo(){
  1346. if ($this->file_name != ''){
  1347. $mp3 = @fopen($this->file_name,"r");
  1348. $header = @fread($mp3,10);
  1349. if (!$header) {
  1350. $this->last_error_num = 2;
  1351. return false;
  1352. die();
  1353. }
  1354. if (substr($header,0,3) != "ID3"){
  1355. $this->last_error_num = 3;
  1356. return false;
  1357. die();
  1358. }
  1359. $header = bin2hex($header);
  1360. $version = base_convert(substr($header,6,2),16,10).".".base_convert(substr($header,8,2),16,10);
  1361. $flags = base_convert(substr($header,10,2),16,2);
  1362. $flags = str_pad($flags,8,0,STR_PAD_LEFT);
  1363. if ($flags[7] == 1){
  1364. //echo('with Unsynchronisation<br>');
  1365. }
  1366. if ($flags[6] == 1){
  1367. //echo('with Extended header<br>');
  1368. }
  1369. if ($flags[5] == 1){//Esperimental tag
  1370. $this->last_error_num = 4;
  1371. return false;
  1372. die();
  1373. }
  1374. $total = $this->get_frame_size(substr($header,12,8));
  1375. $text = @fread($mp3,$total);
  1376. fclose($mp3);
  1377. $this->extractTags($text,$this->tags);
  1378. }
  1379. else{
  1380. $this->last_error_num = 1;//file not set
  1381. return false;
  1382. die();
  1383. }
  1384. return true;
  1385. }
  1386. /*************
  1387. * PUBLIC
  1388. * Functions to get information
  1389. * from the ID3 tag
  1390. **************/
  1391. function getArtist(){
  1392. if (array_key_exists('TPE1',$this->tags)){
  1393. return $this->tags['TPE1'];
  1394. }else{
  1395. $this->last_error_num = 5;
  1396. return false;
  1397. }
  1398. }
  1399. function getTrack(){
  1400. if (array_key_exists('TRCK',$this->tags)){
  1401. return $this->tags['TRCK'];
  1402. }else{
  1403. $this->last_error_num = 5;
  1404. return false;
  1405. }
  1406. }
  1407. function getTitle(){
  1408. if (array_key_exists('TIT2',$this->tags)){
  1409. return $this->tags['TIT2'];
  1410. }else{
  1411. $this->last_error_num = 5;
  1412. return false;
  1413. }
  1414. }
  1415. function getAlbum(){
  1416. if (array_key_exists('TALB',$this->tags)){
  1417. return $this->tags['TALB'];
  1418. }else{
  1419. $this->last_error_num = 5;
  1420. return false;
  1421. }
  1422. }
  1423. function getYear(){
  1424. if (array_key_exists('TYER',$this->tags)){
  1425. return $this->tags['TYER'];
  1426. }else{
  1427. $this->last_error_num = 5;
  1428. return false;
  1429. }
  1430. }
  1431. function getGender(){
  1432. if (array_key_exists('TCON',$this->tags)){
  1433. return $this->tags['TCON'];
  1434. }else{
  1435. $this->last_error_num = 5;
  1436. return false;
  1437. }
  1438. }
  1439. }
  1440. //SCANNING FOLDER FOR MP3 FILES
  1441. $file_dir = $_GET['file_dir'];
  1442. function filearray($start) {
  1443. global $exclude_files;
  1444. $dir=opendir($start);
  1445. while (false !== ($found=readdir($dir))) { $getit[]=$found;
  1446. }
  1447. foreach($getit as $num => $item) {
  1448. if (is_dir($start.$item) && $item!="." && $item!=".." && array_search($item, $exclude_files)===false) { $output["{$item}"]=filearray($start.$item."/"); }
  1449. if (is_file($start.$item) && array_search($item, $exclude_files)===false) { $output["{$item}"]=$start.$item; }
  1450. }
  1451. closedir($dir);
  1452. ksort($output);
  1453. return $output;
  1454. }
  1455. $ff = filearray($file_dir."/");
  1456. function printXML($arr) {
  1457. foreach($arr as $key => $val) {
  1458. if(is_array($val)) {
  1459. $folder_title=substr($key, $omit_folder_chars);
  1460. ksort($val);
  1461. printXML($val);
  1462. }else {
  1463. $file = $val;
  1464. if(substr($file, -3) == 'mp3' || (substr($file, -3) == 'MP3')) {
  1465. $file_title=substr($file,0,strlen($file)-4);
  1466. // ID3v1 and ID3v2 tags parser
  1467. $nome_arq = $file;
  1468. $myId3 = new ID3($nome_arq);
  1469. if ($myId3->getInfo())
  1470. {
  1471. $f_title=$myId3->getTitle();
  1472. $f_artist=$myId3->getArtist();
  1473. }
  1474. if(!($myId3->getArtist()))
  1475. {
  1476. $id3 = new MP3_Id();
  1477. $result = $id3->read($file);
  1478. $f_title=$id3->getTag('name');
  1479. $f_artist=$id3->getTag('artists');
  1480. }
  1481. if ( $f_artist == '0' && $f_title == '0' )
  1482. {
  1483. $arr_names = explode('/',strrev($nome_arq));
  1484. $substr = substr($arr_names[0],4,strlen($arr_names[0]));
  1485. $arr_names_last = explode('_',strrev($substr));
  1486. $f_artist = '';
  1487. $f_title = strrev($substr);
  1488. }
  1489. if($f_artist == '0'){
  1490. $f_artist='';
  1491. }
  1492. $f_id=str_replace("/","",$file_title);
  1493. $f_id=str_replace(".","",$f_id);
  1494. $f_id=str_replace(">","",$f_id);
  1495. $f_id=str_replace("<","",$f_id);
  1496. $f_id=str_replace("=","",$f_id);
  1497. $f_id=str_replace("(","",$f_id);
  1498. $f_id=str_replace(")","",$f_id);
  1499. $f_id=str_replace("\"","",$f_id);
  1500. if ($sEncoding = mb_detect_encoding($f_title, 'au