How to use getid3, if content will be in MySQL?

The place for "I can't figure out how to..." questions.

How to use getid3, if content will be in MySQL?

Postby ERET1K » Sun Oct 27, 2013 8:40 am

I want to use getid3, but my audio content will be in data base (MySQL).
How i can to use getid3 in this situation?
ERET1K
User
 
Posts: 1
Joined: Sun Oct 27, 2013 8:30 am

Re: How to use getid3, if content will be in MySQL?

Postby James Heinrich » Tue Oct 29, 2013 1:51 pm

getID3 is very much file-based, so the easiest way would be to pull the audio data out of your database into a temporary file, analyze it, and I would recommend storing the analysis results back in the same database table so you won't have to analyze one row more than once, and/or you can clear the analysis field if the audio content is changed.

For example:
Code: Select all
$result = mysql_query("SELECT `audiodata`, `getid3_analysis` FROM `audiotable` WHERE `id` = ".intval($_REQUEST['id']);
if ($row = mysql_fetch_assoc($result)) {
   if (is_null($row['getid3_analysis'])) {
      // only call analyze if no previous analysis is available
      require_once('path/to/getid3/getid3.php');
      $getID3 = new getID3;
      $temp_filename = tempnam(GETID3_TEMP_DIR, 'getID3');
      file_put_contents($temp_filename, $row['audiodata']);
      $ThisFileInfo = $getID3->analyze($temp_filename);
      unlink($temp_filename);
      
      // store analysis results so next time this row is accessed getID3 does not need to be called again
      mysql_query("UPDATE `audiotable` SET `getid3_analysis` = '".mysql_real_escape_string(serialize($ThisFileInfo))."' WHERE `id` = ".intval($_REQUEST['id']);
   } else {
      $ThisFileInfo = unserialize($row['getid3_analysis']);
   }
   echo 'File is '.htmlspecialchars($ThisFileInfo['dataformat']).' format and '.htmlspecialchars($ThisFileInfo['playtime_string']).' long.';
} else {
   echo 'Failed to find file #'.intval($_REQUEST['id']);
}
James Heinrich
getID3() v1 developer
 
Posts: 1411
Joined: Fri May 04, 2001 4:00 pm
Location: Northern Ontario, Canada


Return to Support 1.x

Who is online

Users browsing this forum: No registered users and 1 guest

cron