PageRenderTime 48ms CodeModel.GetById 21ms RepoModel.GetById 0ms app.codeStats 0ms

/common/libraries/plugin/getid3/demos/demo.audioinfo.class.php

https://bitbucket.org/chamilo/chamilo-dev/
PHP | 300 lines | 124 code | 59 blank | 117 comment | 15 complexity | 17380d9b174468f09844818997c734fa MD5 | raw file
Possible License(s): GPL-2.0, BSD-3-Clause, LGPL-2.1, LGPL-3.0, GPL-3.0, MIT
  1. <?php
  2. // +----------------------------------------------------------------------+
  3. // | PHP version 4.1.0 |
  4. // +----------------------------------------------------------------------+
  5. // | Placed in public domain by Allan Hansen, 2002. Share and enjoy! |
  6. // +----------------------------------------------------------------------+
  7. // | /demo/demo.audioinfo.class.php |
  8. // | |
  9. // | Example wrapper class to extract information from audio files |
  10. // | through getID3(). |
  11. // | |
  12. // | getID3() returns a lot of information. Much of this information is |
  13. // | not needed for the end-application. It is also possible that some |
  14. // | users want to extract specific info. Modifying getID3() files is a |
  15. // | bad idea, as modifications needs to be done to future versions of |
  16. // | getID3(). |
  17. // | |
  18. // | Modify this wrapper class instead. This example extracts certain |
  19. // | fields only and adds a new root value - encoder_options if possible. |
  20. // | It also checks for mp3 files with wave headers. |
  21. // +----------------------------------------------------------------------+
  22. // | Example code: |
  23. // | $au = new AudioInfo(); |
  24. // | print_r($au->Info('file.flac'); |
  25. // +----------------------------------------------------------------------+
  26. // | Authors: Allan Hansen <ah???artemis*dk> |
  27. // +----------------------------------------------------------------------+
  28. //
  29. /**
  30. * getID3() settings
  31. */
  32. // Updated By systho in order to make the file
  33. //require_once('../getid3/getid3.php');
  34. require_once (dirname(__FILE__) . '/../getid3.php');
  35. /**
  36. * Class for extracting information from audio files with getID3().
  37. */
  38. class AudioInfo
  39. {
  40. /**
  41. * Private variables
  42. */
  43. var $result = NULL;
  44. var $info = NULL;
  45. /**
  46. * Constructor
  47. */
  48. function __construct()
  49. {
  50. // Initialize getID3 engine
  51. $this->getID3 = new getID3();
  52. $this->getID3->option_md5_data = true;
  53. $this->getID3->option_md5_data_source = true;
  54. $this->getID3->encoding = 'UTF-8';
  55. }
  56. /**
  57. * Extract information - only public function
  58. *
  59. * @access public
  60. * @param string file Audio file to extract info from.
  61. */
  62. function Info($file)
  63. {
  64. // Analyze file
  65. $this->info = $this->getID3->analyze($file);
  66. // Exit here on error
  67. if (isset($this->info['error']))
  68. {
  69. return array('error' => $this->info['error']);
  70. }
  71. // Init wrapper object
  72. $this->result = array();
  73. $this->result['format_name'] = @$this->info['fileformat'] . '/' . @$this->info['audio']['dataformat'] . (isset($this->info['video']['dataformat']) ? '/' . @$this->info['video']['dataformat'] : '');
  74. $this->result['encoder_version'] = @$this->info['audio']['encoder'];
  75. $this->result['encoder_options'] = @$this->info['audio']['encoder_options'];
  76. $this->result['bitrate_mode'] = @$this->info['audio']['bitrate_mode'];
  77. $this->result['channels'] = @$this->info['audio']['channels'];
  78. $this->result['sample_rate'] = @$this->info['audio']['sample_rate'];
  79. $this->result['bits_per_sample'] = @$this->info['audio']['bits_per_sample'];
  80. $this->result['playing_time'] = @$this->info['playtime_seconds'];
  81. $this->result['avg_bit_rate'] = @$this->info['audio']['bitrate'];
  82. $this->result['tags'] = @$this->info['tags'];
  83. $this->result['comments'] = @$this->info['comments'];
  84. $this->result['warning'] = @$this->info['warning'];
  85. $this->result['md5'] = @$this->info['md5_data'];
  86. // Post getID3() data handling based on file format
  87. $method = @$this->info['fileformat'] . 'Info';
  88. if (@$this->info['fileformat'] && method_exists($this, $method))
  89. {
  90. $this->$method();
  91. }
  92. return $this->result;
  93. }
  94. /**
  95. * post-getID3() data handling for AAC files.
  96. *
  97. * @access private
  98. */
  99. function aacInfo()
  100. {
  101. $this->result['format_name'] = 'AAC';
  102. }
  103. /**
  104. * post-getID3() data handling for Wave files.
  105. *
  106. * @access private
  107. */
  108. function riffInfo()
  109. {
  110. if ($this->info['audio']['dataformat'] == 'wav')
  111. {
  112. $this->result['format_name'] = 'Wave';
  113. }
  114. else
  115. if (ereg('^mp[1-3]$', $this->info['audio']['dataformat']))
  116. {
  117. $this->result['format_name'] = strtoupper($this->info['audio']['dataformat']);
  118. }
  119. else
  120. {
  121. $this->result['format_name'] = 'riff/' . $this->info['audio']['dataformat'];
  122. }
  123. }
  124. /**
  125. * * post-getID3() data handling for FLAC files.
  126. *
  127. * @access private
  128. */
  129. function flacInfo()
  130. {
  131. $this->result['format_name'] = 'FLAC';
  132. }
  133. /**
  134. * post-getID3() data handling for Monkey's Audio files.
  135. *
  136. * @access private
  137. */
  138. function macInfo()
  139. {
  140. $this->result['format_name'] = 'Monkey\'s Audio';
  141. }
  142. /**
  143. * post-getID3() data handling for Lossless Audio files.
  144. *
  145. * @access private
  146. */
  147. function laInfo()
  148. {
  149. $this->result['format_name'] = 'La';
  150. }
  151. /**
  152. * post-getID3() data handling for Ogg Vorbis files.
  153. *
  154. * @access private
  155. */
  156. function oggInfo()
  157. {
  158. if ($this->info['audio']['dataformat'] == 'vorbis')
  159. {
  160. $this->result['format_name'] = 'Ogg Vorbis';
  161. }
  162. else
  163. if ($this->info['audio']['dataformat'] == 'flac')
  164. {
  165. $this->result['format_name'] = 'Ogg FLAC';
  166. }
  167. else
  168. if ($this->info['audio']['dataformat'] == 'speex')
  169. {
  170. $this->result['format_name'] = 'Ogg Speex';
  171. }
  172. else
  173. {
  174. $this->result['format_name'] = 'Ogg ' . $this->info['audio']['dataformat'];
  175. }
  176. }
  177. /**
  178. * post-getID3() data handling for Musepack files.
  179. *
  180. * @access private
  181. */
  182. function mpcInfo()
  183. {
  184. $this->result['format_name'] = 'Musepack';
  185. }
  186. /**
  187. * post-getID3() data handling for MPEG files.
  188. *
  189. * @access private
  190. */
  191. function mp3Info()
  192. {
  193. $this->result['format_name'] = 'MP3';
  194. }
  195. /**
  196. * post-getID3() data handling for MPEG files.
  197. *
  198. * @access private
  199. */
  200. function mp2Info()
  201. {
  202. $this->result['format_name'] = 'MP2';
  203. }
  204. /**
  205. * post-getID3() data handling for MPEG files.
  206. *
  207. * @access private
  208. */
  209. function mp1Info()
  210. {
  211. $this->result['format_name'] = 'MP1';
  212. }
  213. /**
  214. * post-getID3() data handling for WMA files.
  215. *
  216. * @access private
  217. */
  218. function asfInfo()
  219. {
  220. $this->result['format_name'] = strtoupper($this->info['audio']['dataformat']);
  221. }
  222. /**
  223. * post-getID3() data handling for Real files.
  224. *
  225. * @access private
  226. */
  227. function realInfo()
  228. {
  229. $this->result['format_name'] = 'Real';
  230. }
  231. /**
  232. * post-getID3() data handling for VQF files.
  233. *
  234. * @access private
  235. */
  236. function vqfInfo()
  237. {
  238. $this->result['format_name'] = 'VQF';
  239. }
  240. }
  241. ?>