module.audio.aa.php 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. <?php
  2. /////////////////////////////////////////////////////////////////
  3. /// getID3() by James Heinrich <info@getid3.org> //
  4. // available at https://github.com/JamesHeinrich/getID3 //
  5. // or https://www.getid3.org //
  6. // or http://getid3.sourceforge.net //
  7. // see readme.txt for more details //
  8. /////////////////////////////////////////////////////////////////
  9. // //
  10. // module.audio.aa.php //
  11. // module for analyzing Audible Audiobook files //
  12. // dependencies: NONE //
  13. // ///
  14. /////////////////////////////////////////////////////////////////
  15. if (!defined('GETID3_INCLUDEPATH')) { // prevent path-exposing attacks that access modules directly on public webservers
  16. exit;
  17. }
  18. class getid3_aa extends getid3_handler
  19. {
  20. /**
  21. * @return bool
  22. */
  23. public function Analyze() {
  24. $info = &$this->getid3->info;
  25. $this->fseek($info['avdataoffset']);
  26. $AAheader = $this->fread(8);
  27. $magic = "\x57\x90\x75\x36";
  28. if (substr($AAheader, 4, 4) != $magic) {
  29. $this->error('Expecting "'.getid3_lib::PrintHexBytes($magic).'" at offset '.$info['avdataoffset'].', found "'.getid3_lib::PrintHexBytes(substr($AAheader, 4, 4)).'"');
  30. return false;
  31. }
  32. // shortcut
  33. $info['aa'] = array();
  34. $thisfile_aa = &$info['aa'];
  35. $info['fileformat'] = 'aa';
  36. $info['audio']['dataformat'] = 'aa';
  37. $this->error('Audible Audiobook (.aa) parsing not enabled in this version of getID3() ['.$this->getid3->version().']');
  38. return false;
  39. $info['audio']['bitrate_mode'] = 'cbr'; // is it?
  40. $thisfile_aa['encoding'] = 'ISO-8859-1';
  41. $thisfile_aa['filesize'] = getid3_lib::BigEndian2Int(substr($AAheader, 0, 4));
  42. if ($thisfile_aa['filesize'] > ($info['avdataend'] - $info['avdataoffset'])) {
  43. $this->warning('Possible truncated file - expecting "'.$thisfile_aa['filesize'].'" bytes of data, only found '.($info['avdataend'] - $info['avdataoffset']).' bytes"');
  44. }
  45. $info['audio']['bits_per_sample'] = 16; // is it?
  46. $info['audio']['sample_rate'] = $thisfile_aa['sample_rate'];
  47. $info['audio']['channels'] = $thisfile_aa['channels'];
  48. //$info['playtime_seconds'] = 0;
  49. //$info['audio']['bitrate'] = 0;
  50. return true;
  51. }
  52. }