PageRenderTime 51ms CodeModel.GetById 11ms RepoModel.GetById 0ms app.codeStats 1ms

/components/com_jce/editor/tiny_mce/plugins/mediamanager/classes/getid3/getid3.php

https://bitbucket.org/organicdevelopment/joomla-2.5
PHP | 1761 lines | 1199 code | 268 blank | 294 comment | 231 complexity | d5a79349eb44c0d2fc8508d534e987b0 MD5 | raw file
Possible License(s): LGPL-3.0, GPL-2.0, MIT, BSD-3-Clause, LGPL-2.1

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

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