Skip to content

Commit

Permalink
Minor updates to getID3 so that I can sync up on a pull request to fi…
Browse files Browse the repository at this point in the history
…x a bug upstream
  • Loading branch information
ben-xo committed Apr 18, 2022
1 parent 55b8f73 commit 7869181
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 16 deletions.
9 changes: 8 additions & 1 deletion External/getID3/getid3.lib.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,13 @@
// ///
/////////////////////////////////////////////////////////////////

if(!defined('GETID3_LIBXML_OPTIONS') && defined('LIBXML_VERSION')) {
if(LIBXML_VERSION >= 20621) {
define('GETID3_LIBXML_OPTIONS', LIBXML_NOENT | LIBXML_NONET | LIBXML_NOWARNING | LIBXML_COMPACT);
} else {
define('GETID3_LIBXML_OPTIONS', LIBXML_NOENT | LIBXML_NONET | LIBXML_NOWARNING);
}
}

class getid3_lib
{
Expand Down Expand Up @@ -731,7 +738,7 @@ public static function XML2array($XMLstring) {
// This function has been deprecated in PHP 8.0 because in libxml 2.9.0, external entity loading is
// disabled by default, but is still needed when LIBXML_NOENT is used.
$loader = @libxml_disable_entity_loader(true);
$XMLobject = simplexml_load_string($XMLstring, 'SimpleXMLElement', LIBXML_NOENT);
$XMLobject = simplexml_load_string($XMLstring, 'SimpleXMLElement', GETID3_LIBXML_OPTIONS);
$return = self::SimpleXMLelement2array($XMLobject);
@libxml_disable_entity_loader($loader);
return $return;
Expand Down
25 changes: 13 additions & 12 deletions External/getID3/getid3.php
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,7 @@ class getID3
public $option_md5_data = false;

/**
* Use MD5 of source file if availble - only FLAC and OptimFROG
* Use MD5 of source file if available - only FLAC and OptimFROG
*
* @var bool
*/
Expand Down Expand Up @@ -387,7 +387,7 @@ class getID3
*/
protected $startup_warning = '';

const VERSION = '1.9.21-202112151109';
const VERSION = '1.9.21-202204141319';
const FREAD_BUFFER_SIZE = 32768;

const ATTACHMENTS_NONE = false;
Expand Down Expand Up @@ -568,7 +568,7 @@ public function openfile($filename, $filesize=null, $fp=null) {
$this->info['php_memory_limit'] = (($this->memory_limit > 0) ? $this->memory_limit : false);

// remote files not supported
if (preg_match('#^(ht|f)tp:https://#', $filename)) {
if (preg_match('#^(ht|f)tps?:https://#', $filename)) {
throw new getid3_exception('Remote files are not supported - please copy the file locally first');
}

Expand Down Expand Up @@ -1054,15 +1054,16 @@ public function GetFileFormatArray() {
'mime_type' => 'audio/x-monkeys-audio',
),

// has been known to produce false matches in random files (e.g. JPEGs), leave out until more precise matching available
// // MOD - audio - MODule (assorted sub-formats)
// 'mod' => array(
// 'pattern' => '^.{1080}(M\\.K\\.|M!K!|FLT4|FLT8|[5-9]CHN|[1-3][0-9]CH)',
// 'group' => 'audio',
// 'module' => 'mod',
// 'option' => 'mod',
// 'mime_type' => 'audio/mod',
// ),

// MOD - audio - MODule (SoundTracker)
'mod' => array(
//'pattern' => '^.{1080}(M\\.K\\.|M!K!|FLT4|FLT8|[5-9]CHN|[1-3][0-9]CH)', // has been known to produce false matches in random files (e.g. JPEGs), leave out until more precise matching available
'pattern' => '^.{1080}(M\\.K\\.)',
'group' => 'audio',
'module' => 'mod',
'option' => 'mod',
'mime_type' => 'audio/mod',
),

// MOD - audio - MODule (Impulse Tracker)
'it' => array(
Expand Down
11 changes: 8 additions & 3 deletions External/getID3/module.audio.mp3.php
Original file line number Diff line number Diff line change
Expand Up @@ -315,6 +315,10 @@ public function GuessEncoderOptions() {
$encoder_options .= ' -b'.$thisfile_mpeg_audio_lame['bitrate_min'];
}

if (isset($thisfile_mpeg_audio['bitrate']) && $thisfile_mpeg_audio['bitrate'] === 'free') {
$encoder_options .= ' --freeformat';
}

if (!empty($thisfile_mpeg_audio_lame['encoding_flags']['nogap_prev']) || !empty($thisfile_mpeg_audio_lame['encoding_flags']['nogap_next'])) {
$encoder_options .= ' --nogap';
}
Expand Down Expand Up @@ -750,7 +754,8 @@ public function decodeMPEGaudioHeader($offset, &$info, $recursivesearch=true, $S
unset($thisfile_mpeg_audio_lame['long_version']);

// It the LAME tag was only introduced in LAME v3.90
// https://www.hydrogenaudio.org/?act=ST&f=15&t=9933
// https://wiki.hydrogenaud.io/index.php/LAME#VBR_header_and_LAME_tag
// https://hydrogenaud.io/index.php?topic=9933

// Offsets of various bytes in http://gabriel.mp3-tech.org/mp3infotag.html
// are assuming a 'Xing' identifier offset of 0x24, which is the case for
Expand Down Expand Up @@ -786,7 +791,7 @@ public function decodeMPEGaudioHeader($offset, &$info, $recursivesearch=true, $S
$thisfile_mpeg_audio_lame['lowpass_frequency'] = getid3_lib::BigEndian2Int(substr($headerstring, $LAMEtagOffsetContant + 0xA6, 1)) * 100;

// bytes $A7-$AE Replay Gain
// https://privatewww.essex.ac.uk/~djmrob/replaygain/rg_data_format.html
// https://web.archive.org/web/20021015212753/https://privatewww.essex.ac.uk/~djmrob/replaygain/rg_data_format.html
// bytes $A7-$AA : 32 bit floating point "Peak signal amplitude"
if ($thisfile_mpeg_audio_lame['short_version'] >= 'LAME3.94b') {
// LAME 3.94a16 and later - 9.23 fixed point
Expand Down Expand Up @@ -914,7 +919,7 @@ public function decodeMPEGaudioHeader($offset, &$info, $recursivesearch=true, $S


// LAME CBR
if ($thisfile_mpeg_audio_lame_raw['vbr_method'] == 1) {
if ($thisfile_mpeg_audio_lame_raw['vbr_method'] == 1 && $thisfile_mpeg_audio['bitrate'] !== 'free') {

$thisfile_mpeg_audio['bitrate_mode'] = 'cbr';
$thisfile_mpeg_audio['bitrate'] = self::ClosestStandardMP3Bitrate($thisfile_mpeg_audio['bitrate']);
Expand Down

0 comments on commit 7869181

Please sign in to comment.