Skip to content

Commit

Permalink
Merge pull request #403 from StudioMaX/2.0-with-1.9.22-202207161647
Browse files Browse the repository at this point in the history
Sync 2.0 with 1.9.22-202207161647
  • Loading branch information
StudioMaX committed Oct 28, 2022
2 parents b19ed0e + 1ea0196 commit 4e7aca9
Show file tree
Hide file tree
Showing 17 changed files with 341 additions and 56 deletions.
5 changes: 3 additions & 2 deletions .github/workflows/continuous-integration.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,15 @@ jobs:
- "7.4"
- "8.0"
- "8.1"
- "8.2"
steps:
- uses: "actions/checkout@v2"
- uses: "shivammathur/setup-php@v2"
with:
php-version: "${{ matrix.php-version }}"
ini-values: error_reporting=-1, display_errors=On
coverage: "none"
- uses: "ramsey/composer-install@v1"
- uses: "ramsey/composer-install@v2"
- name: "Run the linter"
run: "composer lint -- --colors"

Expand All @@ -41,7 +42,7 @@ jobs:
php-version: "7.4"
tools: "phpstan:0.12.99"
coverage: "none"
- uses: "ramsey/composer-install@v1"
- uses: "ramsey/composer-install@v2"
- name: "Run PHPStan"
run: "phpstan analyse -c phpstan.neon -l 4 src tests"

Expand Down
24 changes: 24 additions & 0 deletions changelog.txt
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,30 @@
Version History
===============

1.9.22: [2022-09-29] James Heinrich :: 1.9.22-202207161647
* bugfix #387 fails to detect h265 video codec (QuickTime)
* bugfix #385 Quicktime extended atom size
* bugfix #378 AAC bitrate cache warning
* bugfix #376 simplexml_load_string improvments
* bugfix #374 MOD improved SoundTracker support
* bugfix #371 fragmented MP4 unsupported warning
* bugfix #369 fix remote URLs pattern
* bugfix #366 change @error-suppress to isset (quicktime)
* bugfix #365 ZIP array offset on value of type int
* bugfix #364 add support for ANIMEXTS1.0 in GIF files
* bugfix #363 ASF improve support of Header Extension Object data
* bugfix #362 version update for ramsey/composer-install
* bugfix #359 MPEG-2 aspect ratio divide-by-zero
* bugfix #358 free format mp3 bitrate
* bugfix #355 undefined array key in ID3v2 chapters
* bugfix #352 avoid false detection of Musepack format
* bugfix #351 Incorrect length passed to fread on a flac file
* bugfix #348 more targeted usage of clearstatcache calls
* bugfix #347 fixed reported by PHPStan v0.12.99
* bugfix QuickTime support 'ID32' frame (ID3v2 inside QT)
* bugfix fix various PHP 8.1 issues
* bugfix PDF prevent undefined index

1.9.21: [2021-09-22] James Heinrich :: 1.9.21-202109171300
» add support for RIFF.guan
¤ add ID3v1 genres 148-191
Expand Down
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@
"php-parallel-lint/php-parallel-lint": "^1.0"
},
"scripts": {
"lint": "parallel-lint --exclude vendor --exclude .git .",
"lint": "parallel-lint --show-deprecated --exclude vendor --exclude .git .",
"test": [
"composer lint"
]
Expand Down
4 changes: 2 additions & 2 deletions readme.txt
Original file line number Diff line number Diff line change
Expand Up @@ -188,8 +188,8 @@ if ($fp_remote = fopen($remotefilename, 'rb')) {
$remote_headers = array_change_key_case(get_headers($remotefilename, 1), CASE_LOWER);
$remote_filesize = (isset($remote_headers['content-length']) ? (is_array($remote_headers['content-length']) ? $remote_headers['content-length'][count($remote_headers['content-length']) - 1] : $remote_headers['content-length']) : null);

// Initialize getID3 engine
$getID3 = new getID3;
// Initialize GetID3 engine
$getID3 = new GetID3;

$ThisFileInfo = $getID3->analyze($localtempfilename, $remote_filesize, basename($remotefilename));

Expand Down
21 changes: 11 additions & 10 deletions src/GetID3.php
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,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 @@ -319,7 +319,7 @@ class GetID3
*/
protected $startup_warning = '';

const VERSION = '2.0.x-202112151109';
const VERSION = '2.0.x-202207161647';
const FREAD_BUFFER_SIZE = 32768;

const ATTACHMENTS_NONE = false;
Expand Down Expand Up @@ -887,14 +887,15 @@ 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)',
// 'module' => 'Audio\\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\\.)',
'module' => 'Audio\\Mod',
'option' => 'mod',
'mime_type' => 'audio/mod',
),

// MOD - audio - MODule (Impulse Tracker)
'it' => array(
Expand Down
2 changes: 1 addition & 1 deletion src/Module/Archive/Zip.php
Original file line number Diff line number Diff line change
Expand Up @@ -297,7 +297,7 @@ public function ZIPparseLocalFileHeader() {
$DataDescriptor = $this->fread(16);
$LocalFileHeader['data_descriptor']['signature'] = Utils::LittleEndian2Int(substr($DataDescriptor, 0, 4));
if ($LocalFileHeader['data_descriptor']['signature'] != 0x08074B50) { // "PK\x07\x08"
$this->getid3->warning('invalid Local File Header Data Descriptor Signature at offset '.($this->ftell() - 16).' - expecting 08 07 4B 50, found '.Utils::PrintHexBytes($LocalFileHeader['data_descriptor']['signature']));
$this->getid3->warning('invalid Local File Header Data Descriptor Signature at offset '.($this->ftell() - 16).' - expecting 08 07 4B 50, found '.Utils::PrintHexBytes(substr($DataDescriptor, 0, 4)));
$this->fseek($LocalFileHeader['offset']); // seek back to where filepointer originally was so it can be handled properly
return false;
}
Expand Down
2 changes: 1 addition & 1 deletion src/Module/Audio/Aac.php
Original file line number Diff line number Diff line change
Expand Up @@ -400,7 +400,7 @@ public function getAACADTSheaderFilepointer($MaxFramesToScan=1000000, $ReturnExt
if (!isset($BitrateCache[$FrameLength])) {
$BitrateCache[$FrameLength] = ($info['aac']['header']['sample_frequency'] / 1024) * $FrameLength * 8;
}
Utils::safe_inc($info['aac']['bitrate_distribution'][$BitrateCache[$FrameLength]], 1);
Utils::safe_inc($info['aac']['bitrate_distribution'][(string)$BitrateCache[$FrameLength]], 1);

$info['aac'][$framenumber]['aac_frame_length'] = $FrameLength;

Expand Down
58 changes: 49 additions & 9 deletions src/Module/Audio/Mod.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
/////////////////////////////////////////////////////////////////

use JamesHeinrich\GetID3\Module\Handler;
use JamesHeinrich\GetID3\Utils;

class Mod extends Handler
{
Expand All @@ -30,9 +31,17 @@ public function Analyze() {
return $this->getITheaderFilepointer();
} elseif (preg_match('#^Extended Module#', $fileheader)) {
return $this->getXMheaderFilepointer();
} elseif (preg_match('#^.{44}SCRM#', $fileheader)) {
} elseif (preg_match('#^.{44}SCRM#s', $fileheader)) {
return $this->getS3MheaderFilepointer();
} elseif (preg_match('#^.{1080}(M\\.K\\.|M!K!|FLT4|FLT8|[5-9]CHN|[1-3][0-9]CH)#', $fileheader)) {
//} elseif (preg_match('#^.{1080}(M\\.K\\.|M!K!|FLT4|FLT8|[5-9]CHN|[1-3][0-9]CH)#s', $fileheader)) {
} elseif (preg_match('#^.{1080}(M\\.K\\.)#s', $fileheader)) {
/*
The four letters "M.K." - This is something Mahoney & Kaktus inserted when they
increased the number of samples from 15 to 31. If it's not there, the module/song
uses 15 samples or the text has been removed to make the module harder to rip.
Startrekker puts "FLT4" or "FLT8" there instead.
If there are more than 64 patterns, PT2.3 will insert M!K! here.
*/
return $this->getMODheaderFilepointer();
}
$this->error('This is not a known type of MOD file');
Expand All @@ -44,17 +53,48 @@ public function Analyze() {
*/
public function getMODheaderFilepointer() {
$info = &$this->getid3->info;
$this->fseek($info['avdataoffset'] + 1080);
$FormatID = $this->fread(4);
if (!preg_match('#^(M.K.|[5-9]CHN|[1-3][0-9]CH)$#', $FormatID)) {
$this->error('This is not a known type of MOD file');
$this->fseek($info['avdataoffset']);
$filedata = $this->fread(1084);
//if (!preg_match('#^(M.K.|[5-9]CHN|[1-3][0-9]CH)$#', $FormatID)) {
if (substr($filedata, 1080, 4) == 'M.K.') {

// + 0 song/module working title
// + 20 15 sample headers (see below)
// + 470 song length (number of steps in pattern table)
// + 471 song speed in beats per minute (see below)
// + 472 pattern step table
$offset = 0;
$info['mod']['title'] = rtrim(substr($filedata, $offset, 20), "\x00"); $offset += 20;

$info['tags']['mod']['title'] = array($info['mod']['title']);

for ($samplenumber = 0; $samplenumber <= 30; $samplenumber++) {
$sampledata = array();
$sampledata['name'] = substr($filedata, $offset, 22); $offset += 22;
$sampledata['length'] = Utils::BigEndian2Int(substr($filedata, $offset, 2)); $offset += 2;
$sampledata['volume'] = Utils::BigEndian2Int(substr($filedata, $offset, 2)); $offset += 2;
$sampledata['repeat_offset'] = Utils::BigEndian2Int(substr($filedata, $offset, 2)); $offset += 2;
$sampledata['repeat_length'] = Utils::BigEndian2Int(substr($filedata, $offset, 2)); $offset += 2;
$info['mod']['samples'][$samplenumber] = $sampledata;
}

$info['mod']['song_length'] = Utils::BigEndian2Int(substr($filedata, $offset++, 1));// Songlength. Range is 1-128.
$info['mod']['bpm'] = Utils::BigEndian2Int(substr($filedata, $offset++, 1));// This byte is set to 127, so that old trackers will search through all patterns when loading. Noisetracker uses this byte for restart, ProTracker doesn't.

for ($songposition = 0; $songposition <= 127; $songposition++) {
// Song positions 0-127. Each hold a number from 0-63 (or 0-127)
// that tells the tracker what pattern to play at that position.
$info['mod']['song_positions'][$songposition] = Utils::BigEndian2Int(substr($filedata, $offset++, 1));
}

} else {
$this->error('unknown MOD ID at offset 1080: '.Utils::PrintHexBytes(substr($filedata, 1080, 4)));
return false;
}

$info['fileformat'] = 'mod';

$this->error('MOD parsing not enabled in this version of getID3() ['.$this->getid3->version().']');
return false;
$this->warning('MOD (SoundTracker) parsing incomplete in this version of getID3() ['.$this->getid3->version().']');
return true;
}

/**
Expand Down
11 changes: 8 additions & 3 deletions src/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
// http://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'] = Utils::BigEndian2Int(substr($headerstring, $LAMEtagOffsetContant + 0xA6, 1)) * 100;

// bytes $A7-$AE Replay Gain
// http://privatewww.essex.ac.uk/~djmrob/replaygain/rg_data_format.html
// https://web.archive.org/web/20021015212753/http://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
2 changes: 1 addition & 1 deletion src/Module/Audio/Ogg.php
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,7 @@ public function Analyze() {
if ($info['ogg']['pageheader']['theora']['pixel_aspect_denominator'] > 0) {
$info['video']['pixel_aspect_ratio'] = (float) $info['ogg']['pageheader']['theora']['pixel_aspect_numerator'] / $info['ogg']['pageheader']['theora']['pixel_aspect_denominator'];
}
$this->warning('Ogg Theora (v3) not fully supported in this version of getID3 ['.$this->getid3->version().'] -- bitrate, playtime and all audio data are currently unavailable');
$this->warning('Ogg Theora (v3) not fully supported in this version of getID3 ['.$this->getid3->version().'] -- bitrate, playtime and all audio data are currently unavailable');


} elseif (substr($filedata, 0, 8) == "fishead\x00") {
Expand Down
Loading

0 comments on commit 4e7aca9

Please sign in to comment.