Açıklama Yok

getid3.php 73KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304
  1. <?php
  2. /////////////////////////////////////////////////////////////////
  3. /// getID3() by James Heinrich <info@getid3.org> //
  4. // available at https://github.com/JamesHeinrich/getID3 //
  5. // or https://www.getid3.org //
  6. // or http://getid3.sourceforge.net //
  7. // //
  8. // Please see readme.txt for more information //
  9. // ///
  10. /////////////////////////////////////////////////////////////////
  11. // define a constant rather than looking up every time it is needed
  12. if (!defined('GETID3_OS_ISWINDOWS')) {
  13. define('GETID3_OS_ISWINDOWS', (stripos(PHP_OS, 'WIN') === 0));
  14. }
  15. // Get base path of getID3() - ONCE
  16. if (!defined('GETID3_INCLUDEPATH')) {
  17. define('GETID3_INCLUDEPATH', dirname(__FILE__).DIRECTORY_SEPARATOR);
  18. }
  19. // Workaround Bug #39923 (https://bugs.php.net/bug.php?id=39923)
  20. if (!defined('IMG_JPG') && defined('IMAGETYPE_JPEG')) {
  21. define('IMG_JPG', IMAGETYPE_JPEG);
  22. }
  23. if (!defined('ENT_SUBSTITUTE')) { // PHP5.3 adds ENT_IGNORE, PHP5.4 adds ENT_SUBSTITUTE
  24. define('ENT_SUBSTITUTE', (defined('ENT_IGNORE') ? ENT_IGNORE : 8));
  25. }
  26. /*
  27. https://www.getid3.org/phpBB3/viewtopic.php?t=2114
  28. If you are running into a the problem where filenames with special characters are being handled
  29. incorrectly by external helper programs (e.g. metaflac), notably with the special characters removed,
  30. and you are passing in the filename in UTF8 (typically via a HTML form), try uncommenting this line:
  31. */
  32. //setlocale(LC_CTYPE, 'en_US.UTF-8');
  33. // attempt to define temp dir as something flexible but reliable
  34. $temp_dir = ini_get('upload_tmp_dir');
  35. if ($temp_dir && (!is_dir($temp_dir) || !is_readable($temp_dir))) {
  36. $temp_dir = '';
  37. }
  38. if (!$temp_dir && function_exists('sys_get_temp_dir')) { // sys_get_temp_dir added in PHP v5.2.1
  39. // sys_get_temp_dir() may give inaccessible temp dir, e.g. with open_basedir on virtual hosts
  40. $temp_dir = sys_get_temp_dir();
  41. }
  42. $temp_dir = @realpath($temp_dir); // see https://github.com/JamesHeinrich/getID3/pull/10
  43. $open_basedir = ini_get('open_basedir');
  44. if ($open_basedir) {
  45. // e.g. "/var/www/vhosts/getid3.org/httpdocs/:/tmp/"
  46. $temp_dir = str_replace(array('/', '\\'), DIRECTORY_SEPARATOR, $temp_dir);
  47. $open_basedir = str_replace(array('/', '\\'), DIRECTORY_SEPARATOR, $open_basedir);
  48. if (substr($temp_dir, -1, 1) != DIRECTORY_SEPARATOR) {
  49. $temp_dir .= DIRECTORY_SEPARATOR;
  50. }
  51. $found_valid_tempdir = false;
  52. $open_basedirs = explode(PATH_SEPARATOR, $open_basedir);
  53. foreach ($open_basedirs as $basedir) {
  54. if (substr($basedir, -1, 1) != DIRECTORY_SEPARATOR) {
  55. $basedir .= DIRECTORY_SEPARATOR;
  56. }
  57. if (preg_match('#^'.preg_quote($basedir).'#', $temp_dir)) {
  58. $found_valid_tempdir = true;
  59. break;
  60. }
  61. }
  62. if (!$found_valid_tempdir) {
  63. $temp_dir = '';
  64. }
  65. unset($open_basedirs, $found_valid_tempdir, $basedir);
  66. }
  67. if (!$temp_dir) {
  68. $temp_dir = '*'; // invalid directory name should force tempnam() to use system default temp dir
  69. }
  70. // $temp_dir = '/something/else/'; // feel free to override temp dir here if it works better for your system
  71. if (!defined('GETID3_TEMP_DIR')) {
  72. define('GETID3_TEMP_DIR', $temp_dir);
  73. }
  74. unset($open_basedir, $temp_dir);
  75. // End: Defines
  76. class getID3
  77. {
  78. /*
  79. * Settings
  80. */
  81. /**
  82. * CASE SENSITIVE! - i.e. (must be supported by iconv()). Examples: ISO-8859-1 UTF-8 UTF-16 UTF-16BE
  83. *
  84. * @var string
  85. */
  86. public $encoding = 'UTF-8';
  87. /**
  88. * Should always be 'ISO-8859-1', but some tags may be written in other encodings such as 'EUC-CN' or 'CP1252'
  89. *
  90. * @var string
  91. */
  92. public $encoding_id3v1 = 'ISO-8859-1';
  93. /**
  94. * ID3v1 should always be 'ISO-8859-1', but some tags may be written in other encodings such as 'Windows-1251' or 'KOI8-R'. If true attempt to detect these encodings, but may return incorrect values for some tags actually in ISO-8859-1 encoding
  95. *
  96. * @var bool
  97. */
  98. public $encoding_id3v1_autodetect = false;
  99. /*
  100. * Optional tag checks - disable for speed.
  101. */
  102. /**
  103. * Read and process ID3v1 tags
  104. *
  105. * @var bool
  106. */
  107. public $option_tag_id3v1 = true;
  108. /**
  109. * Read and process ID3v2 tags
  110. *
  111. * @var bool
  112. */
  113. public $option_tag_id3v2 = true;
  114. /**
  115. * Read and process Lyrics3 tags
  116. *
  117. * @var bool
  118. */
  119. public $option_tag_lyrics3 = true;
  120. /**
  121. * Read and process APE tags
  122. *
  123. * @var bool
  124. */
  125. public $option_tag_apetag = true;
  126. /**
  127. * Copy tags to root key 'tags' and encode to $this->encoding
  128. *
  129. * @var bool
  130. */
  131. public $option_tags_process = true;
  132. /**
  133. * Copy tags to root key 'tags_html' properly translated from various encodings to HTML entities
  134. *
  135. * @var bool
  136. */
  137. public $option_tags_html = true;
  138. /*
  139. * Optional tag/comment calculations
  140. */
  141. /**
  142. * Calculate additional info such as bitrate, channelmode etc
  143. *
  144. * @var bool
  145. */
  146. public $option_extra_info = true;
  147. /*
  148. * Optional handling of embedded attachments (e.g. images)
  149. */
  150. /**
  151. * Defaults to true (ATTACHMENTS_INLINE) for backward compatibility
  152. *
  153. * @var bool|string
  154. */
  155. public $option_save_attachments = true;
  156. /*
  157. * Optional calculations
  158. */
  159. /**
  160. * Get MD5 sum of data part - slow
  161. *
  162. * @var bool
  163. */
  164. public $option_md5_data = false;
  165. /**
  166. * Use MD5 of source file if availble - only FLAC and OptimFROG
  167. *
  168. * @var bool
  169. */
  170. public $option_md5_data_source = false;
  171. /**
  172. * Get SHA1 sum of data part - slow
  173. *
  174. * @var bool
  175. */
  176. public $option_sha1_data = false;
  177. /**
  178. * Check whether file is larger than 2GB and thus not supported by 32-bit PHP (null: auto-detect based on
  179. * PHP_INT_MAX)
  180. *
  181. * @var bool|null
  182. */
  183. public $option_max_2gb_check;
  184. /**
  185. * Read buffer size in bytes
  186. *
  187. * @var int
  188. */
  189. public $option_fread_buffer_size = 32768;
  190. // Public variables
  191. /**
  192. * Filename of file being analysed.
  193. *
  194. * @var string
  195. */
  196. public $filename;
  197. /**
  198. * Filepointer to file being analysed.
  199. *
  200. * @var resource
  201. */
  202. public $fp;
  203. /**
  204. * Result array.
  205. *
  206. * @var array
  207. */
  208. public $info;
  209. /**
  210. * @var string
  211. */
  212. public $tempdir = GETID3_TEMP_DIR;
  213. /**
  214. * @var int
  215. */
  216. public $memory_limit = 0;
  217. /**
  218. * @var string
  219. */
  220. protected $startup_error = '';
  221. /**
  222. * @var string
  223. */
  224. protected $startup_warning = '';
  225. const VERSION = '1.9.20-202006061653';
  226. const FREAD_BUFFER_SIZE = 32768;
  227. const ATTACHMENTS_NONE = false;
  228. const ATTACHMENTS_INLINE = true;
  229. public function __construct() {
  230. // Check for PHP version
  231. $required_php_version = '5.3.0';
  232. if (version_compare(PHP_VERSION, $required_php_version, '<')) {
  233. $this->startup_error .= 'getID3() requires PHP v'.$required_php_version.' or higher - you are running v'.PHP_VERSION."\n";
  234. return;
  235. }
  236. // Check memory
  237. $memoryLimit = ini_get('memory_limit');
  238. if (preg_match('#([0-9]+) ?M#i', $memoryLimit, $matches)) {
  239. // could be stored as "16M" rather than 16777216 for example
  240. $memoryLimit = $matches[1] * 1048576;
  241. } elseif (preg_match('#([0-9]+) ?G#i', $memoryLimit, $matches)) { // The 'G' modifier is available since PHP 5.1.0
  242. // could be stored as "2G" rather than 2147483648 for example
  243. $memoryLimit = $matches[1] * 1073741824;
  244. }
  245. $this->memory_limit = $memoryLimit;
  246. if ($this->memory_limit <= 0) {
  247. // memory limits probably disabled
  248. } elseif ($this->memory_limit <= 4194304) {
  249. $this->startup_error .= 'PHP has less than 4MB available memory and will very likely run out. Increase memory_limit in php.ini'."\n";
  250. } elseif ($this->memory_limit <= 12582912) {
  251. $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'."\n";
  252. }
  253. // Check safe_mode off
  254. if (preg_match('#(1|ON)#i', ini_get('safe_mode'))) { // phpcs:ignore PHPCompatibility.IniDirectives.RemovedIniDirectives.safe_modeDeprecatedRemoved
  255. $this->warning('WARNING: Safe mode is on, shorten support disabled, md5data/sha1data for ogg vorbis disabled, ogg vorbos/flac tag writing disabled.');
  256. }
  257. // phpcs:ignore PHPCompatibility.IniDirectives.RemovedIniDirectives.mbstring_func_overloadDeprecated
  258. if (($mbstring_func_overload = (int) ini_get('mbstring.func_overload')) && ($mbstring_func_overload & 0x02)) {
  259. // http://php.net/manual/en/mbstring.overload.php
  260. // "mbstring.func_overload in php.ini is a positive value that represents a combination of bitmasks specifying the categories of functions to be overloaded. It should be set to 1 to overload the mail() function. 2 for string functions, 4 for regular expression functions"
  261. // getID3 cannot run when string functions are overloaded. It doesn't matter if mail() or ereg* functions are overloaded since getID3 does not use those.
  262. // phpcs:ignore PHPCompatibility.IniDirectives.RemovedIniDirectives.mbstring_func_overloadDeprecated
  263. $this->startup_error .= 'WARNING: php.ini contains "mbstring.func_overload = '.ini_get('mbstring.func_overload').'", getID3 cannot run with this setting (bitmask 2 (string functions) cannot be set). Recommended to disable entirely.'."\n";
  264. }
  265. // check for magic quotes in PHP < 7.4.0 (when these functions became deprecated)
  266. if (version_compare(PHP_VERSION, '7.4.0', '<')) {
  267. // Check for magic_quotes_runtime
  268. if (function_exists('get_magic_quotes_runtime')) {
  269. // phpcs:ignore PHPCompatibility.FunctionUse.RemovedFunctions.get_magic_quotes_runtimeDeprecated
  270. if (get_magic_quotes_runtime()) {
  271. $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).'."\n";
  272. }
  273. }
  274. // Check for magic_quotes_gpc
  275. if (function_exists('get_magic_quotes_gpc')) {
  276. // phpcs:ignore PHPCompatibility.FunctionUse.RemovedFunctions.get_magic_quotes_gpcDeprecated
  277. if (get_magic_quotes_gpc()) {
  278. $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).'."\n";
  279. }
  280. }
  281. }
  282. // Load support library
  283. if (!include_once(GETID3_INCLUDEPATH.'getid3.lib.php')) {
  284. $this->startup_error .= 'getid3.lib.php is missing or corrupt'."\n";
  285. }
  286. if ($this->option_max_2gb_check === null) {
  287. $this->option_max_2gb_check = (PHP_INT_MAX <= 2147483647);
  288. }
  289. // Needed for Windows only:
  290. // Define locations of helper applications for Shorten, VorbisComment, MetaFLAC
  291. // as well as other helper functions such as head, etc
  292. // This path cannot contain spaces, but the below code will attempt to get the
  293. // 8.3-equivalent path automatically
  294. // IMPORTANT: This path must include the trailing slash
  295. if (GETID3_OS_ISWINDOWS && !defined('GETID3_HELPERAPPSDIR')) {
  296. $helperappsdir = GETID3_INCLUDEPATH.'..'.DIRECTORY_SEPARATOR.'helperapps'; // must not have any space in this path
  297. if (!is_dir($helperappsdir)) {
  298. $this->startup_warning .= '"'.$helperappsdir.'" cannot be defined as GETID3_HELPERAPPSDIR because it does not exist'."\n";
  299. } elseif (strpos(realpath($helperappsdir), ' ') !== false) {
  300. $DirPieces = explode(DIRECTORY_SEPARATOR, realpath($helperappsdir));
  301. $path_so_far = array();
  302. foreach ($DirPieces as $key => $value) {
  303. if (strpos($value, ' ') !== false) {
  304. if (!empty($path_so_far)) {
  305. $commandline = 'dir /x '.escapeshellarg(implode(DIRECTORY_SEPARATOR, $path_so_far));
  306. $dir_listing = `$commandline`;
  307. $lines = explode("\n", $dir_listing);
  308. foreach ($lines as $line) {
  309. $line = trim($line);
  310. if (preg_match('#^([0-9/]{10}) +([0-9:]{4,5}( [AP]M)?) +(<DIR>|[0-9,]+) +([^ ]{0,11}) +(.+)$#', $line, $matches)) {
  311. list($dummy, $date, $time, $ampm, $filesize, $shortname, $filename) = $matches;
  312. if ((strtoupper($filesize) == '<DIR>') && (strtolower($filename) == strtolower($value))) {
  313. $value = $shortname;
  314. }
  315. }
  316. }
  317. } else {
  318. $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.'."\n";
  319. }
  320. }
  321. $path_so_far[] = $value;
  322. }
  323. $helperappsdir = implode(DIRECTORY_SEPARATOR, $path_so_far);
  324. }
  325. define('GETID3_HELPERAPPSDIR', $helperappsdir.DIRECTORY_SEPARATOR);
  326. }
  327. if (!empty($this->startup_error)) {
  328. echo $this->startup_error;
  329. throw new getid3_exception($this->startup_error);
  330. }
  331. }
  332. /**
  333. * @return string
  334. */
  335. public function version() {
  336. return self::VERSION;
  337. }
  338. /**
  339. * @return int
  340. */
  341. public function fread_buffer_size() {
  342. return $this->option_fread_buffer_size;
  343. }
  344. /**
  345. * @param array $optArray
  346. *
  347. * @return bool
  348. */
  349. public function setOption($optArray) {
  350. if (!is_array($optArray) || empty($optArray)) {
  351. return false;
  352. }
  353. foreach ($optArray as $opt => $val) {
  354. if (isset($this->$opt) === false) {
  355. continue;
  356. }
  357. $this->$opt = $val;
  358. }
  359. return true;
  360. }
  361. /**
  362. * @param string $filename
  363. * @param int $filesize
  364. * @param resource $fp
  365. *
  366. * @return bool
  367. *
  368. * @throws getid3_exception
  369. */
  370. public function openfile($filename, $filesize=null, $fp=null) {
  371. try {
  372. if (!empty($this->startup_error)) {
  373. throw new getid3_exception($this->startup_error);
  374. }
  375. if (!empty($this->startup_warning)) {
  376. foreach (explode("\n", $this->startup_warning) as $startup_warning) {
  377. $this->warning($startup_warning);
  378. }
  379. }
  380. // init result array and set parameters
  381. $this->filename = $filename;
  382. $this->info = array();
  383. $this->info['GETID3_VERSION'] = $this->version();
  384. $this->info['php_memory_limit'] = (($this->memory_limit > 0) ? $this->memory_limit : false);
  385. // remote files not supported
  386. if (preg_match('#^(ht|f)tp://#', $filename)) {
  387. throw new getid3_exception('Remote files are not supported - please copy the file locally first');
  388. }
  389. $filename = str_replace('/', DIRECTORY_SEPARATOR, $filename);
  390. //$filename = preg_replace('#(?<!gs:)('.preg_quote(DIRECTORY_SEPARATOR).'{2,})#', DIRECTORY_SEPARATOR, $filename);
  391. // open local file
  392. //if (is_readable($filename) && is_file($filename) && ($this->fp = fopen($filename, 'rb'))) { // see https://www.getid3.org/phpBB3/viewtopic.php?t=1720
  393. if (($fp != null) && ((get_resource_type($fp) == 'file') || (get_resource_type($fp) == 'stream'))) {
  394. $this->fp = $fp;
  395. } elseif ((is_readable($filename) || file_exists($filename)) && is_file($filename) && ($this->fp = fopen($filename, 'rb'))) {
  396. // great
  397. } else {
  398. $errormessagelist = array();
  399. if (!is_readable($filename)) {
  400. $errormessagelist[] = '!is_readable';
  401. }
  402. if (!is_file($filename)) {
  403. $errormessagelist[] = '!is_file';
  404. }
  405. if (!file_exists($filename)) {
  406. $errormessagelist[] = '!file_exists';
  407. }
  408. if (empty($errormessagelist)) {
  409. $errormessagelist[] = 'fopen failed';
  410. }
  411. throw new getid3_exception('Could not open "'.$filename.'" ('.implode('; ', $errormessagelist).')');
  412. }
  413. $this->info['filesize'] = (!is_null($filesize) ? $filesize : filesize($filename));
  414. // set redundant parameters - might be needed in some include file
  415. // filenames / filepaths in getID3 are always expressed with forward slashes (unix-style) for both Windows and other to try and minimize confusion
  416. $filename = str_replace('\\', '/', $filename);
  417. $this->info['filepath'] = str_replace('\\', '/', realpath(dirname($filename)));
  418. $this->info['filename'] = getid3_lib::mb_basename($filename);
  419. $this->info['filenamepath'] = $this->info['filepath'].'/'.$this->info['filename'];
  420. // set more parameters
  421. $this->info['avdataoffset'] = 0;
  422. $this->info['avdataend'] = $this->info['filesize'];
  423. $this->info['fileformat'] = ''; // filled in later
  424. $this->info['audio']['dataformat'] = ''; // filled in later, unset if not used
  425. $this->info['video']['dataformat'] = ''; // filled in later, unset if not used
  426. $this->info['tags'] = array(); // filled in later, unset if not used
  427. $this->info['error'] = array(); // filled in later, unset if not used
  428. $this->info['warning'] = array(); // filled in later, unset if not used
  429. $this->info['comments'] = array(); // filled in later, unset if not used
  430. $this->info['encoding'] = $this->encoding; // required by id3v2 and iso modules - can be unset at the end if desired
  431. // option_max_2gb_check
  432. if ($this->option_max_2gb_check) {
  433. // PHP (32-bit all, and 64-bit Windows) doesn't support integers larger than 2^31 (~2GB)
  434. // filesize() simply returns (filesize % (pow(2, 32)), no matter the actual filesize
  435. // ftell() returns 0 if seeking to the end is beyond the range of unsigned integer
  436. $fseek = fseek($this->fp, 0, SEEK_END);
  437. if (($fseek < 0) || (($this->info['filesize'] != 0) && (ftell($this->fp) == 0)) ||
  438. ($this->info['filesize'] < 0) ||
  439. (ftell($this->fp) < 0)) {
  440. $real_filesize = getid3_lib::getFileSizeSyscall($this->info['filenamepath']);
  441. if ($real_filesize === false) {
  442. unset($this->info['filesize']);
  443. fclose($this->fp);
  444. 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.');
  445. } elseif (getid3_lib::intValueSupported($real_filesize)) {
  446. unset($this->info['filesize']);
  447. fclose($this->fp);
  448. 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 / 1073741824, 3).'GB, please report to info@getid3.org');
  449. }
  450. $this->info['filesize'] = $real_filesize;
  451. $this->warning('File is larger than '.round(PHP_INT_MAX / 1073741824).'GB (filesystem reports it as '.number_format($real_filesize / 1073741824, 3).'GB) and is not properly supported by PHP.');
  452. }
  453. }
  454. return true;
  455. } catch (Exception $e) {
  456. $this->error($e->getMessage());
  457. }
  458. return false;
  459. }
  460. /**
  461. * analyze file
  462. *
  463. * @param string $filename
  464. * @param int $filesize
  465. * @param string $original_filename
  466. * @param resource $fp
  467. *
  468. * @return array
  469. */
  470. public function analyze($filename, $filesize=null, $original_filename='', $fp=null) {
  471. try {
  472. if (!$this->openfile($filename, $filesize, $fp)) {
  473. return $this->info;
  474. }
  475. // Handle tags
  476. foreach (array('id3v2'=>'id3v2', 'id3v1'=>'id3v1', 'apetag'=>'ape', 'lyrics3'=>'lyrics3') as $tag_name => $tag_key) {
  477. $option_tag = 'option_tag_'.$tag_name;
  478. if ($this->$option_tag) {
  479. $this->include_module('tag.'.$tag_name);
  480. try {
  481. $tag_class = 'getid3_'.$tag_name;
  482. $tag = new $tag_class($this);
  483. $tag->Analyze();
  484. }
  485. catch (getid3_exception $e) {
  486. throw $e;
  487. }
  488. }
  489. }
  490. if (isset($this->info['id3v2']['tag_offset_start'])) {
  491. $this->info['avdataoffset'] = max($this->info['avdataoffset'], $this->info['id3v2']['tag_offset_end']);
  492. }
  493. foreach (array('id3v1'=>'id3v1', 'apetag'=>'ape', 'lyrics3'=>'lyrics3') as $tag_name => $tag_key) {
  494. if (isset($this->info[$tag_key]['tag_offset_start'])) {
  495. $this->info['avdataend'] = min($this->info['avdataend'], $this->info[$tag_key]['tag_offset_start']);
  496. }
  497. }
  498. // ID3v2 detection (NOT parsing), even if ($this->option_tag_id3v2 == false) done to make fileformat easier
  499. if (!$this->option_tag_id3v2) {
  500. fseek($this->fp, 0);
  501. $header = fread($this->fp, 10);
  502. if ((substr($header, 0, 3) == 'ID3') && (strlen($header) == 10)) {
  503. $this->info['id3v2']['header'] = true;
  504. $this->info['id3v2']['majorversion'] = ord($header[3]);
  505. $this->info['id3v2']['minorversion'] = ord($header[4]);
  506. $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
  507. }
  508. }
  509. // read 32 kb file data
  510. fseek($this->fp, $this->info['avdataoffset']);
  511. $formattest = fread($this->fp, 32774);
  512. // determine format
  513. $determined_format = $this->GetFileFormat($formattest, ($original_filename ? $original_filename : $filename));
  514. // unable to determine file format
  515. if (!$determined_format) {
  516. fclose($this->fp);
  517. return $this->error('unable to determine file format');
  518. }
  519. // check for illegal ID3 tags
  520. if (isset($determined_format['fail_id3']) && (in_array('id3v1', $this->info['tags']) || in_array('id3v2', $this->info['tags']))) {
  521. if ($determined_format['fail_id3'] === 'ERROR') {
  522. fclose($this->fp);
  523. return $this->error('ID3 tags not allowed on this file type.');
  524. } elseif ($determined_format['fail_id3'] === 'WARNING') {
  525. $this->warning('ID3 tags not allowed on this file type.');
  526. }
  527. }
  528. // check for illegal APE tags
  529. if (isset($determined_format['fail_ape']) && in_array('ape', $this->info['tags'])) {
  530. if ($determined_format['fail_ape'] === 'ERROR') {
  531. fclose($this->fp);
  532. return $this->error('APE tags not allowed on this file type.');
  533. } elseif ($determined_format['fail_ape'] === 'WARNING') {
  534. $this->warning('APE tags not allowed on this file type.');
  535. }
  536. }
  537. // set mime type
  538. $this->info['mime_type'] = $determined_format['mime_type'];
  539. // supported format signature pattern detected, but module deleted
  540. if (!file_exists(GETID3_INCLUDEPATH.$determined_format['include'])) {
  541. fclose($this->fp);
  542. return $this->error('Format not supported, module "'.$determined_format['include'].'" was removed.');
  543. }
  544. // module requires mb_convert_encoding/iconv support
  545. // Check encoding/iconv support
  546. if (!empty($determined_format['iconv_req']) && !function_exists('mb_convert_encoding') && !function_exists('iconv') && !in_array($this->encoding, array('ISO-8859-1', 'UTF-8', 'UTF-16LE', 'UTF-16BE', 'UTF-16'))) {
  547. $errormessage = 'mb_convert_encoding() or 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. ';
  548. if (GETID3_OS_ISWINDOWS) {
  549. $errormessage .= 'PHP does not have mb_convert_encoding() or iconv() support. Please enable php_mbstring.dll / php_iconv.dll in php.ini, and copy php_mbstring.dll / iconv.dll from c:/php/dlls to c:/windows/system32';
  550. } else {
  551. $errormessage .= 'PHP is not compiled with mb_convert_encoding() or iconv() support. Please recompile with the --enable-mbstring / --with-iconv switch';
  552. }
  553. return $this->error($errormessage);
  554. }
  555. // include module
  556. include_once(GETID3_INCLUDEPATH.$determined_format['include']);
  557. // instantiate module class
  558. $class_name = 'getid3_'.$determined_format['module'];
  559. if (!class_exists($class_name)) {
  560. return $this->error('Format not supported, module "'.$determined_format['include'].'" is corrupt.');
  561. }
  562. $class = new $class_name($this);
  563. $class->Analyze();
  564. unset($class);
  565. // close file
  566. fclose($this->fp);
  567. // process all tags - copy to 'tags' and convert charsets
  568. if ($this->option_tags_process) {
  569. $this->HandleAllTags();
  570. }
  571. // perform more calculations
  572. if ($this->option_extra_info) {
  573. $this->ChannelsBitratePlaytimeCalculations();
  574. $this->CalculateCompressionRatioVideo();
  575. $this->CalculateCompressionRatioAudio();
  576. $this->CalculateReplayGain();
  577. $this->ProcessAudioStreams();
  578. }
  579. // get the MD5 sum of the audio/video portion of the file - without ID3/APE/Lyrics3/etc header/footer tags
  580. if ($this->option_md5_data) {
  581. // do not calc md5_data if md5_data_source is present - set by flac only - future MPC/SV8 too
  582. if (!$this->option_md5_data_source || empty($this->info['md5_data_source'])) {
  583. $this->getHashdata('md5');
  584. }
  585. }
  586. // get the SHA1 sum of the audio/video portion of the file - without ID3/APE/Lyrics3/etc header/footer tags
  587. if ($this->option_sha1_data) {
  588. $this->getHashdata('sha1');
  589. }
  590. // remove undesired keys
  591. $this->CleanUp();
  592. } catch (Exception $e) {
  593. $this->error('Caught exception: '.$e->getMessage());
  594. }
  595. // return info array
  596. return $this->info;
  597. }
  598. /**
  599. * Error handling.
  600. *
  601. * @param string $message
  602. *
  603. * @return array
  604. */
  605. public function error($message) {
  606. $this->CleanUp();
  607. if (!isset($this->info['error'])) {
  608. $this->info['error'] = array();
  609. }
  610. $this->info['error'][] = $message;
  611. return $this->info;
  612. }
  613. /**
  614. * Warning handling.
  615. *
  616. * @param string $message
  617. *
  618. * @return bool
  619. */
  620. public function warning($message) {
  621. $this->info['warning'][] = $message;
  622. return true;
  623. }
  624. /**
  625. * @return bool
  626. */
  627. private function CleanUp() {
  628. // remove possible empty keys
  629. $AVpossibleEmptyKeys = array('dataformat', 'bits_per_sample', 'encoder_options', 'streams', 'bitrate');
  630. foreach ($AVpossibleEmptyKeys as $dummy => $key) {
  631. if (empty($this->info['audio'][$key]) && isset($this->info['audio'][$key])) {
  632. unset($this->info['audio'][$key]);
  633. }
  634. if (empty($this->info['video'][$key]) && isset($this->info['video'][$key])) {
  635. unset($this->info['video'][$key]);
  636. }
  637. }
  638. // remove empty root keys
  639. if (!empty($this->info)) {
  640. foreach ($this->info as $key => $value) {
  641. if (empty($this->info[$key]) && ($this->info[$key] !== 0) && ($this->info[$key] !== '0')) {
  642. unset($this->info[$key]);
  643. }
  644. }
  645. }
  646. // remove meaningless entries from unknown-format files
  647. if (empty($this->info['fileformat'])) {
  648. if (isset($this->info['avdataoffset'])) {
  649. unset($this->info['avdataoffset']);
  650. }
  651. if (isset($this->info['avdataend'])) {
  652. unset($this->info['avdataend']);
  653. }
  654. }
  655. // remove possible duplicated identical entries
  656. if (!empty($this->info['error'])) {
  657. $this->info['error'] = array_values(array_unique($this->info['error']));
  658. }
  659. if (!empty($this->info['warning'])) {
  660. $this->info['warning'] = array_values(array_unique($this->info['warning']));
  661. }
  662. // remove "global variable" type keys
  663. unset($this->info['php_memory_limit']);
  664. return true;
  665. }
  666. /**
  667. * Return array containing information about all supported formats.
  668. *
  669. * @return array
  670. */
  671. public function GetFileFormatArray() {
  672. static $format_info = array();
  673. if (empty($format_info)) {
  674. $format_info = array(
  675. // Audio formats
  676. // AC-3 - audio - Dolby AC-3 / Dolby Digital
  677. 'ac3' => array(
  678. 'pattern' => '^\\x0B\\x77',
  679. 'group' => 'audio',
  680. 'module' => 'ac3',
  681. 'mime_type' => 'audio/ac3',
  682. ),
  683. // AAC - audio - Advanced Audio Coding (AAC) - ADIF format
  684. 'adif' => array(
  685. 'pattern' => '^ADIF',
  686. 'group' => 'audio',
  687. 'module' => 'aac',
  688. 'mime_type' => 'audio/aac',
  689. 'fail_ape' => 'WARNING',
  690. ),
  691. /*
  692. // AA - audio - Audible Audiobook
  693. 'aa' => array(
  694. 'pattern' => '^.{4}\\x57\\x90\\x75\\x36',
  695. 'group' => 'audio',
  696. 'module' => 'aa',
  697. 'mime_type' => 'audio/audible',
  698. ),
  699. */
  700. // AAC - audio - Advanced Audio Coding (AAC) - ADTS format (very similar to MP3)
  701. 'adts' => array(
  702. 'pattern' => '^\\xFF[\\xF0-\\xF1\\xF8-\\xF9]',
  703. 'group' => 'audio',
  704. 'module' => 'aac',
  705. 'mime_type' => 'audio/aac',
  706. 'fail_ape' => 'WARNING',
  707. ),
  708. // AU - audio - NeXT/Sun AUdio (AU)
  709. 'au' => array(
  710. 'pattern' => '^\\.snd',
  711. 'group' => 'audio',
  712. 'module' => 'au',
  713. 'mime_type' => 'audio/basic',
  714. ),
  715. // AMR - audio - Adaptive Multi Rate
  716. 'amr' => array(
  717. 'pattern' => '^\\x23\\x21AMR\\x0A', // #!AMR[0A]
  718. 'group' => 'audio',
  719. 'module' => 'amr',
  720. 'mime_type' => 'audio/amr',
  721. ),
  722. // AVR - audio - Audio Visual Research
  723. 'avr' => array(
  724. 'pattern' => '^2BIT',
  725. 'group' => 'audio',
  726. 'module' => 'avr',
  727. 'mime_type' => 'application/octet-stream',
  728. ),
  729. // BONK - audio - Bonk v0.9+
  730. 'bonk' => array(
  731. 'pattern' => '^\\x00(BONK|INFO|META| ID3)',
  732. 'group' => 'audio',
  733. 'module' => 'bonk',
  734. 'mime_type' => 'audio/xmms-bonk',
  735. ),
  736. // DSF - audio - Direct Stream Digital (DSD) Storage Facility files (DSF) - https://en.wikipedia.org/wiki/Direct_Stream_Digital
  737. 'dsf' => array(
  738. 'pattern' => '^DSD ', // including trailing space: 44 53 44 20
  739. 'group' => 'audio',
  740. 'module' => 'dsf',
  741. 'mime_type' => 'audio/dsd',
  742. ),
  743. // DSS - audio - Digital Speech Standard
  744. 'dss' => array(
  745. 'pattern' => '^[\\x02-\\x08]ds[s2]',
  746. 'group' => 'audio',
  747. 'module' => 'dss',
  748. 'mime_type' => 'application/octet-stream',
  749. ),
  750. // DSDIFF - audio - Direct Stream Digital Interchange File Format
  751. 'dsdiff' => array(
  752. 'pattern' => '^FRM8',
  753. 'group' => 'audio',
  754. 'module' => 'dsdiff',
  755. 'mime_type' => 'audio/dsd',
  756. ),
  757. // DTS - audio - Dolby Theatre System
  758. 'dts' => array(
  759. 'pattern' => '^\\x7F\\xFE\\x80\\x01',
  760. 'group' => 'audio',
  761. 'module' => 'dts',
  762. 'mime_type' => 'audio/dts',
  763. ),
  764. // FLAC - audio - Free Lossless Audio Codec
  765. 'flac' => array(
  766. 'pattern' => '^fLaC',
  767. 'group' => 'audio',
  768. 'module' => 'flac',
  769. 'mime_type' => 'audio/flac',
  770. ),
  771. // LA - audio - Lossless Audio (LA)
  772. 'la' => array(
  773. 'pattern' => '^LA0[2-4]',
  774. 'group' => 'audio',
  775. 'module' => 'la',
  776. 'mime_type' => 'application/octet-stream',
  777. ),
  778. // LPAC - audio - Lossless Predictive Audio Compression (LPAC)
  779. 'lpac' => array(
  780. 'pattern' => '^LPAC',
  781. 'group' => 'audio',
  782. 'module' => 'lpac',
  783. 'mime_type' => 'application/octet-stream',
  784. ),
  785. // MIDI - audio - MIDI (Musical Instrument Digital Interface)
  786. 'midi' => array(
  787. 'pattern' => '^MThd',
  788. 'group' => 'audio',
  789. 'module' => 'midi',
  790. 'mime_type' => 'audio/midi',
  791. ),
  792. // MAC - audio - Monkey's Audio Compressor
  793. 'mac' => array(
  794. 'pattern' => '^MAC ',
  795. 'group' => 'audio',
  796. 'module' => 'monkey',
  797. 'mime_type' => 'audio/x-monkeys-audio',
  798. ),
  799. // has been known to produce false matches in random files (e.g. JPEGs), leave out until more precise matching available
  800. // // MOD - audio - MODule (assorted sub-formats)
  801. // 'mod' => array(
  802. // 'pattern' => '^.{1080}(M\\.K\\.|M!K!|FLT4|FLT8|[5-9]CHN|[1-3][0-9]CH)',
  803. // 'group' => 'audio',
  804. // 'module' => 'mod',
  805. // 'option' => 'mod',
  806. // 'mime_type' => 'audio/mod',
  807. // ),
  808. // MOD - audio - MODule (Impulse Tracker)
  809. 'it' => array(
  810. 'pattern' => '^IMPM',
  811. 'group' => 'audio',
  812. 'module' => 'mod',
  813. //'option' => 'it',
  814. 'mime_type' => 'audio/it',
  815. ),
  816. // MOD - audio - MODule (eXtended Module, various sub-formats)
  817. 'xm' => array(
  818. 'pattern' => '^Extended Module',
  819. 'group' => 'audio',
  820. 'module' => 'mod',
  821. //'option' => 'xm',
  822. 'mime_type' => 'audio/xm',
  823. ),
  824. // MOD - audio - MODule (ScreamTracker)
  825. 's3m' => array(
  826. 'pattern' => '^.{44}SCRM',
  827. 'group' => 'audio',
  828. 'module' => 'mod',
  829. //'option' => 's3m',
  830. 'mime_type' => 'audio/s3m',
  831. ),
  832. // MPC - audio - Musepack / MPEGplus
  833. 'mpc' => array(
  834. 'pattern' => '^(MPCK|MP\\+|[\\x00\\x01\\x10\\x11\\x40\\x41\\x50\\x51\\x80\\x81\\x90\\x91\\xC0\\xC1\\xD0\\xD1][\\x20-\\x37][\\x00\\x20\\x40\\x60\\x80\\xA0\\xC0\\xE0])',
  835. 'group' => 'audio',
  836. 'module' => 'mpc',
  837. 'mime_type' => 'audio/x-musepack',
  838. ),
  839. // MP3 - audio - MPEG-audio Layer 3 (very similar to AAC-ADTS)
  840. 'mp3' => array(
  841. '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]',
  842. 'group' => 'audio',
  843. 'module' => 'mp3',
  844. 'mime_type' => 'audio/mpeg',
  845. ),
  846. // OFR - audio - OptimFROG
  847. 'ofr' => array(
  848. 'pattern' => '^(\\*RIFF|OFR)',
  849. 'group' => 'audio',
  850. 'module' => 'optimfrog',
  851. 'mime_type' => 'application/octet-stream',
  852. ),
  853. // RKAU - audio - RKive AUdio compressor
  854. 'rkau' => array(
  855. 'pattern' => '^RKA',
  856. 'group' => 'audio',
  857. 'module' => 'rkau',
  858. 'mime_type' => 'application/octet-stream',
  859. ),
  860. // SHN - audio - Shorten
  861. 'shn' => array(
  862. 'pattern' => '^ajkg',
  863. 'group' => 'audio',
  864. 'module' => 'shorten',
  865. 'mime_type' => 'audio/xmms-shn',
  866. 'fail_id3' => 'ERROR',
  867. 'fail_ape' => 'ERROR',
  868. ),
  869. // TAK - audio - Tom's lossless Audio Kompressor
  870. 'tak' => array(
  871. 'pattern' => '^tBaK',
  872. 'group' => 'audio',
  873. 'module' => 'tak',
  874. 'mime_type' => 'application/octet-stream',
  875. ),
  876. // TTA - audio - TTA Lossless Audio Compressor (http://tta.corecodec.org)
  877. 'tta' => array(
  878. 'pattern' => '^TTA', // could also be '^TTA(\\x01|\\x02|\\x03|2|1)'
  879. 'group' => 'audio',
  880. 'module' => 'tta',
  881. 'mime_type' => 'application/octet-stream',
  882. ),
  883. // VOC - audio - Creative Voice (VOC)
  884. 'voc' => array(
  885. 'pattern' => '^Creative Voice File',
  886. 'group' => 'audio',
  887. 'module' => 'voc',
  888. 'mime_type' => 'audio/voc',
  889. ),
  890. // VQF - audio - transform-domain weighted interleave Vector Quantization Format (VQF)
  891. 'vqf' => array(
  892. 'pattern' => '^TWIN',
  893. 'group' => 'audio',
  894. 'module' => 'vqf',
  895. 'mime_type' => 'application/octet-stream',
  896. ),
  897. // WV - audio - WavPack (v4.0+)
  898. 'wv' => array(
  899. 'pattern' => '^wvpk',
  900. 'group' => 'audio',
  901. 'module' => 'wavpack',
  902. 'mime_type' => 'application/octet-stream',
  903. ),
  904. // Audio-Video formats
  905. // ASF - audio/video - Advanced Streaming Format, Windows Media Video, Windows Media Audio
  906. 'asf' => array(
  907. 'pattern' => '^\\x30\\x26\\xB2\\x75\\x8E\\x66\\xCF\\x11\\xA6\\xD9\\x00\\xAA\\x00\\x62\\xCE\\x6C',
  908. 'group' => 'audio-video',
  909. 'module' => 'asf',
  910. 'mime_type' => 'video/x-ms-asf',
  911. 'iconv_req' => false,
  912. ),
  913. // BINK - audio/video - Bink / Smacker
  914. 'bink' => array(
  915. 'pattern' => '^(BIK|SMK)',
  916. 'group' => 'audio-video',
  917. 'module' => 'bink',
  918. 'mime_type' => 'application/octet-stream',
  919. ),
  920. // FLV - audio/video - FLash Video
  921. 'flv' => array(
  922. 'pattern' => '^FLV[\\x01]',
  923. 'group' => 'audio-video',
  924. 'module' => 'flv',
  925. 'mime_type' => 'video/x-flv',
  926. ),
  927. // IVF - audio/video - IVF
  928. 'ivf' => array(
  929. 'pattern' => '^DKIF',
  930. 'group' => 'audio-video',
  931. 'module' => 'ivf',
  932. 'mime_type' => 'video/x-ivf',
  933. ),
  934. // MKAV - audio/video - Mastroka
  935. 'matroska' => array(
  936. 'pattern' => '^\\x1A\\x45\\xDF\\xA3',
  937. 'group' => 'audio-video',
  938. 'module' => 'matroska',
  939. 'mime_type' => 'video/x-matroska', // may also be audio/x-matroska
  940. ),
  941. // MPEG - audio/video - MPEG (Moving Pictures Experts Group)
  942. 'mpeg' => array(
  943. 'pattern' => '^\\x00\\x00\\x01[\\xB3\\xBA]',
  944. 'group' => 'audio-video',
  945. 'module' => 'mpeg',
  946. 'mime_type' => 'video/mpeg',
  947. ),
  948. // NSV - audio/video - Nullsoft Streaming Video (NSV)
  949. 'nsv' => array(
  950. 'pattern' => '^NSV[sf]',
  951. 'group' => 'audio-video',
  952. 'module' => 'nsv',
  953. 'mime_type' => 'application/octet-stream',
  954. ),
  955. // Ogg - audio/video - Ogg (Ogg-Vorbis, Ogg-FLAC, Speex, Ogg-Theora(*), Ogg-Tarkin(*))
  956. 'ogg' => array(
  957. 'pattern' => '^OggS',
  958. 'group' => 'audio',
  959. 'module' => 'ogg',
  960. 'mime_type' => 'application/ogg',
  961. 'fail_id3' => 'WARNING',
  962. 'fail_ape' => 'WARNING',
  963. ),
  964. // QT - audio/video - Quicktime
  965. 'quicktime' => array(
  966. 'pattern' => '^.{4}(cmov|free|ftyp|mdat|moov|pnot|skip|wide)',
  967. 'group' => 'audio-video',
  968. 'module' => 'quicktime',
  969. 'mime_type' => 'video/quicktime',
  970. ),
  971. // 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)
  972. 'riff' => array(
  973. 'pattern' => '^(RIFF|SDSS|FORM)',
  974. 'group' => 'audio-video',
  975. 'module' => 'riff',
  976. 'mime_type' => 'audio/wav',
  977. 'fail_ape' => 'WARNING',
  978. ),
  979. // Real - audio/video - RealAudio, RealVideo
  980. 'real' => array(
  981. 'pattern' => '^\\.(RMF|ra)',
  982. 'group' => 'audio-video',
  983. 'module' => 'real',
  984. 'mime_type' => 'audio/x-realaudio',
  985. ),
  986. // SWF - audio/video - ShockWave Flash
  987. 'swf' => array(
  988. 'pattern' => '^(F|C)WS',
  989. 'group' => 'audio-video',
  990. 'module' => 'swf',
  991. 'mime_type' => 'application/x-shockwave-flash',
  992. ),
  993. // TS - audio/video - MPEG-2 Transport Stream
  994. 'ts' => array(
  995. 'pattern' => '^(\\x47.{187}){10,}', // packets are 188 bytes long and start with 0x47 "G". Check for at least 10 packets matching this pattern
  996. 'group' => 'audio-video',
  997. 'module' => 'ts',
  998. 'mime_type' => 'video/MP2T',
  999. ),
  1000. // WTV - audio/video - Windows Recorded TV Show
  1001. 'wtv' => array(
  1002. 'pattern' => '^\\xB7\\xD8\\x00\\x20\\x37\\x49\\xDA\\x11\\xA6\\x4E\\x00\\x07\\xE9\\x5E\\xAD\\x8D',
  1003. 'group' => 'audio-video',
  1004. 'module' => 'wtv',
  1005. 'mime_type' => 'video/x-ms-wtv',
  1006. ),
  1007. // Still-Image formats
  1008. // BMP - still image - Bitmap (Windows, OS/2; uncompressed, RLE8, RLE4)
  1009. 'bmp' => array(
  1010. 'pattern' => '^BM',
  1011. 'group' => 'graphic',
  1012. 'module' => 'bmp',
  1013. 'mime_type' => 'image/bmp',
  1014. 'fail_id3' => 'ERROR',
  1015. 'fail_ape' => 'ERROR',
  1016. ),
  1017. // GIF - still image - Graphics Interchange Format
  1018. 'gif' => array(
  1019. 'pattern' => '^GIF',
  1020. 'group' => 'graphic',
  1021. 'module' => 'gif',
  1022. 'mime_type' => 'image/gif',
  1023. 'fail_id3' => 'ERROR',
  1024. 'fail_ape' => 'ERROR',
  1025. ),
  1026. // JPEG - still image - Joint Photographic Experts Group (JPEG)
  1027. 'jpg' => array(
  1028. 'pattern' => '^\\xFF\\xD8\\xFF',
  1029. 'group' => 'graphic',
  1030. 'module' => 'jpg',
  1031. 'mime_type' => 'image/jpeg',
  1032. 'fail_id3' => 'ERROR',
  1033. 'fail_ape' => 'ERROR',
  1034. ),
  1035. // PCD - still image - Kodak Photo CD
  1036. 'pcd' => array(
  1037. 'pattern' => '^.{2048}PCD_IPI\\x00',
  1038. 'group' => 'graphic',
  1039. 'module' => 'pcd',
  1040. 'mime_type' => 'image/x-photo-cd',
  1041. 'fail_id3' => 'ERROR',
  1042. 'fail_ape' => 'ERROR',
  1043. ),
  1044. // PNG - still image - Portable Network Graphics (PNG)
  1045. 'png' => array(
  1046. 'pattern' => '^\\x89\\x50\\x4E\\x47\\x0D\\x0A\\x1A\\x0A',
  1047. 'group' => 'graphic',
  1048. 'module' => 'png',
  1049. 'mime_type' => 'image/png',
  1050. 'fail_id3' => 'ERROR',
  1051. 'fail_ape' => 'ERROR',
  1052. ),
  1053. // SVG - still image - Scalable Vector Graphics (SVG)
  1054. 'svg' => array(
  1055. 'pattern' => '(<!DOCTYPE svg PUBLIC |xmlns="http://www\\.w3\\.org/2000/svg")',
  1056. 'group' => 'graphic',
  1057. 'module' => 'svg',
  1058. 'mime_type' => 'image/svg+xml',
  1059. 'fail_id3' => 'ERROR',
  1060. 'fail_ape' => 'ERROR',
  1061. ),
  1062. // TIFF - still image - Tagged Information File Format (TIFF)
  1063. 'tiff' => array(
  1064. 'pattern' => '^(II\\x2A\\x00|MM\\x00\\x2A)',
  1065. 'group' => 'graphic',
  1066. 'module' => 'tiff',
  1067. 'mime_type' => 'image/tiff',
  1068. 'fail_id3' => 'ERROR',
  1069. 'fail_ape' => 'ERROR',
  1070. ),
  1071. // EFAX - still image - eFax (TIFF derivative)
  1072. 'efax' => array(
  1073. 'pattern' => '^\\xDC\\xFE',
  1074. 'group' => 'graphic',
  1075. 'module' => 'efax',
  1076. 'mime_type' => 'image/efax',
  1077. 'fail_id3' => 'ERROR',
  1078. 'fail_ape' => 'ERROR',
  1079. ),
  1080. // Data formats
  1081. // ISO - data - International Standards Organization (ISO) CD-ROM Image
  1082. 'iso' => array(
  1083. 'pattern' => '^.{32769}CD001',
  1084. 'group' => 'misc',
  1085. 'module' => 'iso',
  1086. 'mime_type' => 'application/octet-stream',
  1087. 'fail_id3' => 'ERROR',
  1088. 'fail_ape' => 'ERROR',
  1089. 'iconv_req' => false,
  1090. ),
  1091. // HPK - data - HPK compressed data
  1092. 'hpk' => array(
  1093. 'pattern' => '^BPUL',
  1094. 'group' => 'archive',
  1095. 'module' => 'hpk',
  1096. 'mime_type' => 'application/octet-stream',
  1097. 'fail_id3' => 'ERROR',
  1098. 'fail_ape' => 'ERROR',
  1099. ),
  1100. // RAR - data - RAR compressed data
  1101. 'rar' => array(
  1102. 'pattern' => '^Rar\\!',
  1103. 'group' => 'archive',
  1104. 'module' => 'rar',
  1105. 'mime_type' => 'application/vnd.rar',
  1106. 'fail_id3' => 'ERROR',
  1107. 'fail_ape' => 'ERROR',
  1108. ),
  1109. // SZIP - audio/data - SZIP compressed data
  1110. 'szip' => array(
  1111. 'pattern' => '^SZ\\x0A\\x04',
  1112. 'group' => 'archive',
  1113. 'module' => 'szip',
  1114. 'mime_type' => 'application/octet-stream',
  1115. 'fail_id3' => 'ERROR',
  1116. 'fail_ape' => 'ERROR',
  1117. ),
  1118. // TAR - data - TAR compressed data
  1119. 'tar' => array(
  1120. '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}',
  1121. 'group' => 'archive',
  1122. 'module' => 'tar',
  1123. 'mime_type' => 'application/x-tar',
  1124. 'fail_id3' => 'ERROR',
  1125. 'fail_ape' => 'ERROR',
  1126. ),
  1127. // GZIP - data - GZIP compressed data
  1128. 'gz' => array(
  1129. 'pattern' => '^\\x1F\\x8B\\x08',
  1130. 'group' => 'archive',
  1131. 'module' => 'gzip',
  1132. 'mime_type' => 'application/gzip',
  1133. 'fail_id3' => 'ERROR',
  1134. 'fail_ape' => 'ERROR',
  1135. ),
  1136. // ZIP - data - ZIP compressed data
  1137. 'zip' => array(
  1138. 'pattern' => '^PK\\x03\\x04',
  1139. 'group' => 'archive',
  1140. 'module' => 'zip',
  1141. 'mime_type' => 'application/zip',
  1142. 'fail_id3' => 'ERROR',
  1143. 'fail_ape' => 'ERROR',
  1144. ),
  1145. // XZ - data - XZ compressed data
  1146. 'xz' => array(
  1147. 'pattern' => '^\\xFD7zXZ\\x00',
  1148. 'group' => 'archive',
  1149. 'module' => 'xz',
  1150. 'mime_type' => 'application/x-xz',
  1151. 'fail_id3' => 'ERROR',
  1152. 'fail_ape' => 'ERROR',
  1153. ),
  1154. // Misc other formats
  1155. // PAR2 - data - Parity Volume Set Specification 2.0
  1156. 'par2' => array (
  1157. 'pattern' => '^PAR2\\x00PKT',
  1158. 'group' => 'misc',
  1159. 'module' => 'par2',
  1160. 'mime_type' => 'application/octet-stream',
  1161. 'fail_id3' => 'ERROR',
  1162. 'fail_ape' => 'ERROR',
  1163. ),
  1164. // PDF - data - Portable Document Format
  1165. 'pdf' => array(
  1166. 'pattern' => '^\\x25PDF',
  1167. 'group' => 'misc',
  1168. 'module' => 'pdf',
  1169. 'mime_type' => 'application/pdf',
  1170. 'fail_id3' => 'ERROR',
  1171. 'fail_ape' => 'ERROR',
  1172. ),
  1173. // MSOFFICE - data - ZIP compressed data
  1174. 'msoffice' => array(
  1175. 'pattern' => '^\\xD0\\xCF\\x11\\xE0\\xA1\\xB1\\x1A\\xE1', // D0CF11E == DOCFILE == Microsoft Office Document
  1176. 'group' => 'misc',
  1177. 'module' => 'msoffice',
  1178. 'mime_type' => 'application/octet-stream',
  1179. 'fail_id3' => 'ERROR',
  1180. 'fail_ape' => 'ERROR',
  1181. ),
  1182. // CUE - data - CUEsheet (index to single-file disc images)
  1183. 'cue' => array(
  1184. 'pattern' => '', // empty pattern means cannot be automatically detected, will fall through all other formats and match based on filename and very basic file contents
  1185. 'group' => 'misc',
  1186. 'module' => 'cue',
  1187. 'mime_type' => 'application/octet-stream',
  1188. ),
  1189. );
  1190. }
  1191. return $format_info;
  1192. }
  1193. /**
  1194. * @param string $filedata
  1195. * @param string $filename
  1196. *
  1197. * @return mixed|false
  1198. */
  1199. public function GetFileFormat(&$filedata, $filename='') {
  1200. // this function will determine the format of a file based on usually
  1201. // the first 2-4 bytes of the file (8 bytes for PNG, 16 bytes for JPG,
  1202. // and in the case of ISO CD image, 6 bytes offset 32kb from the start
  1203. // of the file).
  1204. // Identify file format - loop through $format_info and detect with reg expr
  1205. foreach ($this->GetFileFormatArray() as $format_name => $info) {
  1206. // The /s switch on preg_match() forces preg_match() NOT to treat
  1207. // newline (0x0A) characters as special chars but do a binary match
  1208. if (!empty($info['pattern']) && preg_match('#'.$info['pattern'].'#s', $filedata)) {
  1209. $info['include'] = 'module.'.$info['group'].'.'.$info['module'].'.php';
  1210. return $info;
  1211. }
  1212. }
  1213. if (preg_match('#\\.mp[123a]$#i', $filename)) {
  1214. // Too many mp3 encoders on the market put garbage in front of mpeg files
  1215. // use assume format on these if format detection failed
  1216. $GetFileFormatArray = $this->GetFileFormatArray();
  1217. $info = $GetFileFormatArray['mp3'];
  1218. $info['include'] = 'module.'.$info['group'].'.'.$info['module'].'.php';
  1219. return $info;
  1220. } elseif (preg_match('#\\.cue$#i', $filename) && preg_match('#FILE "[^"]+" (BINARY|MOTOROLA|AIFF|WAVE|MP3)#', $filedata)) {
  1221. // there's not really a useful consistent "magic" at the beginning of .cue files to identify them
  1222. // so until I think of something better, just go by filename if all other format checks fail
  1223. // and verify there's at least one instance of "TRACK xx AUDIO" in the file
  1224. $GetFileFormatArray = $this->GetFileFormatArray();
  1225. $info = $GetFileFormatArray['cue'];
  1226. $info['include'] = 'module.'.$info['group'].'.'.$info['module'].'.php';
  1227. return $info;
  1228. }
  1229. return false;
  1230. }
  1231. /**
  1232. * Converts array to $encoding charset from $this->encoding.
  1233. *
  1234. * @param array $array
  1235. * @param string $encoding
  1236. */
  1237. public function CharConvert(&$array, $encoding) {
  1238. // identical encoding - end here
  1239. if ($encoding == $this->encoding) {
  1240. return;
  1241. }
  1242. // loop thru array
  1243. foreach ($array as $key => $value) {
  1244. // go recursive
  1245. if (is_array($value)) {
  1246. $this->CharConvert($array[$key], $encoding);
  1247. }
  1248. // convert string
  1249. elseif (is_string($value)) {
  1250. $array[$key] = trim(getid3_lib::iconv_fallback($encoding, $this->encoding, $value));
  1251. }
  1252. }
  1253. }
  1254. /**
  1255. * @return bool
  1256. */
  1257. public function HandleAllTags() {
  1258. // key name => array (tag name, character encoding)
  1259. static $tags;
  1260. if (empty($tags)) {
  1261. $tags = array(
  1262. 'asf' => array('asf' , 'UTF-16LE'),
  1263. 'midi' => array('midi' , 'ISO-8859-1'),
  1264. 'nsv' => array('nsv' , 'ISO-8859-1'),
  1265. 'ogg' => array('vorbiscomment' , 'UTF-8'),
  1266. 'png' => array('png' , 'UTF-8'),
  1267. 'tiff' => array('tiff' , 'ISO-8859-1'),
  1268. 'quicktime' => array('quicktime' , 'UTF-8'),
  1269. 'real' => array('real' , 'ISO-8859-1'),
  1270. 'vqf' => array('vqf' , 'ISO-8859-1'),
  1271. 'zip' => array('zip' , 'ISO-8859-1'),
  1272. 'riff' => array('riff' , 'ISO-8859-1'),
  1273. 'lyrics3' => array('lyrics3' , 'ISO-8859-1'),
  1274. 'id3v1' => array('id3v1' , $this->encoding_id3v1),
  1275. '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
  1276. 'ape' => array('ape' , 'UTF-8'),
  1277. 'cue' => array('cue' , 'ISO-8859-1'),
  1278. 'matroska' => array('matroska' , 'UTF-8'),
  1279. 'flac' => array('vorbiscomment' , 'UTF-8'),
  1280. 'divxtag' => array('divx' , 'ISO-8859-1'),
  1281. 'iptc' => array('iptc' , 'ISO-8859-1'),
  1282. 'dsdiff' => array('dsdiff' , 'ISO-8859-1'),
  1283. );
  1284. }
  1285. // loop through comments array
  1286. foreach ($tags as $comment_name => $tagname_encoding_array) {
  1287. list($tag_name, $encoding) = $tagname_encoding_array;
  1288. // fill in default encoding type if not already present
  1289. if (isset($this->info[$comment_name]) && !isset($this->info[$comment_name]['encoding'])) {
  1290. $this->info[$comment_name]['encoding'] = $encoding;
  1291. }
  1292. // copy comments if key name set
  1293. if (!empty($this->info[$comment_name]['comments'])) {
  1294. foreach ($this->info[$comment_name]['comments'] as $tag_key => $valuearray) {
  1295. foreach ($valuearray as $key => $value) {
  1296. if (is_string($value)) {
  1297. $value = trim($value, " \r\n\t"); // do not trim nulls from $value!! Unicode characters will get mangled if trailing nulls are removed!
  1298. }
  1299. if ($value) {
  1300. if (!is_numeric($key)) {
  1301. $this->info['tags'][trim($tag_name)][trim($tag_key)][$key] = $value;
  1302. } else {
  1303. $this->info['tags'][trim($tag_name)][trim($tag_key)][] = $value;
  1304. }
  1305. }
  1306. }
  1307. if ($tag_key == 'picture') {
  1308. // pictures can take up a lot of space, and we don't need multiple copies of them; let there be a single copy in [comments][picture], and not elsewhere
  1309. unset($this->info[$comment_name]['comments'][$tag_key]);
  1310. }
  1311. }
  1312. if (!isset($this->info['tags'][$tag_name])) {
  1313. // comments are set but contain nothing but empty strings, so skip
  1314. continue;
  1315. }
  1316. $this->CharConvert($this->info['tags'][$tag_name], $this->info[$comment_name]['encoding']); // only copy gets converted!
  1317. if ($this->option_tags_html) {
  1318. foreach ($this->info['tags'][$tag_name] as $tag_key => $valuearray) {
  1319. if ($tag_key == 'picture') {
  1320. // Do not to try to convert binary picture data to HTML
  1321. // https://github.com/JamesHeinrich/getID3/issues/178
  1322. continue;
  1323. }
  1324. $this->info['tags_html'][$tag_name][$tag_key] = getid3_lib::recursiveMultiByteCharString2HTML($valuearray, $this->info[$comment_name]['encoding']);
  1325. }
  1326. }
  1327. }
  1328. }
  1329. // pictures can take up a lot of space, and we don't need multiple copies of them; let there be a single copy in [comments][picture], and not elsewhere
  1330. if (!empty($this->info['tags'])) {
  1331. $unset_keys = array('tags', 'tags_html');
  1332. foreach ($this->info['tags'] as $tagtype => $tagarray) {
  1333. foreach ($tagarray as $tagname => $tagdata) {
  1334. if ($tagname == 'picture') {
  1335. foreach ($tagdata as $key => $tagarray) {
  1336. $this->info['comments']['picture'][] = $tagarray;
  1337. if (isset($tagarray['data']) && isset($tagarray['image_mime'])) {
  1338. if (isset($this->info['tags'][$tagtype][$tagname][$key])) {
  1339. unset($this->info['tags'][$tagtype][$tagname][$key]);
  1340. }
  1341. if (isset($this->info['tags_html'][$tagtype][$tagname][$key])) {
  1342. unset($this->info['tags_html'][$tagtype][$tagname][$key]);
  1343. }
  1344. }
  1345. }
  1346. }
  1347. }
  1348. foreach ($unset_keys as $unset_key) {
  1349. // remove possible empty keys from (e.g. [tags][id3v2][picture])
  1350. if (empty($this->info[$unset_key][$tagtype]['picture'])) {
  1351. unset($this->info[$unset_key][$tagtype]['picture']);
  1352. }
  1353. if (empty($this->info[$unset_key][$tagtype])) {
  1354. unset($this->info[$unset_key][$tagtype]);
  1355. }
  1356. if (empty($this->info[$unset_key])) {
  1357. unset($this->info[$unset_key]);
  1358. }
  1359. }
  1360. // remove duplicate copy of picture data from (e.g. [id3v2][comments][picture])
  1361. if (isset($this->info[$tagtype]['comments']['picture'])) {
  1362. unset($this->info[$tagtype]['comments']['picture']);
  1363. }
  1364. if (empty($this->info[$tagtype]['comments'])) {
  1365. unset($this->info[$tagtype]['comments']);
  1366. }
  1367. if (empty($this->info[$tagtype])) {
  1368. unset($this->info[$tagtype]);
  1369. }
  1370. }
  1371. }
  1372. return true;
  1373. }
  1374. /**
  1375. * Calls getid3_lib::CopyTagsToComments() but passes in the option_tags_html setting from this instance of getID3
  1376. *
  1377. * @param array $ThisFileInfo
  1378. *
  1379. * @return bool
  1380. */
  1381. public function CopyTagsToComments(&$ThisFileInfo) {
  1382. return getid3_lib::CopyTagsToComments($ThisFileInfo, $this->option_tags_html);
  1383. }
  1384. /**
  1385. * @param string $algorithm
  1386. *
  1387. * @return array|bool
  1388. */
  1389. public function getHashdata($algorithm) {
  1390. switch ($algorithm) {
  1391. case 'md5':
  1392. case 'sha1':
  1393. break;
  1394. default:
  1395. return $this->error('bad algorithm "'.$algorithm.'" in getHashdata()');
  1396. }
  1397. if (!empty($this->info['fileformat']) && !empty($this->info['dataformat']) && ($this->info['fileformat'] == 'ogg') && ($this->info['audio']['dataformat'] == 'vorbis')) {
  1398. // We cannot get an identical md5_data value for Ogg files where the comments
  1399. // span more than 1 Ogg page (compared to the same audio data with smaller
  1400. // comments) using the normal getID3() method of MD5'ing the data between the
  1401. // end of the comments and the end of the file (minus any trailing tags),
  1402. // because the page sequence numbers of the pages that the audio data is on
  1403. // do not match. Under normal circumstances, where comments are smaller than
  1404. // the nominal 4-8kB page size, then this is not a problem, but if there are
  1405. // very large comments, the only way around it is to strip off the comment
  1406. // tags with vorbiscomment and MD5 that file.
  1407. // This procedure must be applied to ALL Ogg files, not just the ones with
  1408. // comments larger than 1 page, because the below method simply MD5's the
  1409. // whole file with the comments stripped, not just the portion after the
  1410. // comments block (which is the standard getID3() method.
  1411. // The above-mentioned problem of comments spanning multiple pages and changing
  1412. // page sequence numbers likely happens for OggSpeex and OggFLAC as well, but
  1413. // currently vorbiscomment only works on OggVorbis files.
  1414. // phpcs:ignore PHPCompatibility.IniDirectives.RemovedIniDirectives.safe_modeDeprecatedRemoved
  1415. if (preg_match('#(1|ON)#i', ini_get('safe_mode'))) {
  1416. $this->warning('Failed making system call to vorbiscomment.exe - '.$algorithm.'_data is incorrect - error returned: PHP running in Safe Mode (backtick operator not available)');
  1417. $this->info[$algorithm.'_data'] = false;
  1418. } else {
  1419. // Prevent user from aborting script
  1420. $old_abort = ignore_user_abort(true);
  1421. // Create empty file
  1422. $empty = tempnam(GETID3_TEMP_DIR, 'getID3');
  1423. touch($empty);
  1424. // Use vorbiscomment to make temp file without comments
  1425. $temp = tempnam(GETID3_TEMP_DIR, 'getID3');
  1426. $file = $this->info['filenamepath'];
  1427. if (GETID3_OS_ISWINDOWS) {
  1428. if (file_exists(GETID3_HELPERAPPSDIR.'vorbiscomment.exe')) {
  1429. $commandline = '"'.GETID3_HELPERAPPSDIR.'vorbiscomment.exe" -w -c "'.$empty.'" "'.$file.'" "'.$temp.'"';
  1430. $VorbisCommentError = `$commandline`;
  1431. } else {
  1432. $VorbisCommentError = 'vorbiscomment.exe not found in '.GETID3_HELPERAPPSDIR;
  1433. }
  1434. } else {
  1435. $commandline = 'vorbiscomment -w -c '.escapeshellarg($empty).' '.escapeshellarg($file).' '.escapeshellarg($temp).' 2>&1';
  1436. $VorbisCommentError = `$commandline`;
  1437. }
  1438. if (!empty($VorbisCommentError)) {
  1439. $this->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);
  1440. $this->info[$algorithm.'_data'] = false;
  1441. } else {
  1442. // Get hash of newly created file
  1443. switch ($algorithm) {
  1444. case 'md5':
  1445. $this->info[$algorithm.'_data'] = md5_file($temp);
  1446. break;
  1447. case 'sha1':
  1448. $this->info[$algorithm.'_data'] = sha1_file($temp);
  1449. break;
  1450. }
  1451. }
  1452. // Clean up
  1453. unlink($empty);
  1454. unlink($temp);
  1455. // Reset abort setting
  1456. ignore_user_abort($old_abort);
  1457. }
  1458. } else {
  1459. if (!empty($this->info['avdataoffset']) || (isset($this->info['avdataend']) && ($this->info['avdataend'] < $this->info['filesize']))) {
  1460. // get hash from part of file
  1461. $this->info[$algorithm.'_data'] = getid3_lib::hash_data($this->info['filenamepath'], $this->info['avdataoffset'], $this->info['avdataend'], $algorithm);
  1462. } else {
  1463. // get hash from whole file
  1464. switch ($algorithm) {
  1465. case 'md5':
  1466. $this->info[$algorithm.'_data'] = md5_file($this->info['filenamepath']);
  1467. break;
  1468. case 'sha1':
  1469. $this->info[$algorithm.'_data'] = sha1_file($this->info['filenamepath']);
  1470. break;
  1471. }
  1472. }
  1473. }
  1474. return true;
  1475. }
  1476. public function ChannelsBitratePlaytimeCalculations() {
  1477. // set channelmode on audio
  1478. if (!empty($this->info['audio']['channelmode']) || !isset($this->info['audio']['channels'])) {
  1479. // ignore
  1480. } elseif ($this->info['audio']['channels'] == 1) {
  1481. $this->info['audio']['channelmode'] = 'mono';
  1482. } elseif ($this->info['audio']['channels'] == 2) {
  1483. $this->info['audio']['channelmode'] = 'stereo';
  1484. }
  1485. // Calculate combined bitrate - audio + video
  1486. $CombinedBitrate = 0;
  1487. $CombinedBitrate += (isset($this->info['audio']['bitrate']) ? $this->info['audio']['bitrate'] : 0);
  1488. $CombinedBitrate += (isset($this->info['video']['bitrate']) ? $this->info['video']['bitrate'] : 0);
  1489. if (($CombinedBitrate > 0) && empty($this->info['bitrate'])) {
  1490. $this->info['bitrate'] = $CombinedBitrate;
  1491. }
  1492. //if ((isset($this->info['video']) && !isset($this->info['video']['bitrate'])) || (isset($this->info['audio']) && !isset($this->info['audio']['bitrate']))) {
  1493. // // for example, VBR MPEG video files cannot determine video bitrate:
  1494. // // should not set overall bitrate and playtime from audio bitrate only
  1495. // unset($this->info['bitrate']);
  1496. //}
  1497. // video bitrate undetermined, but calculable
  1498. if (isset($this->info['video']['dataformat']) && $this->info['video']['dataformat'] && (!isset($this->info['video']['bitrate']) || ($this->info['video']['bitrate'] == 0))) {
  1499. // if video bitrate not set
  1500. if (isset($this->info['audio']['bitrate']) && ($this->info['audio']['bitrate'] > 0) && ($this->info['audio']['bitrate'] == $this->info['bitrate'])) {
  1501. // AND if audio bitrate is set to same as overall bitrate
  1502. if (isset($this->info['playtime_seconds']) && ($this->info['playtime_seconds'] > 0)) {
  1503. // AND if playtime is set
  1504. if (isset($this->info['avdataend']) && isset($this->info['avdataoffset'])) {
  1505. // AND if AV data offset start/end is known
  1506. // THEN we can calculate the video bitrate
  1507. $this->info['bitrate'] = round((($this->info['avdataend'] - $this->info['avdataoffset']) * 8) / $this->info['playtime_seconds']);
  1508. $this->info['video']['bitrate'] = $this->info['bitrate'] - $this->info['audio']['bitrate'];
  1509. }
  1510. }
  1511. }
  1512. }
  1513. if ((!isset($this->info['playtime_seconds']) || ($this->info['playtime_seconds'] <= 0)) && !empty($this->info['bitrate'])) {
  1514. $this->info['playtime_seconds'] = (($this->info['avdataend'] - $this->info['avdataoffset']) * 8) / $this->info['bitrate'];
  1515. }
  1516. if (!isset($this->info['bitrate']) && !empty($this->info['playtime_seconds'])) {
  1517. $this->info['bitrate'] = (($this->info['avdataend'] - $this->info['avdataoffset']) * 8) / $this->info['playtime_seconds'];
  1518. }
  1519. if (isset($this->info['bitrate']) && empty($this->info['audio']['bitrate']) && empty($this->info['video']['bitrate'])) {
  1520. if (isset($this->info['audio']['dataformat']) && empty($this->info['video']['resolution_x'])) {
  1521. // audio only
  1522. $this->info['audio']['bitrate'] = $this->info['bitrate'];
  1523. } elseif (isset($this->info['video']['resolution_x']) && empty($this->info['audio']['dataformat'])) {
  1524. // video only
  1525. $this->info['video']['bitrate'] = $this->info['bitrate'];
  1526. }
  1527. }
  1528. // Set playtime string
  1529. if (!empty($this->info['playtime_seconds']) && empty($this->info['playtime_string'])) {
  1530. $this->info['playtime_string'] = getid3_lib::PlaytimeString($this->info['playtime_seconds']);
  1531. }
  1532. }
  1533. /**
  1534. * @return bool
  1535. */
  1536. public function CalculateCompressionRatioVideo() {
  1537. if (empty($this->info['video'])) {
  1538. return false;
  1539. }
  1540. if (empty($this->info['video']['resolution_x']) || empty($this->info['video']['resolution_y'])) {
  1541. return false;
  1542. }
  1543. if (empty($this->info['video']['bits_per_sample'])) {
  1544. return false;
  1545. }
  1546. switch ($this->info['video']['dataformat']) {
  1547. case 'bmp':
  1548. case 'gif':
  1549. case 'jpeg':
  1550. case 'jpg':
  1551. case 'png':
  1552. case 'tiff':
  1553. $FrameRate = 1;
  1554. $PlaytimeSeconds = 1;
  1555. $BitrateCompressed = $this->info['filesize'] * 8;
  1556. break;
  1557. default:
  1558. if (!empty($this->info['video']['frame_rate'])) {
  1559. $FrameRate = $this->info['video']['frame_rate'];
  1560. } else {
  1561. return false;
  1562. }
  1563. if (!empty($this->info['playtime_seconds'])) {
  1564. $PlaytimeSeconds = $this->info['playtime_seconds'];
  1565. } else {
  1566. return false;
  1567. }
  1568. if (!empty($this->info['video']['bitrate'])) {
  1569. $BitrateCompressed = $this->info['video']['bitrate'];
  1570. } else {
  1571. return false;
  1572. }
  1573. break;
  1574. }
  1575. $BitrateUncompressed = $this->info['video']['resolution_x'] * $this->info['video']['resolution_y'] * $this->info['video']['bits_per_sample'] * $FrameRate;
  1576. $this->info['video']['compression_ratio'] = $BitrateCompressed / $BitrateUncompressed;
  1577. return true;
  1578. }
  1579. /**
  1580. * @return bool
  1581. */
  1582. public function CalculateCompressionRatioAudio() {
  1583. if (empty($this->info['audio']['bitrate']) || empty($this->info['audio']['channels']) || empty($this->info['audio']['sample_rate']) || !is_numeric($this->info['audio']['sample_rate'])) {
  1584. return false;
  1585. }
  1586. $this->info['audio']['compression_ratio'] = $this->info['audio']['bitrate'] / ($this->info['audio']['channels'] * $this->info['audio']['sample_rate'] * (!empty($this->info['audio']['bits_per_sample']) ? $this->info['audio']['bits_per_sample'] : 16));
  1587. if (!empty($this->info['audio']['streams'])) {
  1588. foreach ($this->info['audio']['streams'] as $streamnumber => $streamdata) {
  1589. if (!empty($streamdata['bitrate']) && !empty($streamdata['channels']) && !empty($streamdata['sample_rate'])) {
  1590. $this->info['audio']['streams'][$streamnumber]['compression_ratio'] = $streamdata['bitrate'] / ($streamdata['channels'] * $streamdata['sample_rate'] * (!empty($streamdata['bits_per_sample']) ? $streamdata['bits_per_sample'] : 16));
  1591. }
  1592. }
  1593. }
  1594. return true;
  1595. }
  1596. /**
  1597. * @return bool
  1598. */
  1599. public function CalculateReplayGain() {
  1600. if (isset($this->info['replay_gain'])) {
  1601. if (!isset($this->info['replay_gain']['reference_volume'])) {
  1602. $this->info['replay_gain']['reference_volume'] = 89.0;
  1603. }
  1604. if (isset($this->info['replay_gain']['track']['adjustment'])) {
  1605. $this->info['replay_gain']['track']['volume'] = $this->info['replay_gain']['reference_volume'] - $this->info['replay_gain']['track']['adjustment'];
  1606. }
  1607. if (isset($this->info['replay_gain']['album']['adjustment'])) {
  1608. $this->info['replay_gain']['album']['volume'] = $this->info['replay_gain']['reference_volume'] - $this->info['replay_gain']['album']['adjustment'];
  1609. }
  1610. if (isset($this->info['replay_gain']['track']['peak'])) {
  1611. $this->info['replay_gain']['track']['max_noclip_gain'] = 0 - getid3_lib::RGADamplitude2dB($this->info['replay_gain']['track']['peak']);
  1612. }
  1613. if (isset($this->info['replay_gain']['album']['peak'])) {
  1614. $this->info['replay_gain']['album']['max_noclip_gain'] = 0 - getid3_lib::RGADamplitude2dB($this->info['replay_gain']['album']['peak']);
  1615. }
  1616. }
  1617. return true;
  1618. }
  1619. /**
  1620. * @return bool
  1621. */
  1622. public function ProcessAudioStreams() {
  1623. if (!empty($this->info['audio']['bitrate']) || !empty($this->info['audio']['channels']) || !empty($this->info['audio']['sample_rate'])) {
  1624. if (!isset($this->info['audio']['streams'])) {
  1625. foreach ($this->info['audio'] as $key => $value) {
  1626. if ($key != 'streams') {
  1627. $this->info['audio']['streams'][0][$key] = $value;
  1628. }
  1629. }
  1630. }
  1631. }
  1632. return true;
  1633. }
  1634. /**
  1635. * @return string|bool
  1636. */
  1637. public function getid3_tempnam() {
  1638. return tempnam($this->tempdir, 'gI3');
  1639. }
  1640. /**
  1641. * @param string $name
  1642. *
  1643. * @return bool
  1644. *
  1645. * @throws getid3_exception
  1646. */
  1647. public function include_module($name) {
  1648. //if (!file_exists($this->include_path.'module.'.$name.'.php')) {
  1649. if (!file_exists(GETID3_INCLUDEPATH.'module.'.$name.'.php')) {
  1650. throw new getid3_exception('Required module.'.$name.'.php is missing.');
  1651. }
  1652. include_once(GETID3_INCLUDEPATH.'module.'.$name.'.php');
  1653. return true;
  1654. }
  1655. /**
  1656. * @param string $filename
  1657. *
  1658. * @return bool
  1659. */
  1660. public static function is_writable ($filename) {
  1661. $ret = is_writable($filename);
  1662. if (!$ret) {
  1663. $perms = fileperms($filename);
  1664. $ret = ($perms & 0x0080) || ($perms & 0x0010) || ($perms & 0x0002);
  1665. }
  1666. return $ret;
  1667. }
  1668. }
  1669. abstract class getid3_handler
  1670. {
  1671. /**
  1672. * @var getID3
  1673. */
  1674. protected $getid3; // pointer
  1675. /**
  1676. * Analyzing filepointer or string.
  1677. *
  1678. * @var bool
  1679. */
  1680. protected $data_string_flag = false;
  1681. /**
  1682. * String to analyze.
  1683. *
  1684. * @var string
  1685. */
  1686. protected $data_string = '';
  1687. /**
  1688. * Seek position in string.
  1689. *
  1690. * @var int
  1691. */
  1692. protected $data_string_position = 0;
  1693. /**
  1694. * String length.
  1695. *
  1696. * @var int
  1697. */
  1698. protected $data_string_length = 0;
  1699. /**
  1700. * @var string
  1701. */
  1702. private $dependency_to;
  1703. /**
  1704. * getid3_handler constructor.
  1705. *
  1706. * @param getID3 $getid3
  1707. * @param string $call_module
  1708. */
  1709. public function __construct(getID3 $getid3, $call_module=null) {
  1710. $this->getid3 = $getid3;
  1711. if ($call_module) {
  1712. $this->dependency_to = str_replace('getid3_', '', $call_module);
  1713. }
  1714. }
  1715. /**
  1716. * Analyze from file pointer.
  1717. *
  1718. * @return bool
  1719. */
  1720. abstract public function Analyze();
  1721. /**
  1722. * Analyze from string instead.
  1723. *
  1724. * @param string $string
  1725. */
  1726. public function AnalyzeString($string) {
  1727. // Enter string mode
  1728. $this->setStringMode($string);
  1729. // Save info
  1730. $saved_avdataoffset = $this->getid3->info['avdataoffset'];
  1731. $saved_avdataend = $this->getid3->info['avdataend'];
  1732. $saved_filesize = (isset($this->getid3->info['filesize']) ? $this->getid3->info['filesize'] : null); // may be not set if called as dependency without openfile() call
  1733. // Reset some info
  1734. $this->getid3->info['avdataoffset'] = 0;
  1735. $this->getid3->info['avdataend'] = $this->getid3->info['filesize'] = $this->data_string_length;
  1736. // Analyze
  1737. $this->Analyze();
  1738. // Restore some info
  1739. $this->getid3->info['avdataoffset'] = $saved_avdataoffset;
  1740. $this->getid3->info['avdataend'] = $saved_avdataend;
  1741. $this->getid3->info['filesize'] = $saved_filesize;
  1742. // Exit string mode
  1743. $this->data_string_flag = false;
  1744. }
  1745. /**
  1746. * @param string $string
  1747. */
  1748. public function setStringMode($string) {
  1749. $this->data_string_flag = true;
  1750. $this->data_string = $string;
  1751. $this->data_string_length = strlen($string);
  1752. }
  1753. /**
  1754. * @return int|bool
  1755. */
  1756. protected function ftell() {
  1757. if ($this->data_string_flag) {
  1758. return $this->data_string_position;
  1759. }
  1760. return ftell($this->getid3->fp);
  1761. }
  1762. /**
  1763. * @param int $bytes
  1764. *
  1765. * @return string|false
  1766. *
  1767. * @throws getid3_exception
  1768. */
  1769. protected function fread($bytes) {
  1770. if ($this->data_string_flag) {
  1771. $this->data_string_position += $bytes;
  1772. return substr($this->data_string, $this->data_string_position - $bytes, $bytes);
  1773. }
  1774. $pos = $this->ftell() + $bytes;
  1775. if (!getid3_lib::intValueSupported($pos)) {
  1776. throw new getid3_exception('cannot fread('.$bytes.' from '.$this->ftell().') because beyond PHP filesystem limit', 10);
  1777. }
  1778. //return fread($this->getid3->fp, $bytes);
  1779. /*
  1780. * https://www.getid3.org/phpBB3/viewtopic.php?t=1930
  1781. * "I found out that the root cause for the problem was how getID3 uses the PHP system function fread().
  1782. * It seems to assume that fread() would always return as many bytes as were requested.
  1783. * However, according the PHP manual (http://php.net/manual/en/function.fread.php), this is the case only with regular local files, but not e.g. with Linux pipes.
  1784. * The call may return only part of the requested data and a new call is needed to get more."
  1785. */
  1786. $contents = '';
  1787. do {
  1788. //if (($this->getid3->memory_limit > 0) && ($bytes > $this->getid3->memory_limit)) {
  1789. if (($this->getid3->memory_limit > 0) && (($bytes / $this->getid3->memory_limit) > 0.99)) { // enable a more-fuzzy match to prevent close misses generating errors like "PHP Fatal error: Allowed memory size of 33554432 bytes exhausted (tried to allocate 33554464 bytes)"
  1790. throw new getid3_exception('cannot fread('.$bytes.' from '.$this->ftell().') that is more than available PHP memory ('.$this->getid3->memory_limit.')', 10);
  1791. }
  1792. $part = fread($this->getid3->fp, $bytes);
  1793. $partLength = strlen($part);
  1794. $bytes -= $partLength;
  1795. $contents .= $part;
  1796. } while (($bytes > 0) && ($partLength > 0));
  1797. return $contents;
  1798. }
  1799. /**
  1800. * @param int $bytes
  1801. * @param int $whence
  1802. *
  1803. * @return int
  1804. *
  1805. * @throws getid3_exception
  1806. */
  1807. protected function fseek($bytes, $whence=SEEK_SET) {
  1808. if ($this->data_string_flag) {
  1809. switch ($whence) {
  1810. case SEEK_SET:
  1811. $this->data_string_position = $bytes;
  1812. break;
  1813. case SEEK_CUR:
  1814. $this->data_string_position += $bytes;
  1815. break;
  1816. case SEEK_END:
  1817. $this->data_string_position = $this->data_string_length + $bytes;
  1818. break;
  1819. }
  1820. return 0;
  1821. } else {
  1822. $pos = $bytes;
  1823. if ($whence == SEEK_CUR) {
  1824. $pos = $this->ftell() + $bytes;
  1825. } elseif ($whence == SEEK_END) {
  1826. $pos = $this->getid3->info['filesize'] + $bytes;
  1827. }
  1828. if (!getid3_lib::intValueSupported($pos)) {
  1829. throw new getid3_exception('cannot fseek('.$pos.') because beyond PHP filesystem limit', 10);
  1830. }
  1831. }
  1832. return fseek($this->getid3->fp, $bytes, $whence);
  1833. }
  1834. /**
  1835. * @return string|false
  1836. *
  1837. * @throws getid3_exception
  1838. */
  1839. protected function fgets() {
  1840. // must be able to handle CR/LF/CRLF but not read more than one lineend
  1841. $buffer = ''; // final string we will return
  1842. $prevchar = ''; // save previously-read character for end-of-line checking
  1843. if ($this->data_string_flag) {
  1844. while (true) {
  1845. $thischar = substr($this->data_string, $this->data_string_position++, 1);
  1846. if (($prevchar == "\r") && ($thischar != "\n")) {
  1847. // read one byte too many, back up
  1848. $this->data_string_position--;
  1849. break;
  1850. }
  1851. $buffer .= $thischar;
  1852. if ($thischar == "\n") {
  1853. break;
  1854. }
  1855. if ($this->data_string_position >= $this->data_string_length) {
  1856. // EOF
  1857. break;
  1858. }
  1859. $prevchar = $thischar;
  1860. }
  1861. } else {
  1862. // Ideally we would just use PHP's fgets() function, however...
  1863. // it does not behave consistently with regards to mixed line endings, may be system-dependent
  1864. // and breaks entirely when given a file with mixed \r vs \n vs \r\n line endings (e.g. some PDFs)
  1865. //return fgets($this->getid3->fp);
  1866. while (true) {
  1867. $thischar = fgetc($this->getid3->fp);
  1868. if (($prevchar == "\r") && ($thischar != "\n")) {
  1869. // read one byte too many, back up
  1870. fseek($this->getid3->fp, -1, SEEK_CUR);
  1871. break;
  1872. }
  1873. $buffer .= $thischar;
  1874. if ($thischar == "\n") {
  1875. break;
  1876. }
  1877. if (feof($this->getid3->fp)) {
  1878. break;
  1879. }
  1880. $prevchar = $thischar;
  1881. }
  1882. }
  1883. return $buffer;
  1884. }
  1885. /**
  1886. * @return bool
  1887. */
  1888. protected function feof() {
  1889. if ($this->data_string_flag) {
  1890. return $this->data_string_position >= $this->data_string_length;
  1891. }
  1892. return feof($this->getid3->fp);
  1893. }
  1894. /**
  1895. * @param string $module
  1896. *
  1897. * @return bool
  1898. */
  1899. final protected function isDependencyFor($module) {
  1900. return $this->dependency_to == $module;
  1901. }
  1902. /**
  1903. * @param string $text
  1904. *
  1905. * @return bool
  1906. */
  1907. protected function error($text) {
  1908. $this->getid3->info['error'][] = $text;
  1909. return false;
  1910. }
  1911. /**
  1912. * @param string $text
  1913. *
  1914. * @return bool
  1915. */
  1916. protected function warning($text) {
  1917. return $this->getid3->warning($text);
  1918. }
  1919. /**
  1920. * @param string $text
  1921. */
  1922. protected function notice($text) {
  1923. // does nothing for now
  1924. }
  1925. /**
  1926. * @param string $name
  1927. * @param int $offset
  1928. * @param int $length
  1929. * @param string $image_mime
  1930. *
  1931. * @return string|null
  1932. *
  1933. * @throws Exception
  1934. * @throws getid3_exception
  1935. */
  1936. public function saveAttachment($name, $offset, $length, $image_mime=null) {
  1937. try {
  1938. // do not extract at all
  1939. if ($this->getid3->option_save_attachments === getID3::ATTACHMENTS_NONE) {
  1940. $attachment = null; // do not set any
  1941. // extract to return array
  1942. } elseif ($this->getid3->option_save_attachments === getID3::ATTACHMENTS_INLINE) {
  1943. $this->fseek($offset);
  1944. $attachment = $this->fread($length); // get whole data in one pass, till it is anyway stored in memory
  1945. if ($attachment === false || strlen($attachment) != $length) {
  1946. throw new Exception('failed to read attachment data');
  1947. }
  1948. // assume directory path is given
  1949. } else {
  1950. // set up destination path
  1951. $dir = rtrim(str_replace(array('/', '\\'), DIRECTORY_SEPARATOR, $this->getid3->option_save_attachments), DIRECTORY_SEPARATOR);
  1952. if (!is_dir($dir) || !getID3::is_writable($dir)) { // check supplied directory
  1953. throw new Exception('supplied path ('.$dir.') does not exist, or is not writable');
  1954. }
  1955. $dest = $dir.DIRECTORY_SEPARATOR.$name.($image_mime ? '.'.getid3_lib::ImageExtFromMime($image_mime) : '');
  1956. // create dest file
  1957. if (($fp_dest = fopen($dest, 'wb')) == false) {
  1958. throw new Exception('failed to create file '.$dest);
  1959. }
  1960. // copy data
  1961. $this->fseek($offset);
  1962. $buffersize = ($this->data_string_flag ? $length : $this->getid3->fread_buffer_size());
  1963. $bytesleft = $length;
  1964. while ($bytesleft > 0) {
  1965. if (($buffer = $this->fread(min($buffersize, $bytesleft))) === false || ($byteswritten = fwrite($fp_dest, $buffer)) === false || ($byteswritten === 0)) {
  1966. throw new Exception($buffer === false ? 'not enough data to read' : 'failed to write to destination file, may be not enough disk space');
  1967. }
  1968. $bytesleft -= $byteswritten;
  1969. }
  1970. fclose($fp_dest);
  1971. $attachment = $dest;
  1972. }
  1973. } catch (Exception $e) {
  1974. // close and remove dest file if created
  1975. if (isset($fp_dest) && is_resource($fp_dest)) {
  1976. fclose($fp_dest);
  1977. }
  1978. if (isset($dest) && file_exists($dest)) {
  1979. unlink($dest);
  1980. }
  1981. // do not set any is case of error
  1982. $attachment = null;
  1983. $this->warning('Failed to extract attachment '.$name.': '.$e->getMessage());
  1984. }
  1985. // seek to the end of attachment
  1986. $this->fseek($offset + $length);
  1987. return $attachment;
  1988. }
  1989. }
  1990. class getid3_exception extends Exception
  1991. {
  1992. public $message;
  1993. }