Skip to content

Commit

Permalink
Merge pull request #173 from Rello/patch-1
Browse files Browse the repository at this point in the history
Add filepointer option to analyze/openfile function
  • Loading branch information
JamesHeinrich authored Dec 4, 2018
2 parents 9812c27 + 5195fbd commit a388653
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 13 deletions.
10 changes: 6 additions & 4 deletions getid3/getid3.php
Original file line number Diff line number Diff line change
Expand Up @@ -406,7 +406,7 @@ public function setOption($optArray) {
*
* @throws getid3_exception
*/
public function openfile($filename, $filesize=null) {
public function openfile($filename, $filesize=null, $fp=null) {
try {
if (!empty($this->startup_error)) {
throw new getid3_exception($this->startup_error);
Expand All @@ -433,7 +433,9 @@ public function openfile($filename, $filesize=null) {

// open local file
//if (is_readable($filename) && is_file($filename) && ($this->fp = fopen($filename, 'rb'))) { // see https://www.getid3.org/phpBB3/viewtopic.php?t=1720
if ((is_readable($filename) || file_exists($filename)) && is_file($filename) && ($this->fp = fopen($filename, 'rb'))) {
if (($fp != null) && ((get_resource_type($fp) == 'file') || (get_resource_type($fp) == 'stream'))) {
$this->fp = $fp;
} else if ((is_readable($filename) || file_exists($filename)) && is_file($filename) && ($this->fp = fopen($filename, 'rb'))) {
// great
} else {
$errormessagelist = array();
Expand Down Expand Up @@ -514,9 +516,9 @@ public function openfile($filename, $filesize=null) {
*
* @return array
*/
public function analyze($filename, $filesize=null, $original_filename='') {
public function analyze($filename, $filesize=null, $original_filename='', $fp=null) {
try {
if (!$this->openfile($filename, $filesize)) {
if (!$this->openfile($filename, $filesize, $fp)) {
return $this->info;
}

Expand Down
18 changes: 9 additions & 9 deletions getid3/module.audio-video.riff.php
Original file line number Diff line number Diff line change
Expand Up @@ -1066,7 +1066,7 @@ public function Analyze() {
if (isset($thisfile_riff[$RIFFsubtype]['ID3 '])) {
getid3_lib::IncludeDependency(GETID3_INCLUDEPATH.'module.tag.id3v2.php', __FILE__, true);
$getid3_temp = new getID3();
$getid3_temp->openfile($this->getid3->filename);
$getid3_temp->openfile($this->getid3->filename, null, $this->getid3->fp);
$getid3_id3v2 = new getid3_id3v2($getid3_temp);
$getid3_id3v2->StartingOffset = $thisfile_riff[$RIFFsubtype]['ID3 '][0]['offset'] + 8;
if ($thisfile_riff[$RIFFsubtype]['ID3 '][0]['valid'] = $getid3_id3v2->Analyze()) {
Expand Down Expand Up @@ -1169,7 +1169,7 @@ public function Analyze() {
getid3_lib::IncludeDependency(GETID3_INCLUDEPATH.'module.audio-video.mpeg.php', __FILE__, true);

$getid3_temp = new getID3();
$getid3_temp->openfile($this->getid3->filename);
$getid3_temp->openfile($this->getid3->filename, null, $this->getid3->fp);
$getid3_mpeg = new getid3_mpeg($getid3_temp);
$getid3_mpeg->Analyze();
if (empty($getid3_temp->info['error'])) {
Expand Down Expand Up @@ -1255,7 +1255,7 @@ public function Analyze() {
getid3_lib::IncludeDependency(GETID3_INCLUDEPATH.'module.tag.id3v2.php', __FILE__, true);

$getid3_temp = new getID3();
$getid3_temp->openfile($this->getid3->filename);
$getid3_temp->openfile($this->getid3->filename, null, $this->getid3->fp);
$getid3_id3v2 = new getid3_id3v2($getid3_temp);
$getid3_id3v2->StartingOffset = $thisfile_riff[$RIFFsubtype]['id3 '][0]['offset'] + 8;
if ($thisfile_riff[$RIFFsubtype]['id3 '][0]['valid'] = $getid3_id3v2->Analyze()) {
Expand Down Expand Up @@ -1554,7 +1554,7 @@ public function ParseRIFF($startoffset, $maxoffset) {
// MP3
if (getid3_mp3::MPEGaudioHeaderBytesValid($FirstFourBytes)) {
$getid3_temp = new getID3();
$getid3_temp->openfile($this->getid3->filename);
$getid3_temp->openfile($this->getid3->filename, null, $this->getid3->fp);
$getid3_temp->info['avdataoffset'] = $this->ftell() - 4;
$getid3_temp->info['avdataend'] = $this->ftell() + $AudioChunkSize;
$getid3_mp3 = new getid3_mp3($getid3_temp, __CLASS__);
Expand All @@ -1576,7 +1576,7 @@ public function ParseRIFF($startoffset, $maxoffset) {

// AC3
$getid3_temp = new getID3();
$getid3_temp->openfile($this->getid3->filename);
$getid3_temp->openfile($this->getid3->filename, null, $this->getid3->fp);
$getid3_temp->info['avdataoffset'] = $this->ftell() - 4;
$getid3_temp->info['avdataend'] = $this->ftell() + $AudioChunkSize;
$getid3_ac3 = new getid3_ac3($getid3_temp);
Expand Down Expand Up @@ -1637,7 +1637,7 @@ public function ParseRIFF($startoffset, $maxoffset) {
// Probably is MP3 data
if (getid3_mp3::MPEGaudioHeaderBytesValid(substr($testData, 0, 4))) {
$getid3_temp = new getID3();
$getid3_temp->openfile($this->getid3->filename);
$getid3_temp->openfile($this->getid3->filename, null, $this->getid3->fp);
$getid3_temp->info['avdataoffset'] = $info['avdataoffset'];
$getid3_temp->info['avdataend'] = $info['avdataend'];
$getid3_mp3 = new getid3_mp3($getid3_temp, __CLASS__);
Expand All @@ -1654,7 +1654,7 @@ public function ParseRIFF($startoffset, $maxoffset) {
// This is probably AC-3 data
$getid3_temp = new getID3();
if ($isRegularAC3) {
$getid3_temp->openfile($this->getid3->filename);
$getid3_temp->openfile($this->getid3->filename, null, $this->getid3->fp);
$getid3_temp->info['avdataoffset'] = $info['avdataoffset'];
$getid3_temp->info['avdataend'] = $info['avdataend'];
}
Expand Down Expand Up @@ -1688,7 +1688,7 @@ public function ParseRIFF($startoffset, $maxoffset) {

// This is probably DTS data
$getid3_temp = new getID3();
$getid3_temp->openfile($this->getid3->filename);
$getid3_temp->openfile($this->getid3->filename, null, $this->getid3->fp);
$getid3_temp->info['avdataoffset'] = $info['avdataoffset'];
$getid3_dts = new getid3_dts($getid3_temp);
$getid3_dts->Analyze();
Expand Down Expand Up @@ -1811,7 +1811,7 @@ public function ParseRIFFdata(&$RIFFdata) {
fclose($fp_temp);

$getid3_temp = new getID3();
$getid3_temp->openfile($tempfile);
$getid3_temp->openfile($tempfile, null, $this->getid3->fp);
$getid3_temp->info['filesize'] = $RIFFdataLength;
$getid3_temp->info['filenamepath'] = $info['filenamepath'];
$getid3_temp->info['tags'] = $info['tags'];
Expand Down

0 comments on commit a388653

Please sign in to comment.