module.audio.mod.php 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  1. <?php
  2. /////////////////////////////////////////////////////////////////
  3. /// getID3() by James Heinrich <info@getid3.org> //
  4. // available at http://getid3.sourceforge.net //
  5. // or http://www.getid3.org //
  6. // also https://github.com/JamesHeinrich/getID3 //
  7. /////////////////////////////////////////////////////////////////
  8. // See readme.txt for more details //
  9. /////////////////////////////////////////////////////////////////
  10. // //
  11. // module.audio.mod.php //
  12. // module for analyzing MOD Audio files //
  13. // dependencies: NONE //
  14. // ///
  15. /////////////////////////////////////////////////////////////////
  16. class getid3_mod extends getid3_handler
  17. {
  18. public function Analyze() {
  19. $info = &$this->getid3->info;
  20. $this->fseek($info['avdataoffset']);
  21. $fileheader = $this->fread(1088);
  22. if (preg_match('#^IMPM#', $fileheader)) {
  23. return $this->getITheaderFilepointer();
  24. } elseif (preg_match('#^Extended Module#', $fileheader)) {
  25. return $this->getXMheaderFilepointer();
  26. } elseif (preg_match('#^.{44}SCRM#', $fileheader)) {
  27. return $this->getS3MheaderFilepointer();
  28. } elseif (preg_match('#^.{1080}(M\\.K\\.|M!K!|FLT4|FLT8|[5-9]CHN|[1-3][0-9]CH)#', $fileheader)) {
  29. return $this->getMODheaderFilepointer();
  30. }
  31. $info['error'][] = 'This is not a known type of MOD file';
  32. return false;
  33. }
  34. public function getMODheaderFilepointer() {
  35. $info = &$this->getid3->info;
  36. $this->fseek($info['avdataoffset'] + 1080);
  37. $FormatID = $this->fread(4);
  38. if (!preg_match('#^(M.K.|[5-9]CHN|[1-3][0-9]CH)$#', $FormatID)) {
  39. $info['error'][] = 'This is not a known type of MOD file';
  40. return false;
  41. }
  42. $info['fileformat'] = 'mod';
  43. $info['error'][] = 'MOD parsing not enabled in this version of getID3() ['.$this->getid3->version().']';
  44. return false;
  45. }
  46. public function getXMheaderFilepointer() {
  47. $info = &$this->getid3->info;
  48. $this->fseek($info['avdataoffset']);
  49. $FormatID = $this->fread(15);
  50. if (!preg_match('#^Extended Module$#', $FormatID)) {
  51. $info['error'][] = 'This is not a known type of XM-MOD file';
  52. return false;
  53. }
  54. $info['fileformat'] = 'xm';
  55. $info['error'][] = 'XM-MOD parsing not enabled in this version of getID3() ['.$this->getid3->version().']';
  56. return false;
  57. }
  58. public function getS3MheaderFilepointer() {
  59. $info = &$this->getid3->info;
  60. $this->fseek($info['avdataoffset'] + 44);
  61. $FormatID = $this->fread(4);
  62. if (!preg_match('#^SCRM$#', $FormatID)) {
  63. $info['error'][] = 'This is not a ScreamTracker MOD file';
  64. return false;
  65. }
  66. $info['fileformat'] = 's3m';
  67. $info['error'][] = 'ScreamTracker parsing not enabled in this version of getID3() ['.$this->getid3->version().']';
  68. return false;
  69. }
  70. public function getITheaderFilepointer() {
  71. $info = &$this->getid3->info;
  72. $this->fseek($info['avdataoffset']);
  73. $FormatID = $this->fread(4);
  74. if (!preg_match('#^IMPM$#', $FormatID)) {
  75. $info['error'][] = 'This is not an ImpulseTracker MOD file';
  76. return false;
  77. }
  78. $info['fileformat'] = 'it';
  79. $info['error'][] = 'ImpulseTracker parsing not enabled in this version of getID3() ['.$this->getid3->version().']';
  80. return false;
  81. }
  82. }