/** * Extract information - only public function * * @access public * @param string file Audio file to extract info from. */ function Info($file) { // Too many mp3 encoders on the market put gabage in front of mpeg files - use assume format on these $assume_mpeg = eregi('\\.mp[123a]$', $file); // Extract info with GetAllFileInfo() - in this example we want MD5data (fourth param). // If MD5data is not needed, set to FALSE for performance improvement. $this->info = GetAllFileInfo($file, $assume_mpeg ? 'mp3' : '', FALSE, TRUE); //dump($this->info, false); // Exit here on error if (isset($this->info['error'])) { return array('error' => $this->info['error']); } // Init wrapper object $this->result = array(); $this->result['format_name'] = @$this->info['fileformat'] . '/' . @$this->info['audio']['dataformat'] . (isset($this->info['video']['dataformat']) ? '/' . @$this->info['video']['dataformat'] : ''); $this->result['encoder_version'] = @$this->info['audio']['encoder']; $this->result['encoder_options'] = NULL; $this->result['bitrate_mode'] = @$this->info['audio']['bitrate_mode']; $this->result['channels'] = @$this->info['audio']['channels']; $this->result['sample_rate'] = @$this->info['audio']['sample_rate']; $this->result['bits_per_sample'] = @$this->info['audio']['bits_per_sample']; $this->result['playing_time'] = @$this->info['playtime_seconds']; $this->result['avg_bit_rate'] = @$this->info['audio']['bitrate']; $this->result['tags'] = @$this->info['tags']; $this->result['comments'] = @$this->info['comments']; $this->result['warning'] = @$this->info['warning']; $this->result['md5'] = @$this->info['md5_data']; // Post getID3() data handling based on file format $method = @$this->info['fileformat'] . 'Info'; if (@$this->info['fileformat'] && method_exists($this, $method)) { $this->{$method}(); } return $this->result; }
function add($item) { $mp3info = GetAllFileInfo($item['path']); //debug('mp3info', $mp3info); $bitrate = (string) $mp3info['audio']['bitrate']; if (!$bitrate) { raiseError("Could not determine bitrate, maybe this is not an audio file: " . $item['path']); } $item['bitrate'] = $bitrate; $this->audioFiles[] = $item; }
/** * Adds a file to the list. * * @param string $path Path of the file to add to the list * @return boolean If the file was successfully added to the list return true, else false */ function add($path) { $path = realpath(trim($path)); if (is_file($path)) { if (!$this->pathExist($path)) { $audioinfo = GetAllFileInfo($path); if (isset($audioinfo["audio"])) { $this->list[] =& new sotf_AudioFile($path); } else { $this->list[] =& new sotf_File($path); } } } return false; }
function add($item) { global $config; if ($item['url']) { // this is a remote file if ($config['httpStreaming']) { $lines = file($item['url']); foreach ($lines as $line) { if (!empty($line)) { $this->audioFiles[] = array('url' => $line); } } } else { // nothing to do // not tested for Tamburine } } else { // this is a local file $mp3info = GetAllFileInfo($item['path']); //debug('mp3info', $mp3info); $bitrate = (string) $mp3info['audio']['bitrate']; if (!$bitrate) { raiseError("Could not determine bitrate, maybe this audio is temporarily unavailable"); } $item['bitrate'] = $bitrate; if ($config['httpStreaming']) { //$tmpFileName = 'au_' . $item['id'] . '_' . ($item['name'] ? $item['name'] : basename($item['path'])); $tmpFileName = 'au_' . $item['id'] . '_' . basename($item['path']); $tmpFile = $config['tmpDir'] . "/{$tmpFileName}"; $file = @readlink($tmpFile); if ($file) { if (!is_readable($file)) { logError("Bad symlink: {$tmpFile} to {$file}"); unlink($tmpFile); $file = false; } } if (!$file) { if (!symlink($item['path'], $tmpFile)) { raiseError("symlink failed in tmp dir"); } } $item['url'] = $config['tmpUrl'] . "/{$tmpFileName}"; } $this->totalLength += $mp3info["playtime_seconds"]; $this->audioFiles[] = $item; } }
/** * Sets up sotf_AudioFile object * * @constructor sotf_AudioFile * @param string $path Path of the file */ function sotf_AudioFile($path) { $parent = get_parent_class($this); parent::$parent($path); // Call the constructor of the parent class. lk. super() $fileinfo = GetAllFileInfo($this->path); //if ($audioinfo["fileformat"] == 'mp3' || $audioinfo["fileformat"] == 'ogg') { debug("finfo", $fileinfo); if (isset($fileinfo['audio'])) { $audioinfo = $fileinfo['audio']; $this->type = "audio"; $this->format = $fileinfo["fileformat"]; if ($audioinfo["bitrate_mode"] == 'vbr') { $this->bitrate = "VBR"; } $this->bitrate = round($audioinfo["bitrate"] / 1000); $this->average_bitrate = round($audioinfo["bitrate"] / 1000); $this->samplerate = $audioinfo["sample_rate"]; $this->channels = $audioinfo["channels"]; $this->duration = round($fileinfo["playtime_seconds"]); $this->mimetype = $this->determineMimeType($this->format); } }
function get_file_info($name, $return_finfo = false) { global $streamtypes, $cfg; $ret = gen_file_header(); $ret['ftypeid'] = file_type($name); $finfo = null; if ($cfg['enablegetid3']) { if (GETID3_V == 16) { $finfo = GetAllFileInfo($name, file_extension($name)); if (isset($finfo['tags']) && is_array($finfo['tags'])) { $use = ''; foreach ($finfo['tags'] as $tagroot) { $use = $tagroot; if ($use == 'id3v2') { break; } // prefer id3v2. } } $ret['bitrate'] = isset($finfo['bitrate']) ? round($finfo['bitrate']) / 1000 : 0; $ret['ratemode'] = isset($finfo['audio']['bitrate_mode']) ? ratetypeid($finfo['audio']['bitrate_mode']) : 0; $ret['length'] = isset($finfo['playtime_string']) ? $finfo['playtime_string'] : '00:00'; $ret['lengths'] = isset($finfo['playtime_seconds']) ? (int) round($finfo['playtime_seconds']) : 0; if (!empty($use) && @is_array($finfo[$use])) { if ($use == 'id3v2' && isset($finfo['id3v1'])) { $order = getid3order(); foreach ($order as $idtag) { switch ($idtag) { case 1: array_fetch($finfo['id3v1'], $ret); break; case 2: array_fetch($finfo[$use]['comments'], $ret); break; } } } else { if ($use == 'id3v2') { array_fetch($finfo[$use]['comments'], $ret); } else { array_fetch($finfo[$use], $ret); } } } else { if (@is_array($finfo['comments'])) { array_fetch($finfo['comments'], $ret); } } } else { if (GETID3_V == 17 || GETID3_V == 19) { $getID3 = new getID3(); if (UTF8MODE) { $getID3->encoding = 'UTF-8'; } $finfo = $getID3->analyze($name); $ret['length'] = isset($finfo['playtime_string']) ? $finfo['playtime_string'] : '00:00'; $ret['lengths'] = isset($finfo['playtime_seconds']) ? round($finfo['playtime_seconds']) : 0; isset($finfo['audio']['bitrate']) ? $ret['bitrate'] = round($finfo['audio']['bitrate']) / 1000 : 0; if (isset($finfo['bitrate'])) { $ret['bitrate'] = round($finfo['bitrate']) / 1000; } $ret['ratemode'] = isset($finfo['audio']['bitrate_mode']) ? ratetypeid($finfo['audio']['bitrate_mode']) : 0; if (isset($finfo['tags']) && is_array($finfo['tags'])) { $first = ''; foreach ($finfo['tags'] as $tagroot => $vals) { $use = $tagroot; if ($use == 'id3v2') { break; } // prefer id3v2. } if (!empty($use)) { if ($use == 'id3v2' && isset($finfo['tags']['id3v1'])) { $order = getid3order(); foreach ($order as $idtag) { switch ($idtag) { case 1: array_fetch($finfo['tags']['id3v1'], $ret); break; case 2: array_fetch($finfo['tags']['id3v2'], $ret); break; } } } else { array_fetch($finfo['tags'][$use], $ret); } if (isset($finfo['id3v2']['APIC'][0]) && is_array($finfo['id3v2']['APIC'][0])) { $apic = $finfo['id3v2']['APIC'][0]; if (isset($apic['mime']) && isset($apic['data']) && !empty($apic['data'])) { $ret['id3image'] = 1; } } if (isset($finfo['tags'][$use]['genre'])) { $ret['genre'] = getgenreidfromName($finfo['tags'][$use]['genre'][0]); } else { if (isset($finfo['tags'][$use]['content_type'][0])) { $genreinfo = $finfo['tags'][$use]['content_type'][0]; $gnum = extractnum($genreinfo); if (is_numeric($gnum)) { $ret['genre'] = $gnum; } } } } } } } } else { $ftype = file_type($name); if ($ftype != -1) { $getidf = @$streamtypes[$ftype][3] or $getidf = 0; switch ($getidf) { case 1: if (class_exists('id3')) { $id3 = new id3($name); $ret['title'] = trim($id3->name); $ret['artist'] = trim($id3->artists); $ret['album'] = trim($id3->album); $ret['length'] = $id3->length; $ret['track'] = (int) $id3->track; $ret['year'] = (int) $id3->year; $ret['comment'] = trim($id3->comment); if ($id3->bitrate) { $ret['bitrate'] = $id3->bitrate; } if ($id3->lengths > 0) { $ret['lengths'] = $id3->lengths; } $ret['genre'] = $id3->genreno; } break; case 2: if (class_exists('ogg')) { $ogg = new ogg($name); foreach ($ogg->fields as $name => $val) { $ch = strtolower($name); if (isset($ret[$ch])) { $ind = ''; foreach ($val as $contents) { $ind .= $contents; } switch ($ch) { case 'genre': if (is_numeric($ind)) { $ret[$ch] = $ind; } break; case 'lengths': if (is_numeric($ind)) { $ret[$ch] = $ind; } break; default: $ret[$ch] = $ind; break; } } } } break; default: break; } } } if (!is_numeric($ret['track'])) { $slashp = strpos($ret['track'], '/', 1); if ($slashp !== false) { $ret['track'] = substr($ret['track'], 0, $slashp); } if (!is_numeric($ret['track'])) { $ret['track'] = 0; } } if (!is_numeric($ret['year'])) { $ret['year'] = 0; } if (!is_numeric($ret['lengths'])) { $ret['lengths'] = 0; } if (!is_numeric($ret['bitrate'])) { $ret['bitrate'] = 0; } if ($return_finfo) { return $finfo; } return $ret; }
// delete tags if (isset($_POST['VersionToEdit1']) && $_POST['VersionToEdit1'] == '1') { echo 'ID3v1 tag' . (RemoveID3v1($EditorFilename, true) ? '' : ' NOT') . ' successfully deleted<HR>'; } if (isset($_POST['VersionToEdit2']) && $_POST['VersionToEdit2'] == '2') { echo 'ID3v2 tag' . (RemoveID3v2($EditorFilename, true) ? '' : ' NOT') . ' successfully deleted<HR>'; } } } echo '<A HREF="' . $_SERVER['PHP_SELF'] . '">Start Over</A><BR>'; echo '<TABLE BORDER="0"><FORM ACTION="' . $_SERVER['PHP_SELF'] . '" METHOD="POST" ENCTYPE="multipart/form-data">'; echo '<TR><TD ALIGN="CENTER" COLSPAN="2"><B>Sample ID3v1/ID3v2/OggComment editor</B></TD></TR>'; if ($EditorFilename) { echo '<TR><TD ALIGN="RIGHT"><B>Filename: </B></TD><TD><INPUT TYPE="HIDDEN" NAME="EditorFilename" VALUE="' . FixTextFields($EditorFilename) . '"><I>' . $EditorFilename . '</I></TD></TR>'; if (file_exists($EditorFilename)) { $OldThisfileInfo = GetAllFileInfo($EditorFilename); echo '<TR><TD ALIGN="RIGHT"><B>Title</B></TD><TD><INPUT TYPE="TEXT" SIZE="40" NAME="EditorTitle" VALUE="' . FixTextFields(isset($OldThisfileInfo['comments']['title'][0]) ? $OldThisfileInfo['comments']['title'][0] : '') . '"></TD></TR>'; echo '<TR><TD ALIGN="RIGHT"><B>Artist</B></TD><TD><INPUT TYPE="TEXT" SIZE="40" NAME="EditorArtist" VALUE="' . FixTextFields(isset($OldThisfileInfo['comments']['artist'][0]) ? $OldThisfileInfo['comments']['artist'][0] : '') . '"></TD></TR>'; echo '<TR><TD ALIGN="RIGHT"><B>Album</B></TD><TD><INPUT TYPE="TEXT" SIZE="40" NAME="EditorAlbum" VALUE="' . FixTextFields(isset($OldThisfileInfo['comments']['album'][0]) ? $OldThisfileInfo['comments']['album'][0] : '') . '"></TD></TR>'; if ($OldThisfileInfo['fileformat'] == 'mp3') { echo '<TR><TD ALIGN="RIGHT"><B>Year</B></TD><TD><INPUT TYPE="TEXT" SIZE="4" NAME="EditorYear" VALUE="' . FixTextFields(isset($OldThisfileInfo['comments']['year'][0]) ? $OldThisfileInfo['comments']['year'][0] : '') . '"></TD></TR>'; } echo '<TR><TD ALIGN="RIGHT"><B>Track</B></TD><TD><INPUT TYPE="TEXT" SIZE="2" NAME="EditorTrack" VALUE="' . FixTextFields(isset($OldThisfileInfo['comments']['track'][0]) ? $OldThisfileInfo['comments']['track'][0] : '') . '"></TD></TR>'; echo '<TR><TD ALIGN="RIGHT"><B>Genre</B></TD><TD><SELECT NAME="EditorGenre">'; require_once GETID3_INCLUDEPATH . 'getid3.id3.php'; $ArrayOfGenres = ArrayOfGenres(); // get the array of genres unset($ArrayOfGenres['CR']); // take off these special cases unset($ArrayOfGenres['RX']); unset($ArrayOfGenres[255]);
} $FilesInDir = array_unique($FilesInDir); sort($FilesInDir); require_once 'getid3.php'; $starttime = time(); $rowcounter = 0; $totaltoprocess = count($FilesInDir); $formatExtensions = array('mp3' => 'mp3', 'ogg' => 'ogg', 'zip' => 'zip', 'wav' => 'riff', 'avi' => 'riff', 'mid' => 'midi', 'mpg' => 'mpeg'); foreach ($FilesInDir as $filename) { set_time_limit(30); echo date('H:i:s') . ' [' . number_format(++$rowcounter) . ' / ' . number_format($totaltoprocess) . '] ' . $filename . '<BR>'; flush(); $ThisFileInfo = GetAllFileInfo($filename, '', true, true, true); if (empty($ThisFileInfo['fileformat']) || $ThisFileInfo['fileformat'] == 'id3') { if (isset($formatExtensions[strtolower(fileextension($filename))])) { $ThisFileInfo = GetAllFileInfo($filename, $formatExtensions[strtolower(fileextension($filename))], true, true, true); } } if (!empty($_REQUEST['rescanerrors'])) { $SQLquery = 'UPDATE files SET '; $SQLquery .= 'md5_file = "' . addslashes(@$ThisFileInfo['md5_file']) . '", '; $SQLquery .= 'md5_data = "' . addslashes(@$ThisFileInfo['md5_data']) . '", '; $SQLquery .= 'md5_data_source = "' . addslashes(@$ThisFileInfo['md5_data_source']) . '", '; $SQLquery .= 'filesize = "' . addslashes(@$ThisFileInfo['filesize']) . '", '; $SQLquery .= 'fileformat = "' . addslashes(@$ThisFileInfo['fileformat']) . '", '; $SQLquery .= 'audio_dataformat = "' . addslashes(@$ThisFileInfo['audio']['dataformat']) . '", '; $SQLquery .= 'video_dataformat = "' . addslashes(@$ThisFileInfo['video']['dataformat']) . '", '; $SQLquery .= 'audio_bitrate = "' . addslashes(@$ThisFileInfo['audio']['bitrate']) . '", '; $SQLquery .= 'video_bitrate = "' . addslashes(@$ThisFileInfo['video']['bitrate']) . '", '; $SQLquery .= 'playtime_seconds = "' . addslashes(@$ThisFileInfo['playtime_seconds']) . '", '; $SQLquery .= 'tags = "' . addslashes(@implode(',', @$ThisFileInfo['tags'])) . '", ';
$DirectoryContents["{$currentfulldir}"]['dir']["{$file}"]['filename'] = $ParentDir; break; case '.': // ignore break; default: $DirectoryContents["{$currentfulldir}"]['dir']["{$file}"]['filename'] = $file; break; } } elseif ($TargetObjectType == 'file') { $fileinformation = GetAllFileInfo($currentfilename, false, isset($_REQUEST['ShowMD5']), isset($_REQUEST['ShowMD5'])); if (empty($fileinformation['fileformat'])) { // auto-detect couldn't find the file format (probably corrupt header?), re-scan based on extension, if applicable $formatExtensions = array('mp3' => 'mp3', 'ogg' => 'ogg', 'zip' => 'zip', 'wav' => 'riff', 'avi' => 'riff', 'mid' => 'midi', 'mpg' => 'mpeg', 'jpg' => 'image', 'gif' => 'image', 'png' => 'image'); if (isset($formatExtensions[fileextension($currentfilename)])) { $fileinformation = GetAllFileInfo($currentfilename, $formatExtensions[fileextension($currentfilename)], isset($_REQUEST['ShowMD5']), isset($_REQUEST['ShowMD5'])); } } if (!empty($fileinformation['fileformat'])) { $DirectoryContents["{$currentfulldir}"]['known']["{$file}"] = $fileinformation; } else { $DirectoryContents["{$currentfulldir}"]['other']["{$file}"] = $fileinformation; $DirectoryContents["{$currentfulldir}"]['other']["{$file}"]['playtime_string'] = '-'; } } } $endtime = getmicrotime(); closedir($handle); echo 'done<BR>'; echo 'Directory scanned in ' . number_format($endtime - $starttime, 2) . ' seconds.<BR>'; flush();
function RemoveID3v2($filename, $showerrors = false) { // File MUST be writeable - CHMOD(646) at least. It's best if the // directory is also writeable, because that method is both faster and less susceptible to errors. if (is_writeable(dirname($filename))) { // preferred method - only one copying operation, minimal chance of corrupting // original file if script is interrupted, but required directory to be writeable if ($fp_source = @fopen($filename, 'rb')) { $OldThisfileInfo = GetAllFileInfo($filename); rewind($fp_source); if ($OldThisfileInfo['avdataoffset'] !== false) { fseek($fp_source, $OldThisfileInfo['avdataoffset'], SEEK_SET); } if ($fp_temp = @fopen($filename . 'getid3tmp', 'w+b')) { // while (($buffer = fread($fp_source, FREAD_BUFFER_SIZE)) !== false) { while ($buffer = fread($fp_source, FREAD_BUFFER_SIZE)) { fwrite($fp_temp, $buffer, strlen($buffer)); } fclose($fp_temp); } else { $error .= 'Could not open ' . $filename . 'getid3tmp mode "w+b"<BR>'; } fclose($fp_source); } else { $error .= 'Could not open ' . $filename . ' mode "rb"<BR>'; } if (file_exists($filename)) { unlink($filename); } rename($filename . 'getid3tmp', $filename); } elseif (is_writable($filename)) { // less desirable alternate method - double-copies the file, overwrites original file // and could corrupt source file if the script is interrupted or an error occurs. if ($fp_source = @fopen($filename, 'rb')) { $OldThisfileInfo = GetAllFileInfo($filename); rewind($fp_source); if ($OldThisfileInfo['avdataoffset'] !== false) { fseek($fp_source, $OldThisfileInfo['avdataoffset'], SEEK_SET); } if ($fp_temp = tmpfile()) { // while (($buffer = fread($fp_source, FREAD_BUFFER_SIZE)) !== false) { while ($buffer = fread($fp_source, FREAD_BUFFER_SIZE)) { fwrite($fp_temp, $buffer, strlen($buffer)); } fclose($fp_source); if ($fp_source = @fopen($filename, 'wb')) { rewind($fp_temp); // while (($buffer = fread($fp_temp, FREAD_BUFFER_SIZE)) !== false) { while ($buffer = fread($fp_temp, FREAD_BUFFER_SIZE)) { fwrite($fp_source, $buffer, strlen($buffer)); } fseek($fp_temp, -128, SEEK_END); fclose($fp_source); } else { $error .= 'Could not open ' . $filename . ' mode "wb"<BR>'; } fclose($fp_temp); } else { $error .= 'Could not create tmpfile()<BR>'; } } else { $error .= 'Could not open ' . $filename . ' mode "rb"<BR>'; } } else { $error .= 'Directory and file both not writeable<BR>'; } if ($error) { if ($showerrors) { echo $error; } return false; } return true; }