PageRenderTime 65ms CodeModel.GetById 28ms RepoModel.GetById 0ms app.codeStats 0ms

/includes/getid3/getid3.php

https://bitbucket.org/gregwiley/sermon-manager-for-wordpress
PHP | 1754 lines | 1273 code | 245 blank | 236 comment | 229 complexity | 78ce1a8e6243b7e73b07a57c8d22e0a9 MD5 | raw file

Large files files are truncated, but you can click here to view the full file

  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. /////////////////////////////////////////////////////////////////
  7. // //
  8. // Please see readme.txt for more information //
  9. // ///
  10. /////////////////////////////////////////////////////////////////
  11. // attempt to define temp dir as something flexible but reliable
  12. $temp_dir = ini_get('upload_tmp_dir');
  13. if ($temp_dir && (!is_dir($temp_dir) || !is_readable($temp_dir))) {
  14. $temp_dir = '';
  15. }
  16. if (!$temp_dir && function_exists('sys_get_temp_dir')) {
  17. // PHP v5.2.1+
  18. // sys_get_temp_dir() may give inaccessible temp dir, e.g. with open_basedir on virtual hosts
  19. $temp_dir = sys_get_temp_dir();
  20. }
  21. $temp_dir = realpath($temp_dir);
  22. $open_basedir = ini_get('open_basedir');
  23. if ($open_basedir) {
  24. // e.g. "/var/www/vhosts/getid3.org/httpdocs/:/tmp/"
  25. $temp_dir = str_replace(array('/', '\\'), DIRECTORY_SEPARATOR, $temp_dir);
  26. $open_basedir = str_replace(array('/', '\\'), DIRECTORY_SEPARATOR, $open_basedir);
  27. if (substr($temp_dir, -1, 1) != DIRECTORY_SEPARATOR) {
  28. $temp_dir .= DIRECTORY_SEPARATOR;
  29. }
  30. $found_valid_tempdir = false;
  31. $open_basedirs = explode(':', $open_basedir);
  32. foreach ($open_basedirs as $basedir) {
  33. if (substr($basedir, -1, 1) != DIRECTORY_SEPARATOR) {
  34. $basedir .= DIRECTORY_SEPARATOR;
  35. }
  36. if (preg_match('#^'.preg_quote($basedir).'#', $temp_dir)) {
  37. $found_valid_tempdir = true;
  38. break;
  39. }
  40. }
  41. if (!$found_valid_tempdir) {
  42. $temp_dir = '';
  43. }
  44. unset($open_basedirs, $found_valid_tempdir, $basedir);
  45. }
  46. if (!$temp_dir) {
  47. $temp_dir = '*'; // invalid directory name should force tempnam() to use system default temp dir
  48. }
  49. // $temp_dir = '/something/else/'; // feel free to override temp dir here if it works better for your system
  50. define('GETID3_TEMP_DIR', $temp_dir);
  51. unset($open_basedir, $temp_dir);
  52. // define a constant rather than looking up every time it is needed
  53. if (!defined('GETID3_OS_ISWINDOWS')) {
  54. if (strtoupper(substr(PHP_OS, 0, 3)) == 'WIN') {
  55. define('GETID3_OS_ISWINDOWS', true);
  56. } else {
  57. define('GETID3_OS_ISWINDOWS', false);
  58. }
  59. }
  60. // Get base path of getID3() - ONCE
  61. if (!defined('GETID3_INCLUDEPATH')) {
  62. foreach (get_included_files() as $key => $val) {
  63. if (basename($val) == 'getid3.php') {
  64. define('GETID3_INCLUDEPATH', dirname($val).DIRECTORY_SEPARATOR);
  65. break;
  66. }
  67. }
  68. }
  69. // End: Defines
  70. class getID3
  71. {
  72. // public: Settings
  73. public $encoding = 'UTF-8'; // CASE SENSITIVE! - i.e. (must be supported by iconv()). Examples: ISO-8859-1 UTF-8 UTF-16 UTF-16BE
  74. public $encoding_id3v1 = 'ISO-8859-1'; // Should always be 'ISO-8859-1', but some tags may be written in other encodings such as 'EUC-CN' or 'CP1252'
  75. // public: Optional tag checks - disable for speed.
  76. public $option_tag_id3v1 = true; // Read and process ID3v1 tags
  77. public $option_tag_id3v2 = true; // Read and process ID3v2 tags
  78. public $option_tag_lyrics3 = true; // Read and process Lyrics3 tags
  79. public $option_tag_apetag = true; // Read and process APE tags
  80. public $option_tags_process = true; // Copy tags to root key 'tags' and encode to $this->encoding
  81. public $option_tags_html = true; // Copy tags to root key 'tags_html' properly translated from various encodings to HTML entities
  82. // public: Optional tag/comment calucations
  83. public $option_extra_info = true; // Calculate additional info such as bitrate, channelmode etc
  84. // public: Optional handling of embedded attachments (e.g. images)
  85. public $option_save_attachments = true; // defaults to true (ATTACHMENTS_INLINE) for backward compatibility
  86. // public: Optional calculations
  87. public $option_md5_data = false; // Get MD5 sum of data part - slow
  88. public $option_md5_data_source = false; // Use MD5 of source file if availble - only FLAC and OptimFROG
  89. public $option_sha1_data = false; // Get SHA1 sum of data part - slow
  90. public $option_max_2gb_check = null; // Check whether file is larger than 2GB and thus not supported by 32-bit PHP (null: auto-detect based on PHP_INT_MAX)
  91. // public: Read buffer size in bytes
  92. public $option_fread_buffer_size = 32768;
  93. // Public variables
  94. public $filename; // Filename of file being analysed.
  95. public $fp; // Filepointer to file being analysed.
  96. public $info; // Result array.
  97. // Protected variables
  98. protected $startup_error = '';
  99. protected $startup_warning = '';
  100. protected $memory_limit = 0;
  101. const VERSION = '1.9.3-20111213';
  102. const FREAD_BUFFER_SIZE = 32768;
  103. var $tempdir = GETID3_TEMP_DIR;
  104. const ATTACHMENTS_NONE = false;
  105. const ATTACHMENTS_INLINE = true;
  106. // public: constructor
  107. public function __construct() {
  108. // Check for PHP version
  109. $required_php_version = '5.0.5';
  110. if (version_compare(PHP_VERSION, $required_php_version, '<')) {
  111. $this->startup_error .= 'getID3() requires PHP v'.$required_php_version.' or higher - you are running v'.PHP_VERSION;
  112. return false;
  113. }
  114. // Check memory
  115. $this->memory_limit = ini_get('memory_limit');
  116. if (preg_match('#([0-9]+)M#i', $this->memory_limit, $matches)) {
  117. // could be stored as "16M" rather than 16777216 for example
  118. $this->memory_limit = $matches[1] * 1048576;
  119. } elseif (preg_match('#([0-9]+)G#i', $this->memory_limit, $matches)) { // The 'G' modifier is available since PHP 5.1.0
  120. // could be stored as "2G" rather than 2147483648 for example
  121. $this->memory_limit = $matches[1] * 1073741824;
  122. }
  123. if ($this->memory_limit <= 0) {
  124. // memory limits probably disabled
  125. } elseif ($this->memory_limit <= 4194304) {
  126. $this->startup_error .= 'PHP has less than 4MB available memory and will very likely run out. Increase memory_limit in php.ini';
  127. } elseif ($this->memory_limit <= 12582912) {
  128. $this->startup_warning .= 'PHP has less than 12MB available memory and might run out if all modules are loaded. Increase memory_limit in php.ini';
  129. }
  130. // Check safe_mode off
  131. if (preg_match('#(1|ON)#i', ini_get('safe_mode'))) {
  132. $this->warning('WARNING: Safe mode is on, shorten support disabled, md5data/sha1data for ogg vorbis disabled, ogg vorbos/flac tag writing disabled.');
  133. }
  134. if (intval(ini_get('mbstring.func_overload')) > 0) {
  135. $this->warning('WARNING: php.ini contains "mbstring.func_overload = '.ini_get('mbstring.func_overload').'", this may break things.');
  136. }
  137. // Check for magic_quotes_runtime
  138. if (function_exists('get_magic_quotes_runtime')) {
  139. if (get_magic_quotes_runtime()) {
  140. return $this->startup_error('magic_quotes_runtime must be disabled before running getID3(). Surround getid3 block by set_magic_quotes_runtime(0) and set_magic_quotes_runtime(1).');
  141. }
  142. }
  143. // Check for magic_quotes_gpc
  144. if (function_exists('magic_quotes_gpc')) {
  145. if (get_magic_quotes_gpc()) {
  146. return $this->startup_error('magic_quotes_gpc must be disabled before running getID3(). Surround getid3 block by set_magic_quotes_gpc(0) and set_magic_quotes_gpc(1).');
  147. }
  148. }
  149. // Load support library
  150. if (!include_once(GETID3_INCLUDEPATH.'getid3.lib.php')) {
  151. $this->startup_error .= 'getid3.lib.php is missing or corrupt';
  152. }
  153. if ($this->option_max_2gb_check === null) {
  154. $this->option_max_2gb_check = (PHP_INT_MAX <= 2147483647);
  155. }
  156. // Needed for Windows only:
  157. // Define locations of helper applications for Shorten, VorbisComment, MetaFLAC
  158. // as well as other helper functions such as head, tail, md5sum, etc
  159. // This path cannot contain spaces, but the below code will attempt to get the
  160. // 8.3-equivalent path automatically
  161. // IMPORTANT: This path must include the trailing slash
  162. if (GETID3_OS_ISWINDOWS && !defined('GETID3_HELPERAPPSDIR')) {
  163. $helperappsdir = GETID3_INCLUDEPATH.'..'.DIRECTORY_SEPARATOR.'helperapps'; // must not have any space in this path
  164. if (!is_dir($helperappsdir)) {
  165. $this->startup_warning .= '"'.$helperappsdir.'" cannot be defined as GETID3_HELPERAPPSDIR because it does not exist';
  166. } elseif (strpos(realpath($helperappsdir), ' ') !== false) {
  167. $DirPieces = explode(DIRECTORY_SEPARATOR, realpath($helperappsdir));
  168. $path_so_far = array();
  169. foreach ($DirPieces as $key => $value) {
  170. if (strpos($value, ' ') !== false) {
  171. if (!empty($path_so_far)) {
  172. $commandline = 'dir /x '.escapeshellarg(implode(DIRECTORY_SEPARATOR, $path_so_far));
  173. $dir_listing = `$commandline`;
  174. $lines = explode("\n", $dir_listing);
  175. foreach ($lines as $line) {
  176. $line = trim($line);
  177. if (preg_match('#^([0-9/]{10}) +([0-9:]{4,5}( [AP]M)?) +(<DIR>|[0-9,]+) +([^ ]{0,11}) +(.+)$#', $line, $matches)) {
  178. list($dummy, $date, $time, $ampm, $filesize, $shortname, $filename) = $matches;
  179. if ((strtoupper($filesize) == '<DIR>') && (strtolower($filename) == strtolower($value))) {
  180. $value = $shortname;
  181. }
  182. }
  183. }
  184. } else {
  185. $this->startup_warning .= 'GETID3_HELPERAPPSDIR must not have any spaces in it - use 8dot3 naming convention if neccesary. You can run "dir /x" from the commandline to see the correct 8.3-style names.';
  186. }
  187. }
  188. $path_so_far[] = $value;
  189. }
  190. $helperappsdir = implode(DIRECTORY_SEPARATOR, $path_so_far);
  191. }
  192. define('GETID3_HELPERAPPSDIR', $helperappsdir.DIRECTORY_SEPARATOR);
  193. }
  194. return true;
  195. }
  196. public function version() {
  197. return self::VERSION;
  198. }
  199. public function fread_buffer_size() {
  200. return $this->option_fread_buffer_size;
  201. }
  202. // public: setOption
  203. function setOption($optArray) {
  204. if (!is_array($optArray) || empty($optArray)) {
  205. return false;
  206. }
  207. foreach ($optArray as $opt => $val) {
  208. if (isset($this->$opt) === false) {
  209. continue;
  210. }
  211. $this->$opt = $val;
  212. }
  213. return true;
  214. }
  215. public function openfile($filename, $filesize=false) {
  216. try {
  217. if (!empty($this->startup_error)) {
  218. throw new getid3_exception($this->startup_error);
  219. }
  220. if (!empty($this->startup_warning)) {
  221. $this->warning($this->startup_warning);
  222. }
  223. // init result array and set parameters
  224. $this->filename = $filename;
  225. $this->info = array();
  226. $this->info['GETID3_VERSION'] = $this->version();
  227. $this->info['php_memory_limit'] = $this->memory_limit;
  228. // remote files not supported
  229. if (preg_match('/^(ht|f)tp:\/\//', $filename)) {
  230. throw new getid3_exception('Remote files are not supported - please copy the file locally first');
  231. }
  232. $filename = str_replace('/', DIRECTORY_SEPARATOR, $filename);
  233. $filename = preg_replace('#(.+)'.preg_quote(DIRECTORY_SEPARATOR).'{2,}#U', '\1'.DIRECTORY_SEPARATOR, $filename);
  234. // open local file
  235. if (is_readable($filename) && is_file($filename) && ($this->fp = fopen($filename, 'rb'))) {
  236. // great
  237. } else {
  238. throw new getid3_exception('Could not open "'.$filename.'" (does not exist, or is not a file)');
  239. }
  240. if( $filesize )
  241. $this->info['filesize'] = $filesize;
  242. else
  243. $this->info['filesize'] = filesize($filename);
  244. // set redundant parameters - might be needed in some include file
  245. $this->info['filename'] = basename($filename);
  246. $this->info['filepath'] = str_replace('\\', '/', realpath(dirname($filename)));
  247. $this->info['filenamepath'] = $this->info['filepath'].'/'.$this->info['filename'];
  248. // option_max_2gb_check
  249. if ($this->option_max_2gb_check) {
  250. // PHP (32-bit all, and 64-bit Windows) doesn't support integers larger than 2^31 (~2GB)
  251. // filesize() simply returns (filesize % (pow(2, 32)), no matter the actual filesize
  252. // ftell() returns 0 if seeking to the end is beyond the range of unsigned integer
  253. $fseek = fseek($this->fp, 0, SEEK_END);
  254. if (($fseek < 0) || (($this->info['filesize'] != 0) && (ftell($this->fp) == 0)) ||
  255. ($this->info['filesize'] < 0) ||
  256. (ftell($this->fp) < 0)) {
  257. $real_filesize = false;
  258. if (GETID3_OS_ISWINDOWS) {
  259. $commandline = 'dir /-C "'.str_replace('/', DIRECTORY_SEPARATOR, $filename).'"';
  260. $dir_output = `$commandline`;
  261. if (preg_match('#1 File\(s\)[ ]+([0-9]+) bytes#i', $dir_output, $matches)) {
  262. $real_filesize = (float) $matches[1];
  263. }
  264. } else {
  265. $commandline = 'ls -o -g -G --time-style=long-iso '.escapeshellarg($filename);
  266. $dir_output = `$commandline`;
  267. if (preg_match('#([0-9]+) ([0-9]{4}-[0-9]{2}\-[0-9]{2} [0-9]{2}:[0-9]{2}) '.str_replace('#', '\\#', preg_quote($filename)).'$#', $dir_output, $matches)) {
  268. $real_filesize = (float) $matches[1];
  269. }
  270. }
  271. if ($real_filesize === false) {
  272. unset($this->info['filesize']);
  273. fclose($this->fp);
  274. throw new getid3_exception('Unable to determine actual filesize. File is most likely larger than '.round(PHP_INT_MAX / 1073741824).'GB and is not supported by PHP.');
  275. } elseif (getid3_lib::intValueSupported($real_filesize)) {
  276. unset($this->info['filesize']);
  277. fclose($this->fp);
  278. throw new getid3_exception('PHP seems to think the file is larger than '.round(PHP_INT_MAX / 1073741824).'GB, but filesystem reports it as '.number_format($real_filesize, 3).'GB, please report to info@getid3.org');
  279. }
  280. $this->info['filesize'] = $real_filesize;
  281. $this->error('File is larger than '.round(PHP_INT_MAX / 1073741824).'GB (filesystem reports it as '.number_format($real_filesize, 3).'GB) and is not properly supported by PHP.');
  282. }
  283. }
  284. // set more parameters
  285. $this->info['avdataoffset'] = 0;
  286. $this->info['avdataend'] = $this->info['filesize'];
  287. $this->info['fileformat'] = ''; // filled in later
  288. $this->info['audio']['dataformat'] = ''; // filled in later, unset if not used
  289. $this->info['video']['dataformat'] = ''; // filled in later, unset if not used
  290. $this->info['tags'] = array(); // filled in later, unset if not used
  291. $this->info['error'] = array(); // filled in later, unset if not used
  292. $this->info['warning'] = array(); // filled in later, unset if not used
  293. $this->info['comments'] = array(); // filled in later, unset if not used
  294. $this->info['encoding'] = $this->encoding; // required by id3v2 and iso modules - can be unset at the end if desired
  295. return true;
  296. } catch (Exception $e) {
  297. $this->error($e->getMessage());
  298. }
  299. return false;
  300. }
  301. // public: analyze file
  302. function analyze($filename, $filesize=false, $orig_filename='file.mp3') { // 2nd AND 3rd PARAMTERS ADDED BY POWERPRESS
  303. try {
  304. if (!$this->openfile($filename, $filesize)) {
  305. return $this->info;
  306. }
  307. // ADDED BY POWERPRESS
  308. //if( $filesize )
  309. // $this->info['filesize'] = $filesize;
  310. // END ADDED BY POWERPRESS
  311. // Handle tags
  312. foreach (array('id3v2'=>'id3v2', 'id3v1'=>'id3v1', 'apetag'=>'ape', 'lyrics3'=>'lyrics3') as $tag_name => $tag_key) {
  313. $option_tag = 'option_tag_'.$tag_name;
  314. if ($this->$option_tag) {
  315. $this->include_module('tag.'.$tag_name);
  316. try {
  317. $tag_class = 'getid3_'.$tag_name;
  318. $tag = new $tag_class($this);
  319. $tag->Analyze();
  320. }
  321. catch (getid3_exception $e) {
  322. throw $e;
  323. }
  324. }
  325. }
  326. if (isset($this->info['id3v2']['tag_offset_start'])) {
  327. $this->info['avdataoffset'] = max($this->info['avdataoffset'], $this->info['id3v2']['tag_offset_end']);
  328. }
  329. foreach (array('id3v1'=>'id3v1', 'apetag'=>'ape', 'lyrics3'=>'lyrics3') as $tag_name => $tag_key) {
  330. if (isset($this->info[$tag_key]['tag_offset_start'])) {
  331. $this->info['avdataend'] = min($this->info['avdataend'], $this->info[$tag_key]['tag_offset_start']);
  332. }
  333. }
  334. // ID3v2 detection (NOT parsing), even if ($this->option_tag_id3v2 == false) done to make fileformat easier
  335. if (!$this->option_tag_id3v2) {
  336. fseek($this->fp, 0, SEEK_SET);
  337. $header = fread($this->fp, 10);
  338. if ((substr($header, 0, 3) == 'ID3') && (strlen($header) == 10)) {
  339. $this->info['id3v2']['header'] = true;
  340. $this->info['id3v2']['majorversion'] = ord($header{3});
  341. $this->info['id3v2']['minorversion'] = ord($header{4});
  342. $this->info['avdataoffset'] += getid3_lib::BigEndian2Int(substr($header, 6, 4), 1) + 10; // length of ID3v2 tag in 10-byte header doesn't include 10-byte header length
  343. }
  344. }
  345. // read 32 kb file data
  346. fseek($this->fp, $this->info['avdataoffset'], SEEK_SET);
  347. $formattest = fread($this->fp, 32774);
  348. // determine format
  349. // MODIFIED BY POWERPRESS
  350. $determined_format = $this->GetFileFormat($formattest, $orig_filename);
  351. // MODIFIED BY POWERPRESS
  352. // unable to determine file format
  353. if (!$determined_format) {
  354. fclose($this->fp);
  355. return $this->error('unable to determine file format');
  356. }
  357. // check for illegal ID3 tags
  358. if (isset($determined_format['fail_id3']) && (in_array('id3v1', $this->info['tags']) || in_array('id3v2', $this->info['tags']))) {
  359. if ($determined_format['fail_id3'] === 'ERROR') {
  360. fclose($this->fp);
  361. return $this->error('ID3 tags not allowed on this file type.');
  362. } elseif ($determined_format['fail_id3'] === 'WARNING') {
  363. $this->warning('ID3 tags not allowed on this file type.');
  364. }
  365. }
  366. // check for illegal APE tags
  367. if (isset($determined_format['fail_ape']) && in_array('ape', $this->info['tags'])) {
  368. if ($determined_format['fail_ape'] === 'ERROR') {
  369. fclose($this->fp);
  370. return $this->error('APE tags not allowed on this file type.');
  371. } elseif ($determined_format['fail_ape'] === 'WARNING') {
  372. $this->warning('APE tags not allowed on this file type.');
  373. }
  374. }
  375. // set mime type
  376. $this->info['mime_type'] = $determined_format['mime_type'];
  377. // supported format signature pattern detected, but module deleted
  378. if (!file_exists(GETID3_INCLUDEPATH.$determined_format['include'])) {
  379. fclose($this->fp);
  380. return $this->error('Format not supported, module "'.$determined_format['include'].'" was removed.');
  381. }
  382. // module requires iconv support
  383. // Check encoding/iconv support
  384. if (!empty($determined_format['iconv_req']) && !function_exists('iconv') && !in_array($this->encoding, array('ISO-8859-1', 'UTF-8', 'UTF-16LE', 'UTF-16BE', 'UTF-16'))) {
  385. $errormessage = 'iconv() support is required for this module ('.$determined_format['include'].') for encodings other than ISO-8859-1, UTF-8, UTF-16LE, UTF16-BE, UTF-16. ';
  386. if (GETID3_OS_ISWINDOWS) {
  387. $errormessage .= 'PHP does not have iconv() support. Please enable php_iconv.dll in php.ini, and copy iconv.dll from c:/php/dlls to c:/windows/system32';
  388. } else {
  389. $errormessage .= 'PHP is not compiled with iconv() support. Please recompile with the --with-iconv switch';
  390. }
  391. return $this->error($errormessage);
  392. }
  393. // include module
  394. include_once(GETID3_INCLUDEPATH.$determined_format['include']);
  395. // instantiate module class
  396. $class_name = 'getid3_'.$determined_format['module'];
  397. if (!class_exists($class_name)) {
  398. return $this->error('Format not supported, module "'.$determined_format['include'].'" is corrupt.');
  399. }
  400. //if (isset($determined_format['option'])) {
  401. // //$class = new $class_name($this->fp, $this->info, $determined_format['option']);
  402. //} else {
  403. //$class = new $class_name($this->fp, $this->info);
  404. $class = new $class_name($this);
  405. //}
  406. if (!empty($determined_format['set_inline_attachments'])) {
  407. $class->inline_attachments = $this->option_save_attachments;
  408. }
  409. $class->Analyze();
  410. unset($class);
  411. // close file
  412. fclose($this->fp);
  413. // process all tags - copy to 'tags' and convert charsets
  414. if ($this->option_tags_process) {
  415. $this->HandleAllTags();
  416. }
  417. // perform more calculations
  418. if ($this->option_extra_info) {
  419. $this->ChannelsBitratePlaytimeCalculations();
  420. $this->CalculateCompressionRatioVideo();
  421. $this->CalculateCompressionRatioAudio();
  422. $this->CalculateReplayGain();
  423. $this->ProcessAudioStreams();
  424. }
  425. // get the MD5 sum of the audio/video portion of the file - without ID3/APE/Lyrics3/etc header/footer tags
  426. if ($this->option_md5_data) {
  427. // do not cald md5_data if md5_data_source is present - set by flac only - future MPC/SV8 too
  428. if (!$this->option_md5_data_source || empty($this->info['md5_data_source'])) {
  429. $this->getHashdata('md5');
  430. }
  431. }
  432. // get the SHA1 sum of the audio/video portion of the file - without ID3/APE/Lyrics3/etc header/footer tags
  433. if ($this->option_sha1_data) {
  434. $this->getHashdata('sha1');
  435. }
  436. // remove undesired keys
  437. $this->CleanUp();
  438. } catch (Exception $e) {
  439. $this->error('Caught exception: '.$e->getMessage());
  440. }
  441. // return info array
  442. return $this->info;
  443. }
  444. // private: error handling
  445. function error($message) {
  446. $this->CleanUp();
  447. if (!isset($this->info['error'])) {
  448. $this->info['error'] = array();
  449. }
  450. $this->info['error'][] = $message;
  451. return $this->info;
  452. }
  453. // private: warning handling
  454. function warning($message) {
  455. $this->info['warning'][] = $message;
  456. return true;
  457. }
  458. // private: CleanUp
  459. function CleanUp() {
  460. // remove possible empty keys
  461. $AVpossibleEmptyKeys = array('dataformat', 'bits_per_sample', 'encoder_options', 'streams', 'bitrate');
  462. foreach ($AVpossibleEmptyKeys as $dummy => $key) {
  463. if (empty($this->info['audio'][$key]) && isset($this->info['audio'][$key])) {
  464. unset($this->info['audio'][$key]);
  465. }
  466. if (empty($this->info['video'][$key]) && isset($this->info['video'][$key])) {
  467. unset($this->info['video'][$key]);
  468. }
  469. }
  470. // remove empty root keys
  471. if (!empty($this->info)) {
  472. foreach ($this->info as $key => $value) {
  473. if (empty($this->info[$key]) && ($this->info[$key] !== 0) && ($this->info[$key] !== '0')) {
  474. unset($this->info[$key]);
  475. }
  476. }
  477. }
  478. // remove meaningless entries from unknown-format files
  479. if (empty($this->info['fileformat'])) {
  480. if (isset($this->info['avdataoffset'])) {
  481. unset($this->info['avdataoffset']);
  482. }
  483. if (isset($this->info['avdataend'])) {
  484. unset($this->info['avdataend']);
  485. }
  486. }
  487. // remove possible duplicated identical entries
  488. if (!empty($this->info['error'])) {
  489. $this->info['error'] = array_values(array_unique($this->info['error']));
  490. }
  491. if (!empty($this->info['warning'])) {
  492. $this->info['warning'] = array_values(array_unique($this->info['warning']));
  493. }
  494. // remove "global variable" type keys
  495. unset($this->info['php_memory_limit']);
  496. return true;
  497. }
  498. // return array containing information about all supported formats
  499. function GetFileFormatArray() {
  500. static $format_info = array();
  501. if (empty($format_info)) {
  502. $format_info = array(
  503. // Audio formats
  504. // AC-3 - audio - Dolby AC-3 / Dolby Digital
  505. 'ac3' => array(
  506. 'pattern' => '^\x0B\x77',
  507. 'group' => 'audio',
  508. 'module' => 'ac3',
  509. 'mime_type' => 'audio/ac3',
  510. ),
  511. // AAC - audio - Advanced Audio Coding (AAC) - ADIF format
  512. 'adif' => array(
  513. 'pattern' => '^ADIF',
  514. 'group' => 'audio',
  515. 'module' => 'aac',
  516. 'mime_type' => 'application/octet-stream',
  517. 'fail_ape' => 'WARNING',
  518. ),
  519. // AA - audio - Audible Audiobook
  520. 'adts' => array(
  521. 'pattern' => '^.{4}\x57\x90\x75\x36',
  522. 'group' => 'audio',
  523. 'module' => 'aa',
  524. 'mime_type' => 'audio/audible ',
  525. ),
  526. // AAC - audio - Advanced Audio Coding (AAC) - ADTS format (very similar to MP3)
  527. 'adts' => array(
  528. 'pattern' => '^\xFF[\xF0-\xF1\xF8-\xF9]',
  529. 'group' => 'audio',
  530. 'module' => 'aac',
  531. 'mime_type' => 'application/octet-stream',
  532. 'fail_ape' => 'WARNING',
  533. ),
  534. // AU - audio - NeXT/Sun AUdio (AU)
  535. 'au' => array(
  536. 'pattern' => '^\.snd',
  537. 'group' => 'audio',
  538. 'module' => 'au',
  539. 'mime_type' => 'audio/basic',
  540. ),
  541. // AVR - audio - Audio Visual Research
  542. 'avr' => array(
  543. 'pattern' => '^2BIT',
  544. 'group' => 'audio',
  545. 'module' => 'avr',
  546. 'mime_type' => 'application/octet-stream',
  547. ),
  548. // BONK - audio - Bonk v0.9+
  549. 'bonk' => array(
  550. 'pattern' => '^\x00(BONK|INFO|META| ID3)',
  551. 'group' => 'audio',
  552. 'module' => 'bonk',
  553. 'mime_type' => 'audio/xmms-bonk',
  554. ),
  555. // DSS - audio - Digital Speech Standard
  556. 'dss' => array(
  557. 'pattern' => '^[\x02-\x03]dss',
  558. 'group' => 'audio',
  559. 'module' => 'dss',
  560. 'mime_type' => 'application/octet-stream',
  561. ),
  562. // DTS - audio - Dolby Theatre System
  563. 'dts' => array(
  564. 'pattern' => '^\x7F\xFE\x80\x01',
  565. 'group' => 'audio',
  566. 'module' => 'dts',
  567. 'mime_type' => 'audio/dts',
  568. ),
  569. // FLAC - audio - Free Lossless Audio Codec
  570. 'flac' => array(
  571. 'pattern' => '^fLaC',
  572. 'group' => 'audio',
  573. 'module' => 'flac',
  574. 'mime_type' => 'audio/x-flac',
  575. 'set_inline_attachments' => true,
  576. ),
  577. // LA - audio - Lossless Audio (LA)
  578. 'la' => array(
  579. 'pattern' => '^LA0[2-4]',
  580. 'group' => 'audio',
  581. 'module' => 'la',
  582. 'mime_type' => 'application/octet-stream',
  583. ),
  584. // LPAC - audio - Lossless Predictive Audio Compression (LPAC)
  585. 'lpac' => array(
  586. 'pattern' => '^LPAC',
  587. 'group' => 'audio',
  588. 'module' => 'lpac',
  589. 'mime_type' => 'application/octet-stream',
  590. ),
  591. // MIDI - audio - MIDI (Musical Instrument Digital Interface)
  592. 'midi' => array(
  593. 'pattern' => '^MThd',
  594. 'group' => 'audio',
  595. 'module' => 'midi',
  596. 'mime_type' => 'audio/midi',
  597. ),
  598. // MAC - audio - Monkey's Audio Compressor
  599. 'mac' => array(
  600. 'pattern' => '^MAC ',
  601. 'group' => 'audio',
  602. 'module' => 'monkey',
  603. 'mime_type' => 'application/octet-stream',
  604. ),
  605. // has been known to produce false matches in random files (e.g. JPEGs), leave out until more precise matching available
  606. // // MOD - audio - MODule (assorted sub-formats)
  607. // 'mod' => array(
  608. // 'pattern' => '^.{1080}(M\\.K\\.|M!K!|FLT4|FLT8|[5-9]CHN|[1-3][0-9]CH)',
  609. // 'group' => 'audio',
  610. // 'module' => 'mod',
  611. // 'option' => 'mod',
  612. // 'mime_type' => 'audio/mod',
  613. // ),
  614. // MOD - audio - MODule (Impulse Tracker)
  615. 'it' => array(
  616. 'pattern' => '^IMPM',
  617. 'group' => 'audio',
  618. 'module' => 'mod',
  619. //'option' => 'it',
  620. 'mime_type' => 'audio/it',
  621. ),
  622. // MOD - audio - MODule (eXtended Module, various sub-formats)
  623. 'xm' => array(
  624. 'pattern' => '^Extended Module',
  625. 'group' => 'audio',
  626. 'module' => 'mod',
  627. //'option' => 'xm',
  628. 'mime_type' => 'audio/xm',
  629. ),
  630. // MOD - audio - MODule (ScreamTracker)
  631. 's3m' => array(
  632. 'pattern' => '^.{44}SCRM',
  633. 'group' => 'audio',
  634. 'module' => 'mod',
  635. //'option' => 's3m',
  636. 'mime_type' => 'audio/s3m',
  637. ),
  638. // MPC - audio - Musepack / MPEGplus
  639. 'mpc' => array(
  640. 'pattern' => '^(MPCK|MP\+|[\x00\x01\x10\x11\x40\x41\x50\x51\x80\x81\x90\x91\xC0\xC1\xD0\xD1][\x20-37][\x00\x20\x40\x60\x80\xA0\xC0\xE0])',
  641. 'group' => 'audio',
  642. 'module' => 'mpc',
  643. 'mime_type' => 'audio/x-musepack',
  644. ),
  645. // MP3 - audio - MPEG-audio Layer 3 (very similar to AAC-ADTS)
  646. 'mp3' => array(
  647. 'pattern' => '^\xFF[\xE2-\xE7\xF2-\xF7\xFA-\xFF][\x00-\x0B\x10-\x1B\x20-\x2B\x30-\x3B\x40-\x4B\x50-\x5B\x60-\x6B\x70-\x7B\x80-\x8B\x90-\x9B\xA0-\xAB\xB0-\xBB\xC0-\xCB\xD0-\xDB\xE0-\xEB\xF0-\xFB]',
  648. 'group' => 'audio',
  649. 'module' => 'mp3',
  650. 'mime_type' => 'audio/mpeg',
  651. ),
  652. // OFR - audio - OptimFROG
  653. 'ofr' => array(
  654. 'pattern' => '^(\*RIFF|OFR)',
  655. 'group' => 'audio',
  656. 'module' => 'optimfrog',
  657. 'mime_type' => 'application/octet-stream',
  658. ),
  659. // RKAU - audio - RKive AUdio compressor
  660. 'rkau' => array(
  661. 'pattern' => '^RKA',
  662. 'group' => 'audio',
  663. 'module' => 'rkau',
  664. 'mime_type' => 'application/octet-stream',
  665. ),
  666. // SHN - audio - Shorten
  667. 'shn' => array(
  668. 'pattern' => '^ajkg',
  669. 'group' => 'audio',
  670. 'module' => 'shorten',
  671. 'mime_type' => 'audio/xmms-shn',
  672. 'fail_id3' => 'ERROR',
  673. 'fail_ape' => 'ERROR',
  674. ),
  675. // TTA - audio - TTA Lossless Audio Compressor (http://tta.corecodec.org)
  676. 'tta' => array(
  677. 'pattern' => '^TTA', // could also be '^TTA(\x01|\x02|\x03|2|1)'
  678. 'group' => 'audio',
  679. 'module' => 'tta',
  680. 'mime_type' => 'application/octet-stream',
  681. ),
  682. // VOC - audio - Creative Voice (VOC)
  683. 'voc' => array(
  684. 'pattern' => '^Creative Voice File',
  685. 'group' => 'audio',
  686. 'module' => 'voc',
  687. 'mime_type' => 'audio/voc',
  688. ),
  689. // VQF - audio - transform-domain weighted interleave Vector Quantization Format (VQF)
  690. 'vqf' => array(
  691. 'pattern' => '^TWIN',
  692. 'group' => 'audio',
  693. 'module' => 'vqf',
  694. 'mime_type' => 'application/octet-stream',
  695. ),
  696. // WV - audio - WavPack (v4.0+)
  697. 'wv' => array(
  698. 'pattern' => '^wvpk',
  699. 'group' => 'audio',
  700. 'module' => 'wavpack',
  701. 'mime_type' => 'application/octet-stream',
  702. ),
  703. // Audio-Video formats
  704. // ASF - audio/video - Advanced Streaming Format, Windows Media Video, Windows Media Audio
  705. 'asf' => array(
  706. 'pattern' => '^\x30\x26\xB2\x75\x8E\x66\xCF\x11\xA6\xD9\x00\xAA\x00\x62\xCE\x6C',
  707. 'group' => 'audio-video',
  708. 'module' => 'asf',
  709. 'mime_type' => 'video/x-ms-asf',
  710. 'iconv_req' => false,
  711. ),
  712. // BINK - audio/video - Bink / Smacker
  713. 'bink' => array(
  714. 'pattern' => '^(BIK|SMK)',
  715. 'group' => 'audio-video',
  716. 'module' => 'bink',
  717. 'mime_type' => 'application/octet-stream',
  718. ),
  719. // FLV - audio/video - FLash Video
  720. 'flv' => array(
  721. 'pattern' => '^FLV\x01',
  722. 'group' => 'audio-video',
  723. 'module' => 'flv',
  724. 'mime_type' => 'video/x-flv',
  725. ),
  726. // MKAV - audio/video - Mastroka
  727. 'matroska' => array(
  728. 'pattern' => '^\x1A\x45\xDF\xA3',
  729. 'group' => 'audio-video',
  730. 'module' => 'matroska',
  731. 'mime_type' => 'video/x-matroska', // may also be audio/x-matroska
  732. 'set_inline_attachments' => true,
  733. ),
  734. // MPEG - audio/video - MPEG (Moving Pictures Experts Group)
  735. 'mpeg' => array(
  736. 'pattern' => '^\x00\x00\x01(\xBA|\xB3)',
  737. 'group' => 'audio-video',
  738. 'module' => 'mpeg',
  739. 'mime_type' => 'video/mpeg',
  740. ),
  741. // NSV - audio/video - Nullsoft Streaming Video (NSV)
  742. 'nsv' => array(
  743. 'pattern' => '^NSV[sf]',
  744. 'group' => 'audio-video',
  745. 'module' => 'nsv',
  746. 'mime_type' => 'application/octet-stream',
  747. ),
  748. // Ogg - audio/video - Ogg (Ogg-Vorbis, Ogg-FLAC, Speex, Ogg-Theora(*), Ogg-Tarkin(*))
  749. 'ogg' => array(
  750. 'pattern' => '^OggS',
  751. 'group' => 'audio',
  752. 'module' => 'ogg',
  753. 'mime_type' => 'application/ogg',
  754. 'fail_id3' => 'WARNING',
  755. 'fail_ape' => 'WARNING',
  756. 'set_inline_attachments' => true,
  757. ),
  758. // QT - audio/video - Quicktime
  759. 'quicktime' => array(
  760. 'pattern' => '^.{4}(cmov|free|ftyp|mdat|moov|pnot|skip|wide)',
  761. 'group' => 'audio-video',
  762. 'module' => 'quicktime',
  763. 'mime_type' => 'video/quicktime',
  764. ),
  765. // RIFF - audio/video - Resource Interchange File Format (RIFF) / WAV / AVI / CD-audio / SDSS = renamed variant used by SmartSound QuickTracks (www.smartsound.com) / FORM = Audio Interchange File Format (AIFF)
  766. 'riff' => array(
  767. 'pattern' => '^(RIFF|SDSS|FORM)',
  768. 'group' => 'audio-video',
  769. 'module' => 'riff',
  770. 'mime_type' => 'audio/x-wave',
  771. 'fail_ape' => 'WARNING',
  772. ),
  773. // Real - audio/video - RealAudio, RealVideo
  774. 'real' => array(
  775. 'pattern' => '^(\\.RMF|\\.ra)',
  776. 'group' => 'audio-video',
  777. 'module' => 'real',
  778. 'mime_type' => 'audio/x-realaudio',
  779. ),
  780. // SWF - audio/video - ShockWave Flash
  781. 'swf' => array(
  782. 'pattern' => '^(F|C)WS',
  783. 'group' => 'audio-video',
  784. 'module' => 'swf',
  785. 'mime_type' => 'application/x-shockwave-flash',
  786. ),
  787. // Still-Image formats
  788. // BMP - still image - Bitmap (Windows, OS/2; uncompressed, RLE8, RLE4)
  789. 'bmp' => array(
  790. 'pattern' => '^BM',
  791. 'group' => 'graphic',
  792. 'module' => 'bmp',
  793. 'mime_type' => 'image/bmp',
  794. 'fail_id3' => 'ERROR',
  795. 'fail_ape' => 'ERROR',
  796. ),
  797. // GIF - still image - Graphics Interchange Format
  798. 'gif' => array(
  799. 'pattern' => '^GIF',
  800. 'group' => 'graphic',
  801. 'module' => 'gif',
  802. 'mime_type' => 'image/gif',
  803. 'fail_id3' => 'ERROR',
  804. 'fail_ape' => 'ERROR',
  805. ),
  806. // JPEG - still image - Joint Photographic Experts Group (JPEG)
  807. 'jpg' => array(
  808. 'pattern' => '^\xFF\xD8\xFF',
  809. 'group' => 'graphic',
  810. 'module' => 'jpg',
  811. 'mime_type' => 'image/jpeg',
  812. 'fail_id3' => 'ERROR',
  813. 'fail_ape' => 'ERROR',
  814. ),
  815. // PCD - still image - Kodak Photo CD
  816. 'pcd' => array(
  817. 'pattern' => '^.{2048}PCD_IPI\x00',
  818. 'group' => 'graphic',
  819. 'module' => 'pcd',
  820. 'mime_type' => 'image/x-photo-cd',
  821. 'fail_id3' => 'ERROR',
  822. 'fail_ape' => 'ERROR',
  823. ),
  824. // PNG - still image - Portable Network Graphics (PNG)
  825. 'png' => array(
  826. 'pattern' => '^\x89\x50\x4E\x47\x0D\x0A\x1A\x0A',
  827. 'group' => 'graphic',
  828. 'module' => 'png',
  829. 'mime_type' => 'image/png',
  830. 'fail_id3' => 'ERROR',
  831. 'fail_ape' => 'ERROR',
  832. ),
  833. // SVG - still image - Scalable Vector Graphics (SVG)
  834. 'svg' => array(
  835. 'pattern' => '(<!DOCTYPE svg PUBLIC |xmlns="http:\/\/www\.w3\.org\/2000\/svg")',
  836. 'group' => 'graphic',
  837. 'module' => 'svg',
  838. 'mime_type' => 'image/svg+xml',
  839. 'fail_id3' => 'ERROR',
  840. 'fail_ape' => 'ERROR',
  841. ),
  842. // TIFF - still image - Tagged Information File Format (TIFF)
  843. 'tiff' => array(
  844. 'pattern' => '^(II\x2A\x00|MM\x00\x2A)',
  845. 'group' => 'graphic',
  846. 'module' => 'tiff',
  847. 'mime_type' => 'image/tiff',
  848. 'fail_id3' => 'ERROR',
  849. 'fail_ape' => 'ERROR',
  850. ),
  851. // EFAX - still image - eFax (TIFF derivative)
  852. 'bmp' => array(
  853. 'pattern' => '^\xDC\xFE',
  854. 'group' => 'graphic',
  855. 'module' => 'efax',
  856. 'mime_type' => 'image/efax',
  857. 'fail_id3' => 'ERROR',
  858. 'fail_ape' => 'ERROR',
  859. ),
  860. // Data formats
  861. // ISO - data - International Standards Organization (ISO) CD-ROM Image
  862. 'iso' => array(
  863. 'pattern' => '^.{32769}CD001',
  864. 'group' => 'misc',
  865. 'module' => 'iso',
  866. 'mime_type' => 'application/octet-stream',
  867. 'fail_id3' => 'ERROR',
  868. 'fail_ape' => 'ERROR',
  869. 'iconv_req' => false,
  870. ),
  871. // RAR - data - RAR compressed data
  872. 'rar' => array(
  873. 'pattern' => '^Rar\!',
  874. 'group' => 'archive',
  875. 'module' => 'rar',
  876. 'mime_type' => 'application/octet-stream',
  877. 'fail_id3' => 'ERROR',
  878. 'fail_ape' => 'ERROR',
  879. ),
  880. // SZIP - audio/data - SZIP compressed data
  881. 'szip' => array(
  882. 'pattern' => '^SZ\x0A\x04',
  883. 'group' => 'archive',
  884. 'module' => 'szip',
  885. 'mime_type' => 'application/octet-stream',
  886. 'fail_id3' => 'ERROR',
  887. 'fail_ape' => 'ERROR',
  888. ),
  889. // TAR - data - TAR compressed data
  890. 'tar' => array(
  891. 'pattern' => '^.{100}[0-9\x20]{7}\x00[0-9\x20]{7}\x00[0-9\x20]{7}\x00[0-9\x20\x00]{12}[0-9\x20\x00]{12}',
  892. 'group' => 'archive',
  893. 'module' => 'tar',
  894. 'mime_type' => 'application/x-tar',
  895. 'fail_id3' => 'ERROR',
  896. 'fail_ape' => 'ERROR',
  897. ),
  898. // GZIP - data - GZIP compressed data
  899. 'gz' => array(
  900. 'pattern' => '^\x1F\x8B\x08',
  901. 'group' => 'archive',
  902. 'module' => 'gzip',
  903. 'mime_type' => 'application/x-gzip',
  904. 'fail_id3' => 'ERROR',
  905. 'fail_ape' => 'ERROR',
  906. ),
  907. // ZIP - data - ZIP compressed data
  908. 'zip' => array(
  909. 'pattern' => '^PK\x03\x04',
  910. 'group' => 'archive',
  911. 'module' => 'zip',
  912. 'mime_type' => 'application/zip',
  913. 'fail_id3' => 'ERROR',
  914. 'fail_ape' => 'ERROR',
  915. ),
  916. // Misc other formats
  917. // PAR2 - data - Parity Volume Set Specification 2.0
  918. 'par2' => array (
  919. 'pattern' => '^PAR2\x00PKT',
  920. 'group' => 'misc',
  921. 'module' => 'par2',
  922. 'mime_type' => 'application/octet-stream',
  923. 'fail_id3' => 'ERROR',
  924. 'fail_ape' => 'ERROR',
  925. ),
  926. // PDF - data - Portable Document Format
  927. 'pdf' => array(
  928. 'pattern' => '^\x25PDF',
  929. 'group' => 'misc',
  930. 'module' => 'pdf',
  931. 'mime_type' => 'application/pdf',
  932. 'fail_id3' => 'ERROR',
  933. 'fail_ape' => 'ERROR',
  934. ),
  935. // MSOFFICE - data - ZIP compressed data
  936. 'msoffice' => array(
  937. 'pattern' => '^\xD0\xCF\x11\xE0\xA1\xB1\x1A\xE1', // D0CF11E == DOCFILE == Microsoft Office Document
  938. 'group' => 'misc',
  939. 'module' => 'msoffice',
  940. 'mime_type' => 'application/octet-stream',
  941. 'fail_id3' => 'ERROR',
  942. 'fail_ape' => 'ERROR',
  943. ),
  944. // CUE - data - CUEsheet (index to single-file disc images)
  945. 'cue' => array(
  946. 'pattern' => '', // empty pattern means cannot be automatically detected, will fall through all other formats and match based on filename and very basic file contents
  947. 'group' => 'misc',
  948. 'module' => 'cue',
  949. 'mime_type' => 'application/octet-stream',
  950. ),
  951. );
  952. }
  953. return $format_info;
  954. }
  955. function GetFileFormat(&$filedata, $filename='') {
  956. // this function will determine the format of a file based on usually
  957. // the first 2-4 bytes of the file (8 bytes for PNG, 16 bytes for JPG,
  958. // and in the case of ISO CD image, 6 bytes offset 32kb from the start
  959. // of the file).
  960. // Identify file format - loop through $format_info and detect with reg expr
  961. foreach ($this->GetFileFormatArray() as $format_name => $info) {
  962. // The /s switch on preg_match() forces preg_match() NOT to treat
  963. // newline (0x0A) characters as special chars but do a binary match
  964. if (!empty($info['pattern']) && preg_match('#'.$info['pattern'].'#s', $filedata)) {
  965. $info['include'] = 'module.'.$info['group'].'.'.$info['module'].'.php';
  966. return $info;
  967. }
  968. }
  969. if (preg_match('#\.mp[123a]$#i', $filename)) {
  970. // Too many mp3 encoders on the market put gabage in front of mpeg files
  971. // use assume format on these if format detection failed
  972. $GetFileFormatArray = $this->GetFileFormatArray();
  973. $info = $GetFileFormatArray['mp3'];
  974. $info['include'] = 'module.'.$info['group'].'.'.$info['module'].'.php';
  975. return $info;
  976. } elseif (preg_match('/\.cue$/i', $filename) && preg_match('#FILE "[^"]+" (BINARY|MOTOROLA|AIFF|WAVE|MP3)#', $filedata)) {
  977. // there's not really a useful consistent "magic" at the beginning of .cue files to identify them
  978. // so until I think of something better, just go by filename if all other format checks fail
  979. // and verify there's at least one instance of "TRACK xx AUDIO" in the file
  980. $GetFileFormatArray = $this->GetFileFormatArray();
  981. $info = $GetFileFormatArray['cue'];
  982. $info['include'] = 'module.'.$info['group'].'.'.$info['module'].'.php';
  983. return $info;
  984. }
  985. return false;
  986. }
  987. // converts array to $encoding charset from $this->encoding
  988. function CharConvert(&$array, $encoding) {
  989. // identical encoding - end here
  990. if ($encoding == $this->encoding) {
  991. return;
  992. }
  993. // loop thru array
  994. foreach ($array as $key => $value) {
  995. // go recursive
  996. if (is_array($value)) {
  997. $this->CharConvert($array[$key], $encoding);
  998. }
  999. // convert string
  1000. elseif (is_string($value)) {
  1001. $array[$key] = trim(getid3_lib::iconv_fallback($encoding, $this->encoding, $value));
  1002. }
  1003. }
  1004. }
  1005. function HandleAllTags() {
  1006. // key name => array (tag name, character encoding)
  1007. static $tags;
  1008. if (empty($tags)) {
  1009. $tags = array(
  1010. 'asf' => array('asf' , 'UTF-16LE'),
  1011. 'midi' => array('midi' , 'ISO-8859-1'),
  1012. 'nsv' => array('nsv' , 'ISO-8859-1'),
  1013. 'ogg' => array('vorbiscomment' , 'UTF-8'),
  1014. 'png' => array('png' , 'UTF-8'),
  1015. 'tiff' => array('tiff' , 'ISO-8859-1'),
  1016. 'quicktime' => array('quicktime' , 'UTF-8'),
  1017. 'real' => array('real' , 'ISO-8859-1'),
  1018. 'vqf' => array('vqf' , 'ISO-8859-1'),
  1019. 'zip' => array('zip' , 'ISO-8859-1'),
  1020. 'riff' => array('riff' , 'ISO-8859-1'),
  1021. 'lyrics3' => array('lyrics3' , 'ISO-8859-1'),
  1022. 'id3v1' => array('id3v1' , $this->encoding_id3v1),
  1023. 'id3v2' => array('id3v2' , 'UTF-8'), // not according to the specs (every frame can have a different encoding), but getID3() force-converts all encodings to UTF-8
  1024. 'ape' => array('ape' , 'UTF-8'),
  1025. 'cue' => array('cue' , 'ISO-8859-1'),
  1026. 'matroska' => array('matroska' , 'UTF-8'),
  1027. );
  1028. }
  1029. // loop through comments array
  1030. foreach ($tags as $comment_name => $tagname_encoding_array) {
  1031. list($tag_name, $encoding) = $tagname_encoding_array;
  1032. // fill in default encoding type if not already present
  1033. if (isset($this->info[$comment_name]) && !isset($this->info[$comment_name]['encoding'])) {
  1034. $this->info[$comment_name]['encoding'] = $encoding;
  1035. }
  1036. // copy comments if key name set
  1037. if (!empty($this->info[$comment_name]['comments'])) {
  1038. foreach ($this->info[$comment_name]['comments'] as $tag_key => $valuearray) {
  1039. foreach ($valuearray as $key => $value) {
  1040. if (is_string($value)) {
  1041. $value = trim($value, " \r\n\t"); // do not trim nulls from $value!! Unicode characters will get mangled if trailing nulls are removed!
  1042. }
  1043. if ($value) {
  1044. $this->info['tags'][trim($tag_name)][trim($tag_key)][] = $value;
  1045. }
  1046. }
  1047. }
  1048. if (!isset($this->info['tags'][$tag_name])) {
  1049. // comments are set but contain nothing but empty strings, so skip
  1050. continue;
  1051. }
  1052. if ($this->option_tags_html) {
  1053. foreach ($this->info['tags'][$tag_name] as $tag_key => $valuearray) {
  1054. foreach ($valuearray as $key => $value) {
  1055. if (is_string($value)) {
  1056. //$this->info['tags_html'][$tag_name][$tag_key][$key] = getid3_lib::MultiByteCharString2HTML($value, $encoding);
  1057. $this->info['tags_html'][$tag_name][$tag_key][$key] = str_replace('&#0;', '', trim(getid3_lib::MultiByteCharString2HTML($value, $encoding)));
  1058. } else {
  1059. $this->info['tags_html'][$tag_name][$tag_key][$key] = $value;
  1060. }
  1061. }
  1062. }
  1063. }
  1064. $this->CharConvert($this->info['tags'][$tag_name], $encoding); // only copy gets converted!
  1065. }
  1066. }
  1067. // pictures can take up a lot of space, and we don't need multiple copies of them
  1068. // let there be a single copy in [comments][picture], and not elsewhere
  1069. if (!empty($this->info['tags'])) {
  1070. $unset_keys = array('tags', 'tags_html');
  1071. foreach ($this->info['tags'] as $tagtype => $tagarray) {
  1072. foreach ($tagarray as $tagname => $tagdata) {
  1073. if ($tagname == 'picture') {
  1074. foreach ($tagdata as $key => $tagarray) {
  1075. $this->info['comments']['picture'][] = $tagarray;
  1076. if (isset($tagarray['data']) && isset($tagarray['image_mime'])) {
  1077. if (isset($this->info['tags'][$tagtype][$tagname][$key])) {
  1078. unset($this->info['tags'][$tagtype][$tagname][$key]);
  1079. }
  1080. if (isset($this->info['tags_html'][$tagtype][$tagname][$key])) {
  1081. unset($this->info['tags_html'][$tagtype][$tagname][$key]);
  1082. }
  1083. }
  1084. }
  1085. }
  1086. }
  1087. foreach ($unset_keys as $unset_key) {
  1088. // remove possible empty keys from (e.g. [tags][id3v2][picture])
  1089. if (empty($this->info[$unset_key][$tagtype]['picture'])) {
  1090. unset($this->info[$unset_key][$tagtype]['picture']);
  1091. }
  1092. if (empty($this->info[$unset_key][$tagtype])) {
  1093. unset($this->info[$unset_key][$tagtype]);
  1094. }
  1095. if (empty($this->info[$unset_key])) {
  1096. unset($this->info[$unset_key]);
  1097. }
  1098. }
  1099. // remove duplicate copy of picture data from (e.g. [id3v2][comments][picture])
  1100. if (isset($this->info[$tagtype]['comments']['picture'])) {
  1101. unset($this->info[$tagtype]['comments']['picture']);
  1102. }
  1103. if (empty($this->info[$tagtype]['comments'])) {
  1104. unset($this->info[$tagtype]['comments']);
  1105. }
  1106. if (empty($this->info[$tagtype])) {
  1107. unset($this->info[$tagtype]);
  1108. }
  1109. }
  1110. }
  1111. return true;
  1112. }
  1113. function getHashdata($algorithm) {
  1114. switch ($algorithm) {
  1115. case 'md5':
  1116. case 'sha1':
  1117. break;
  1118. default:
  1119. return $this->error('bad algorithm "'.$algorithm.'" in getHashdata()');
  1120. break;
  1121. }
  1122. if (!empty($this->info['fileformat']) && !empty($this->info['dataformat']) && ($this->info['fileformat'] == 'ogg') && ($this->info['audio']['dataformat'] == 'vorbis')) {
  1123. // We cannot get an identical md5_data value for Ogg files where the comments
  1124. // span more than 1 Ogg page (compared to the same audio data with smaller
  1125. // comments) using the normal getID3() method of MD5'ing the data between the
  1126. // end of the comments and the end of the file (minus any trailing tags),
  1127. // because the page sequence numbers of the pages that the audio data is on
  1128. // do not match. Under normal circumstances, where comments are smaller than
  1129. // the nominal 4-8kB page size, then this is not a problem, but if there are
  1130. // very large comments, the only way around it is to strip off the comment
  1131. // tags with vorbiscomment and MD5 that file.
  1132. // This procedure must be applied to ALL Ogg files, not just the ones with
  1133. // comments larger than 1 page, because the below method simply MD5's the
  1134. // whole file with the comments stripped, not just the portion after the
  1135. // comments block (which is the standard getID3() method.
  1136. // The above-mentioned problem of comments spanning multiple pages and changing
  1137. // page sequence numbers likely happens for OggSpeex and OggFLAC as well, but
  1138. // currently vorbiscomment only works on OggVorbis files.
  1139. if (preg_match('#(1|ON)#i', ini_get('safe_mode'))) {
  1140. $this->warning('Failed making system call to vorbiscomment.exe - '.$algorithm.'_data is incorrect - error returned: PHP running in Safe Mode (backtick operator not available)');
  1141. $this->info[$algorithm.'_data'] = false;
  1142. } else {
  1143. // Prevent user from aborting script
  1144. $old_abort = ignore_user_abort(true);
  1145. // Create empty file
  1146. $empty = tempnam(GETID3_TEMP_DIR, 'getID3');
  1147. touch($empty);
  1148. // Use vorbiscomment to make temp file without comments
  1149. $temp = tempnam(GETID3_TEMP_DIR, 'getID3');
  1150. $file = $this->info['filenamepath'];
  1151. if (GETID3_OS_ISWINDOWS) {
  1152. if (file_exists(GETID3_HELPERAPPSDIR.'vorbiscomment.exe')) {
  1153. $commandline = '"'.GETID3_HELPERAPPSDIR.'vorbiscomment.exe" -w -c "'.$empty.'" "'.$file.'" "'.$temp.'"';
  1154. $VorbisCommentError = `$commandline`;
  1155. } else {
  1156. $VorbisCommentError = 'vorbiscomment.exe not found in '.GETID3_HELPERAPPSDIR;
  1157. }
  1158. } else {
  1159. $commandline = 'vorbiscomment -w -c "'.$empty.'" "'.$file.'" "'.$temp.'" 2>&1';
  1160. $commandline = 'vorbiscomment -w -c '.escapeshellarg($empty).' '.escapeshellarg($file).' '.escapeshellarg($temp).' 2>&1';
  1161. $VorbisCommentError = `$commandline`;
  1162. }
  1163. if (!empty($VorbisCommentError)) {
  1164. $this->info['warning'][] = 'Failed making system call to vorbiscomment(.exe) - '.$algorithm.'_data will be incorrect. If vorbiscomment is unavailable, please download from http://www.vorbis.com/download.psp and put in the getID3() directory. Error returned: '.$VorbisCommentError;
  1165. $this->info[$algorithm.'_data'] = false;
  1166. } else {
  1167. // Get hash of newly created file
  1168. switch ($algorithm) {
  1169. case 'md5':
  1170. $this->info[$algorithm.'_data'] = md5_file($temp);
  1171. break;
  1172. case 'sha1':
  1173. $this->info[$algorithm.'_data'] = sha1_file($temp);
  1174. break;
  1175. }
  1176. }
  1177. // Clean up
  1178. unlink($empty);
  1179. unlink($temp);
  1180. // Reset abort setting
  1181. ignore_user_abort($old_abort);
  1182. }
  1183. } else {
  1184. if (!empty($this->info['avdataoffset']) || (isset($this->info['avdataend']) && ($this->info['avdataend'] < $this->info['filesize']))) {
  1185. // get hash from part of file
  1186. $this->info[$algorithm.'_data'] = getid3_lib::hash_data($this->info['filenamepath'], $this->info['avdataoffset'], $this->info['avdataend'], $algorithm);
  1187. } else {
  1188. // get hash from whole file
  1189. switch ($algorithm) {
  1190. case 'md5':
  1191. $this->info[$algorithm.'_data'] = md5_file($this->info['filenamepath']);
  1192. break;
  1193. case 'sha1':
  1194. $this->info[$algorithm.'_data'] = sha1_

Large files files are truncated, but you can click here to view the full file