getid3 returning empty arrays

Locked
preahkumpii
User
Posts: 2
Joined: Tue Sep 10, 2013 2:21 am
Are you a spambot?: no

getid3 returning empty arrays

Post by preahkumpii » Tue Sep 10, 2013 2:26 am

Here is my code:

Code: Select all

<?php
require_once('getid3/getid3.php');
function listSongs() {
	
	$dir    = 'audio/';
	$files = scandir($dir);
	$ignore = array(".", "..", ".DS_Store");
	
	foreach ($files as $curfile) {
		if (!in_array($curfile, $ignore)) {
			
			$getID3 = new getID3;
			$tag = $getID3->analyze($curfile);
			getid3_lib::CopyTagsToComments($tag);
			
			echo "<tr data-url='audio/" . $curfile . "'><td>" . $curfile . "</td><td>" . $tag['audio']['bitrate'] . "</td><td>" . $tag['playtime_string'] . "</td></tr>";
			
		}
	}
} 
?>
I am simply copy and pasting code from the demo.basic.php file. getid3 appears to be returning empty in the $tag['audio']['bitrate'] and $tag['playtime_string']. I have no idea why. I am not getting any errors that I can tell. Any help is appreciated.

James Heinrich
getID3() v1 developer
Posts: 1457
Joined: Fri May 04, 2001 4:00 pm
Are you a spambot?: no
Location: Northern Ontario, Canada
Contact:

Re: getid3 returning empty arrays

Post by James Heinrich » Tue Sep 10, 2013 7:31 am

You should examine $tag['warning'] and $tag['error'] -- warnings are minor errors that don't usually prevent the file from being fully analyzed, errors are serious and usually prevent any useful information from being obtained (e.g. "file not found").

Code: Select all

<?php
require_once('getid3/getid3.php');
function listSongs() {
   
   $dir    = 'audio/';
   $files = scandir($dir);
   $ignore = array(".", "..", ".DS_Store");
   
   foreach ($files as $curfile) {
      if (!in_array($curfile, $ignore)) {
         
         $getID3 = new getID3;
         $tag = $getID3->analyze($curfile);
         getid3_lib::CopyTagsToComments($tag);
         
if (!empty($tag['error'])) {
  echo "<tr data-url='audio/" . $curfile . "'><td>" . $curfile . "</td><td colspan="2">Errors:<ul><li>" . implode("</li><li>", $tag['error'] . "</li></ul></td></tr>";
} else {
         echo "<tr data-url='audio/" . $curfile . "'><td>" . $curfile . "</td><td>" . $tag['audio']['bitrate'] . "</td><td>" . $tag['playtime_string'] . "</td>" . (!empty($tag['warning']) ? "<td>Warnings:<ul><li>" . implode("</li><li>", $tag['warning'] . "</li></ul></td>" : "") . "</tr>";
}
         
      }
   }
}
Of course, at any time you could do something like echo '<pre>'.htmlentities(print_r($tag, true)).'</pre>'; to see the full contents of what's being returned, if you're not sure where the data is you're looking for. demo.browse.php is also a great tool (in your browser) to browse through files and see exactly where data is sitting.

preahkumpii
User
Posts: 2
Joined: Tue Sep 10, 2013 2:21 am
Are you a spambot?: no

Re: getid3 returning empty arrays

Post by preahkumpii » Tue Sep 10, 2013 10:05 am

I found the problem. I didn't realize that my $curfile was not sending the entire path to getid3(), but only the file name. Since the file was not in the directory, it was coming back empty. Thanks James for showing me how to output the error, which is how I found it.

Locked