function tag_mp3($filename, $songname, $albumname, $artist, $time) { $TaggingFormat = 'UTF-8'; // Initialize getID3 engine $getID3 = new getID3(); $getID3->setOption(array('encoding' => $TaggingFormat)); getid3_lib::IncludeDependency('/var/www/html/getid3/getid3/write.php', __FILE__, true); // Initialize getID3 tag-writing module $tagwriter = new getid3_writetags(); $tagwriter->filename = $filename; $tagwriter->tagformats = array('id3v1', 'id3v2.3'); // set various options (optional) $tagwriter->overwrite_tags = true; $tagwriter->tag_encoding = $TaggingFormat; $tagwriter->remove_other_tags = true; // populate data array $TagData['title'][] = $songname; $TagData['artist'][] = $artist; $TagData['album'][] = $albumname; $tagwriter->tag_data = $TagData; // write tags if ($tagwriter->WriteTags()) { echo 'Successfully wrote tags<br>'; if (!empty($tagwriter->warnings)) { echo 'There were some warnings:<br>' . implode('<br><br>', $tagwriter->warnings); } } else { echo 'Failed to write tags!<br>' . implode('<br><br>', $tagwriter->errors); } }
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 // CHANGED BY BUDDHAFLY 06-02-20 if (!in_array(sotf_File::getExtension($item['path']), $config['skipGetID3FileTypes'])) { $getID3 = new getID3(); $mp3info = $getID3->analyze($item['path']); getid3_lib::CopyTagsToComments($mp3info); } else { $fileinfo['video'] = true; } //$mp3info = GetAllFileInfo($item['path']); //debug('mp3info', $mp3info); // CHANGED BY BUDDHAFLY 06-02-20 $bitrate = (string) $mp3info['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; } }
protected function extractDataFromFilename($filename) { if (empty($filename)) { return null; } $id3 = new getID3(); $data = $id3->analyze($filename); getid3_lib::CopyTagsToComments($data); return $data; }
/** * 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() // CHANGED BY BUDDHAFLY 06-05-12 $getID3 = new getID3(); $fileinfo = $getID3->analyze($this->path); getid3_lib::CopyTagsToComments($fileinfo); //$fileinfo = GetAllFileInfo($this->path); $this->allInfo = $fileInfo; //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); } }
/** * * * @return array */ public function getId3Data() : array { $reader = new \getID3(); $info = $reader->analyze($this->path); \getid3_lib::CopyTagsToComments($info); return $info; }
function import_show($showid, $dir, $type) { // Initialize getID3 engine $getID3 = new getID3(); // Read files and directories if (is_dir($dir)) { if ($dh = opendir($dir)) { while (($file = readdir($dh)) !== false) { $full_name = $dir . "/" . $file; if (is_file($full_name) || $file[0] != '.') { $ThisFileInfo = $getID3->analyze($full_name); if ($ThisFileInfo['fileformat'] == "mp3") { getid3_lib::CopyTagsToComments($ThisFileInfo); $album = mysql_real_escape_string(@implode(@$ThisFileInfo['comments_html']['album'])); $play_time = mysql_real_escape_string(@$ThisFileInfo['playtime_seconds']); $title_name = mysql_real_escape_string(@implode(@$ThisFileInfo['comments_html']['title'])); $artist_name = mysql_real_escape_string(@implode(@$ThisFileInfo['comments_html']['artist'])); $full_name = mysql_real_escape_string($full_name); if ($id = song_non_existant($full_name, $showid)) { $artist_id = check_or_insert_artist($artist_name); insert_into_tunes($title_name, $artist_id, $full_name, $album, $play_time, $showid, -1, $type); } else { $artist_id = check_or_insert_artist($artist_name); update_tunes($title_name, $id, $artist_id, $full_name, $album, $play_time); } } } } closedir($dh); } } }
/** * Get ID3 Details * * @param string $path * * @return array */ protected function getId3($path) { $getID3 = new \getID3(); $analyze = $getID3->analyze($path); \getid3_lib::CopyTagsToComments($analyze); return $analyze; }
public static function readMetadata($file) { require_once __DIR__ . '/../vendor/autoload.php'; $getID3 = new \getID3(); $meta = $getID3->analyze($file); \getid3_lib::CopyTagsToComments($meta); return $meta; }
public function getID3() { require_once PHPWS_SOURCE_DIR . 'lib/vendor/autoload.php'; $getID3 = new getID3(); // File to get info from $file_location = $this->getPath(); // Get information from the file $fileinfo = $getID3->analyze($file_location); getid3_lib::CopyTagsToComments($fileinfo); return $fileinfo; }
/** * Extract information - only public function * * @access public * @param string file Audio file to extract info from. */ function Info($file) { // Analyze file $this->info = $this->getID3->analyze($file); // Exit here on error if (isset($this->info['error'])) { return array('error' => $this->info['error']); } else { getid3_lib::CopyTagsToComments($this->info); } // Init wrapper object $this->result = array(); $this->result['format_name'] = (isset($this->info['fileformat']) ? $this->info['fileformat'] : '') . '/' . (isset($this->info['audio']['dataformat']) ? $this->info['audio']['dataformat'] : '') . (isset($this->info['video']['dataformat']) ? '/' . $this->info['video']['dataformat'] : ''); $this->result['encoder_version'] = isset($this->info['audio']['encoder']) ? $this->info['audio']['encoder'] : ''; $this->result['encoder_options'] = isset($this->info['audio']['encoder_options']) ? $this->info['audio']['encoder_options'] : ''; $this->result['bitrate_mode'] = isset($this->info['audio']['bitrate_mode']) ? $this->info['audio']['bitrate_mode'] : ''; $this->result['channels'] = isset($this->info['audio']['channels']) ? $this->info['audio']['channels'] : ''; $this->result['sample_rate'] = isset($this->info['audio']['sample_rate']) ? $this->info['audio']['sample_rate'] : ''; $this->result['bits_per_sample'] = isset($this->info['audio']['bits_per_sample']) ? $this->info['audio']['bits_per_sample'] : ''; $this->result['playing_time'] = isset($this->info['playtime_seconds']) ? $this->info['playtime_seconds'] : ''; $this->result['playtime_string'] = isset($this->info['playtime_string']) ? $this->info['playtime_string'] : ''; $this->result['avg_bit_rate'] = isset($this->info['audio']['bitrate']) ? $this->info['audio']['bitrate'] : ''; $this->result['tags'] = isset($this->info['tags']) ? $this->info['tags'] : ''; $this->result['comments'] = isset($this->info['comments']) ? $this->info['comments'] : ''; $this->result['warning'] = isset($this->info['warning']) ? $this->info['warning'] : ''; $this->result['md5'] = isset($this->info['md5_data']) ? $this->info['md5_data'] : ''; // Post getID3() data handling based on file format $method = (isset($this->info['fileformat']) ? $this->info['fileformat'] : '') . 'Info'; if ($method && method_exists($this, $method)) { $this->{$method}(); } return $this->result; }
function readFileDirectory($path) { global $mysql, $getID3, $albumSongs; foreach (scandir($path) as $currentFile) { if ($currentFile == "." || $currentFile == "..") { continue; } $fullPath = $path . "/" . $currentFile; if (is_dir($fullPath)) { readFileDirectory($fullPath); } else { $fileExtension = pathinfo($currentFile, PATHINFO_EXTENSION); if ($fileExtension == "mp3" || $fileExtension == "wav" || $fileExtension == "ogg") { $songInfo = $getID3->analyze($fullPath); getid3_lib::CopyTagsToComments($songInfo); if (!$songInfo['comments_html']['title'][0]) { $songInfo['comments_html']['title'][0] = basename($currentFile); } if ($songInfo['tags']['id3v2']['album'][0]) { $albumSongs[escape($songInfo['tags']['id3v2']['album'][0])] = true; } else { $albumSongs[escape($songInfo['comments_html']['artist'][0])] = true; } $mysql->query("INSERT INTO `songs` (`path`, `title`, `artist`, `album`, `length`) VALUES ('{$fullPath}', '" . escape($songInfo['comments_html']['title'][0]) . "', '" . escape($songInfo['comments_html']['artist'][0]) . "', '" . escape($songInfo['tags']['id3v2']['album'][0]) . "', '" . escape($songInfo['playtime_string']) . "')"); } } } }
public function Analyze() { $info =& $this->getid3->info; $info['fileformat'] = 'rar'; if ($this->option_use_rar_extension === true) { if (function_exists('rar_open')) { if ($rp = rar_open($info['filenamepath'])) { $info['rar']['files'] = array(); $entries = rar_list($rp); foreach ($entries as $entry) { $info['rar']['files'] = getid3_lib::array_merge_clobber($info['rar']['files'], getid3_lib::CreateDeepArray($entry->getName(), '/', $entry->getUnpackedSize())); } rar_close($rp); return true; } else { $info['error'][] = 'failed to rar_open(' . $info['filename'] . ')'; } } else { $info['error'][] = 'RAR support does not appear to be available in this PHP installation'; } } else { $info['error'][] = 'PHP-RAR processing has been disabled (set $getid3_rar->option_use_rar_extension=true to enable)'; } return false; }
public static function parseSoundFile($filename) { global $getID3; // Get sound meta $id3 = $getID3->analyze($filename); getid3_lib::CopyTagsToComments($id3); // Validate if (!Sounds::validateID3($id3)) { unlink($filename); return false; } // Make our directory $artist = @$id3['comments']['artist'][0]; $album = @$id3['comments']['album'][0]; $dir = DOC_ROOT . '/music/' . Sounds::safeDirectory($artist) . '/' . Sounds::safeDirectory($album); if (!is_dir($dir)) { mkdir($dir, 0777, true); } // Our new filename $moved = $dir . '/' . basename($filename); // Already exists! Madness! if (file_exists($moved)) { unlink($filename); return false; } // Move rename($filename, $moved); // Create and Save $sound = new Sound(array('filename' => $moved)); $sound->save(); return $sound; }
function Analyze() { $info =& $this->getid3->info; fseek($this->getid3->fp, $info['avdataoffset'], SEEK_SET); $DSSheader = fread($this->getid3->fp, 1256); if (!preg_match('#^(\\x02|\\x03)dss#', $DSSheader)) { $info['error'][] = 'Expecting "[02-03] 64 73 73" at offset ' . $info['avdataoffset'] . ', found "' . getid3_lib::PrintHexBytes(substr($DSSheader, 0, 4)) . '"'; return false; } // some structure information taken from http://cpansearch.perl.org/src/RGIBSON/Audio-DSS-0.02/lib/Audio/DSS.pm // shortcut $info['dss'] = array(); $thisfile_dss =& $info['dss']; $info['fileformat'] = 'dss'; $info['audio']['dataformat'] = 'dss'; $info['audio']['bitrate_mode'] = 'cbr'; //$thisfile_dss['encoding'] = 'ISO-8859-1'; $thisfile_dss['version'] = ord(substr($DSSheader, 0, 1)); $thisfile_dss['date_create'] = $this->DSSdateStringToUnixDate(substr($DSSheader, 38, 12)); $thisfile_dss['date_complete'] = $this->DSSdateStringToUnixDate(substr($DSSheader, 50, 12)); //$thisfile_dss['length'] = intval(substr($DSSheader, 62, 6)); // I thought time was in seconds, it's actually HHMMSS $thisfile_dss['length'] = intval(substr($DSSheader, 62, 2) * 3600 + substr($DSSheader, 64, 2) * 60 + substr($DSSheader, 66, 2)); $thisfile_dss['priority'] = ord(substr($DSSheader, 793, 1)); $thisfile_dss['comments'] = trim(substr($DSSheader, 798, 100)); //$info['audio']['bits_per_sample'] = ?; //$info['audio']['sample_rate'] = ?; $info['audio']['channels'] = 1; $info['playtime_seconds'] = $thisfile_dss['length']; $info['audio']['bitrate'] = $info['filesize'] * 8 / $info['playtime_seconds']; return true; }
function getid3_exe(&$fd, &$ThisFileInfo) { fseek($fd, $ThisFileInfo['avdataoffset'], SEEK_SET); $EXEheader = fread($fd, 28); if (substr($EXEheader, 0, 2) != 'MZ') { $ThisFileInfo['error'][] = 'Expecting "MZ" at offset ' . $ThisFileInfo['avdataoffset'] . ', found "' . substr($EXEheader, 0, 2) . '" instead.'; return false; } $ThisFileInfo['fileformat'] = 'exe'; $ThisFileInfo['exe']['mz']['magic'] = 'MZ'; $ThisFileInfo['exe']['mz']['raw']['last_page_size'] = getid3_lib::LittleEndian2Int(substr($EXEheader, 2, 2)); $ThisFileInfo['exe']['mz']['raw']['page_count'] = getid3_lib::LittleEndian2Int(substr($EXEheader, 4, 2)); $ThisFileInfo['exe']['mz']['raw']['relocation_count'] = getid3_lib::LittleEndian2Int(substr($EXEheader, 6, 2)); $ThisFileInfo['exe']['mz']['raw']['header_paragraphs'] = getid3_lib::LittleEndian2Int(substr($EXEheader, 8, 2)); $ThisFileInfo['exe']['mz']['raw']['min_memory_paragraphs'] = getid3_lib::LittleEndian2Int(substr($EXEheader, 10, 2)); $ThisFileInfo['exe']['mz']['raw']['max_memory_paragraphs'] = getid3_lib::LittleEndian2Int(substr($EXEheader, 12, 2)); $ThisFileInfo['exe']['mz']['raw']['initial_ss'] = getid3_lib::LittleEndian2Int(substr($EXEheader, 14, 2)); $ThisFileInfo['exe']['mz']['raw']['initial_sp'] = getid3_lib::LittleEndian2Int(substr($EXEheader, 16, 2)); $ThisFileInfo['exe']['mz']['raw']['checksum'] = getid3_lib::LittleEndian2Int(substr($EXEheader, 18, 2)); $ThisFileInfo['exe']['mz']['raw']['cs_ip'] = getid3_lib::LittleEndian2Int(substr($EXEheader, 20, 4)); $ThisFileInfo['exe']['mz']['raw']['relocation_table_offset'] = getid3_lib::LittleEndian2Int(substr($EXEheader, 24, 2)); $ThisFileInfo['exe']['mz']['raw']['overlay_number'] = getid3_lib::LittleEndian2Int(substr($EXEheader, 26, 2)); $ThisFileInfo['exe']['mz']['byte_size'] = ($ThisFileInfo['exe']['mz']['raw']['page_count'] - 1) * 512 + $ThisFileInfo['exe']['mz']['raw']['last_page_size']; $ThisFileInfo['exe']['mz']['header_size'] = $ThisFileInfo['exe']['mz']['raw']['header_paragraphs'] * 16; $ThisFileInfo['exe']['mz']['memory_minimum'] = $ThisFileInfo['exe']['mz']['raw']['min_memory_paragraphs'] * 16; $ThisFileInfo['exe']['mz']['memory_recommended'] = $ThisFileInfo['exe']['mz']['raw']['max_memory_paragraphs'] * 16; $ThisFileInfo['error'][] = 'EXE parsing not enabled in this version of getID3()'; return false; }
public function Analyze() { $info =& $this->getid3->info; $this->fseek($info['avdataoffset']); $EXEheader = $this->fread(28); $magic = 'MZ'; if (substr($EXEheader, 0, 2) != $magic) { $info['error'][] = 'Expecting "' . getid3_lib::PrintHexBytes($magic) . '" at offset ' . $info['avdataoffset'] . ', found "' . getid3_lib::PrintHexBytes(substr($EXEheader, 0, 2)) . '"'; return false; } $info['fileformat'] = 'exe'; $info['exe']['mz']['magic'] = 'MZ'; $info['exe']['mz']['raw']['last_page_size'] = getid3_lib::LittleEndian2Int(substr($EXEheader, 2, 2)); $info['exe']['mz']['raw']['page_count'] = getid3_lib::LittleEndian2Int(substr($EXEheader, 4, 2)); $info['exe']['mz']['raw']['relocation_count'] = getid3_lib::LittleEndian2Int(substr($EXEheader, 6, 2)); $info['exe']['mz']['raw']['header_paragraphs'] = getid3_lib::LittleEndian2Int(substr($EXEheader, 8, 2)); $info['exe']['mz']['raw']['min_memory_paragraphs'] = getid3_lib::LittleEndian2Int(substr($EXEheader, 10, 2)); $info['exe']['mz']['raw']['max_memory_paragraphs'] = getid3_lib::LittleEndian2Int(substr($EXEheader, 12, 2)); $info['exe']['mz']['raw']['initial_ss'] = getid3_lib::LittleEndian2Int(substr($EXEheader, 14, 2)); $info['exe']['mz']['raw']['initial_sp'] = getid3_lib::LittleEndian2Int(substr($EXEheader, 16, 2)); $info['exe']['mz']['raw']['checksum'] = getid3_lib::LittleEndian2Int(substr($EXEheader, 18, 2)); $info['exe']['mz']['raw']['cs_ip'] = getid3_lib::LittleEndian2Int(substr($EXEheader, 20, 4)); $info['exe']['mz']['raw']['relocation_table_offset'] = getid3_lib::LittleEndian2Int(substr($EXEheader, 24, 2)); $info['exe']['mz']['raw']['overlay_number'] = getid3_lib::LittleEndian2Int(substr($EXEheader, 26, 2)); $info['exe']['mz']['byte_size'] = ($info['exe']['mz']['raw']['page_count'] - 1) * 512 + $info['exe']['mz']['raw']['last_page_size']; $info['exe']['mz']['header_size'] = $info['exe']['mz']['raw']['header_paragraphs'] * 16; $info['exe']['mz']['memory_minimum'] = $info['exe']['mz']['raw']['min_memory_paragraphs'] * 16; $info['exe']['mz']['memory_recommended'] = $info['exe']['mz']['raw']['max_memory_paragraphs'] * 16; $info['error'][] = 'EXE parsing not enabled in this version of getID3() [' . $this->getid3->version() . ']'; return false; }
function getid3_jpg(&$fd, &$ThisFileInfo) { $ThisFileInfo['fileformat'] = 'jpg'; $ThisFileInfo['video']['dataformat'] = 'jpg'; $ThisFileInfo['video']['lossless'] = false; $ThisFileInfo['video']['bits_per_sample'] = 24; $ThisFileInfo['video']['pixel_aspect_ratio'] = (double) 1; fseek($fd, $ThisFileInfo['avdataoffset'], SEEK_SET); list($width, $height, $type) = getid3_lib::GetDataImageSize(fread($fd, $ThisFileInfo['filesize'])); if ($type == 2) { $ThisFileInfo['video']['resolution_x'] = $width; $ThisFileInfo['video']['resolution_y'] = $height; if (version_compare(phpversion(), '4.2.0', '>=')) { if (function_exists('exif_read_data')) { ob_start(); $ThisFileInfo['jpg']['exif'] = exif_read_data($ThisFileInfo['filenamepath'], '', true, false); $errors = ob_get_contents(); if ($errors) { $ThisFileInfo['error'][] = strip_tags($errors); unset($ThisFileInfo['jpg']['exif']); } ob_end_clean(); } else { $ThisFileInfo['warning'][] = 'EXIF parsing only available when ' . (GETID3_OS_ISWINDOWS ? 'php_exif.dll enabled' : 'compiled with --enable-exif'); } } else { $ThisFileInfo['warning'][] = 'EXIF parsing only available in PHP v4.2.0 and higher compiled with --enable-exif (or php_exif.dll enabled for Windows). You are using PHP v' . phpversion(); } return true; } unset($ThisFileInfo['fileformat']); return false; }
public function Analyze() { $getid3 = $this->getid3; fseek($getid3->fp, $getid3->info['avdataoffset'], SEEK_SET); $au_header = fread($getid3->fp, 8); // Magic bytes: .snd $getid3->info['au'] = array(); $info_au =& $getid3->info['au']; $getid3->info['fileformat'] = 'au'; $getid3->info['audio']['dataformat'] = 'au'; $getid3->info['audio']['bitrate_mode'] = 'cbr'; $info_au['encoding'] = 'ISO-8859-1'; $info_au['header_length'] = getid3_lib::BigEndian2Int(substr($au_header, 4, 4)); $au_header .= fread($getid3->fp, $info_au['header_length'] - 8); $getid3->info['avdataoffset'] += $info_au['header_length']; getid3_lib::ReadSequence('BigEndian2Int', $info_au, $au_header, 8, array('data_size' => 4, 'data_format_id' => 4, 'sample_rate' => 4, 'channels' => 4)); $info_au['comments']['comment'][] = trim(substr($au_header, 24)); $info_au['data_format'] = getid3_au::AUdataFormatNameLookup($info_au['data_format_id']); $info_au['used_bits_per_sample'] = getid3_au::AUdataFormatUsedBitsPerSampleLookup($info_au['data_format_id']); if ($info_au['bits_per_sample'] = getid3_au::AUdataFormatBitsPerSampleLookup($info_au['data_format_id'])) { $getid3->info['audio']['bits_per_sample'] = $info_au['bits_per_sample']; } else { unset($info_au['bits_per_sample']); } $getid3->info['audio']['sample_rate'] = $info_au['sample_rate']; $getid3->info['audio']['channels'] = $info_au['channels']; if ($getid3->info['avdataoffset'] + $info_au['data_size'] > $getid3->info['avdataend']) { $getid3->warning('Possible truncated file - expecting "' . $info_au['data_size'] . '" bytes of audio data, only found ' . ($getid3->info['avdataend'] - $getid3->info['avdataoffset']) . ' bytes"'); } $getid3->info['playtime_seconds'] = $info_au['data_size'] / ($info_au['sample_rate'] * $info_au['channels'] * ($info_au['used_bits_per_sample'] / 8)); $getid3->info['audio']['bitrate'] = $info_au['data_size'] * 8 / $getid3->info['playtime_seconds']; return true; }
public function Analyze() { $getid3 = $this->getid3; // http://www.uni-jena.de/~pfk/mpp/sv8/header.html $getid3->info['mpc']['header'] = array(); $info_mpc_header =& $getid3->info['mpc']['header']; $getid3->info['fileformat'] = 'mpc'; $getid3->info['audio']['dataformat'] = 'mpc'; $getid3->info['audio']['bitrate_mode'] = 'vbr'; $getid3->info['audio']['channels'] = 2; // the format appears to be hardcoded for stereo only $getid3->info['audio']['lossless'] = false; fseek($getid3->fp, $getid3->info['avdataoffset'], SEEK_SET); $info_mpc_header['size'] = 8; $getid3->info['avdataoffset'] += $info_mpc_header['size']; $mpc_header_data = fread($getid3->fp, $info_mpc_header['size']); // Most of this code adapted from Jurgen Faul's MPEGplus source code - thanks Jurgen! :) $header_dword[0] = getid3_lib::LittleEndian2Int(substr($mpc_header_data, 0, 4)); $header_dword[1] = getid3_lib::LittleEndian2Int(substr($mpc_header_data, 4, 4)); // DDDD DDDD CCCC CCCC BBBB BBBB AAAA AAAA // aaaa aaaa abcd dddd dddd deee eeff ffff // // a = bitrate = anything // b = IS = anything // c = MS = anything // d = streamversion = 0000000004 or 0000000005 or 0000000006 // e = maxband = anything // f = blocksize = 000001 for SV5+, anything(?) for SV4 $info_mpc_header['target_bitrate'] = ($header_dword[0] & 4286578688.0) >> 23; $info_mpc_header['intensity_stereo'] = (bool) (($header_dword[0] & 0x400000) >> 22); $info_mpc_header['mid-side_stereo'] = (bool) (($header_dword[0] & 0x200000) >> 21); $info_mpc_header['stream_major_version'] = ($header_dword[0] & 0x1ff800) >> 11; $info_mpc_header['stream_minor_version'] = 0; $info_mpc_header['max_band'] = ($header_dword[0] & 0x7c0) >> 6; // related to lowpass frequency, not sure how it translates exactly $info_mpc_header['block_size'] = $header_dword[0] & 0x3f; switch ($info_mpc_header['stream_major_version']) { case 4: $info_mpc_header['frame_count'] = $header_dword[1] >> 16; break; case 5: case 6: $info_mpc_header['frame_count'] = $header_dword[1]; break; default: throw new getid3_exception('Expecting 4, 5 or 6 in version field, found ' . $info_mpc_header['stream_major_version'] . ' instead'); } if ($info_mpc_header['stream_major_version'] > 4 && $info_mpc_header['block_size'] != 1) { $getid3->warning('Block size expected to be 1, actual value found: ' . $info_mpc_header['block_size']); } $info_mpc_header['sample_rate'] = $getid3->info['audio']['sample_rate'] = 44100; // AB: used by all files up to SV7 $info_mpc_header['samples'] = $info_mpc_header['frame_count'] * 1152 * $getid3->info['audio']['channels']; $getid3->info['audio']['bitrate_mode'] = $info_mpc_header['target_bitrate'] == 0 ? 'vbr' : 'cbr'; $getid3->info['mpc']['bitrate'] = ($getid3->info['avdataend'] - $getid3->info['avdataoffset']) * 8 * 44100 / $info_mpc_header['frame_count'] / 1152; $getid3->info['audio']['bitrate'] = $getid3->info['mpc']['bitrate']; $getid3->info['audio']['encoder'] = 'SV' . $info_mpc_header['stream_major_version']; return true; }
function Analyze() { $info =& $this->getid3->info; fseek($this->getid3->fp, $info['avdataoffset'], SEEK_SET); $SZIPHeader = fread($this->getid3->fp, 6); if (substr($SZIPHeader, 0, 4) != "SZ\n") { $info['error'][] = 'Expecting "53 5A 0A 04" at offset ' . $info['avdataoffset'] . ', found "' . getid3_lib::PrintHexBytes(substr($SZIPHeader, 0, 4)) . '"'; return false; } $info['fileformat'] = 'szip'; $info['szip']['major_version'] = getid3_lib::BigEndian2Int(substr($SZIPHeader, 4, 1)); $info['szip']['minor_version'] = getid3_lib::BigEndian2Int(substr($SZIPHeader, 5, 1)); while (!feof($this->getid3->fp)) { $NextBlockID = fread($this->getid3->fp, 2); switch ($NextBlockID) { case 'SZ': // Note that szip files can be concatenated, this has the same effect as // concatenating the files. this also means that global header blocks // might be present between directory/data blocks. fseek($this->getid3->fp, 4, SEEK_CUR); break; case 'BH': $BHheaderbytes = getid3_lib::BigEndian2Int(fread($this->getid3->fp, 3)); $BHheaderdata = fread($this->getid3->fp, $BHheaderbytes); $BHheaderoffset = 0; while (strpos($BHheaderdata, "", $BHheaderoffset) > 0) { //filename as \0 terminated string (empty string indicates end) //owner as \0 terminated string (empty is same as last file) //group as \0 terminated string (empty is same as last file) //3 byte filelength in this block //2 byte access flags //4 byte creation time (like in unix) //4 byte modification time (like in unix) //4 byte access time (like in unix) $BHdataArray['filename'] = substr($BHheaderdata, $BHheaderoffset, strcspn($BHheaderdata, "")); $BHheaderoffset += strlen($BHdataArray['filename']) + 1; $BHdataArray['owner'] = substr($BHheaderdata, $BHheaderoffset, strcspn($BHheaderdata, "")); $BHheaderoffset += strlen($BHdataArray['owner']) + 1; $BHdataArray['group'] = substr($BHheaderdata, $BHheaderoffset, strcspn($BHheaderdata, "")); $BHheaderoffset += strlen($BHdataArray['group']) + 1; $BHdataArray['filelength'] = getid3_lib::BigEndian2Int(substr($BHheaderdata, $BHheaderoffset, 3)); $BHheaderoffset += 3; $BHdataArray['access_flags'] = getid3_lib::BigEndian2Int(substr($BHheaderdata, $BHheaderoffset, 2)); $BHheaderoffset += 2; $BHdataArray['creation_time'] = getid3_lib::BigEndian2Int(substr($BHheaderdata, $BHheaderoffset, 4)); $BHheaderoffset += 4; $BHdataArray['modification_time'] = getid3_lib::BigEndian2Int(substr($BHheaderdata, $BHheaderoffset, 4)); $BHheaderoffset += 4; $BHdataArray['access_time'] = getid3_lib::BigEndian2Int(substr($BHheaderdata, $BHheaderoffset, 4)); $BHheaderoffset += 4; $info['szip']['BH'][] = $BHdataArray; } break; default: break 2; } } return true; }
public function Analyze() { $getid3 = $this->getid3; $getid3->info['fileformat'] = 'tta'; $getid3->info['audio']['dataformat'] = 'tta'; $getid3->info['audio']['lossless'] = true; $getid3->info['audio']['bitrate_mode'] = 'vbr'; fseek($getid3->fp, $getid3->info['avdataoffset'], SEEK_SET); $tta_header = fread($getid3->fp, 26); $getid3->info['tta']['magic'] = 'TTA'; // Magic bytes switch ($tta_header[3]) { case "": // TTA v1.x // TTA v1.x case "": // TTA v1.x // TTA v1.x case "": // TTA v1.x // "It was the demo-version of the TTA encoder. There is no released format with such header. TTA encoder v1 is not supported about a year." $getid3->info['tta']['major_version'] = 1; $getid3->info['avdataoffset'] += 16; getid3_lib::ReadSequence('LittleEndian2Int', $getid3->info['tta'], $tta_header, 4, array('channels' => 2, 'bits_per_sample' => 2, 'sample_rate' => 4, 'samples_per_channel' => 4)); $getid3->info['tta']['compression_level'] = ord($tta_header[3]); $getid3->info['audio']['encoder_options'] = '-e' . $getid3->info['tta']['compression_level']; $getid3->info['playtime_seconds'] = $getid3->info['tta']['samples_per_channel'] / $getid3->info['tta']['sample_rate']; break; case '2': // TTA v2.x // "I have hurried to release the TTA 2.0 encoder. Format documentation is removed from our site. This format still in development. Please wait the TTA2 format, encoder v4." $getid3->info['tta']['major_version'] = 2; $getid3->info['avdataoffset'] += 20; getid3_lib::ReadSequence('LittleEndian2Int', $getid3->info['tta'], $tta_header, 4, array('compression_level' => 2, 'audio_format' => 2, 'channels' => 2, 'bits_per_sample' => 2, 'sample_rate' => 4, 'data_length' => 4)); $getid3->info['audio']['encoder_options'] = '-e' . $getid3->info['tta']['compression_level']; $getid3->info['playtime_seconds'] = $getid3->info['tta']['data_length'] / $getid3->info['tta']['sample_rate']; break; case '1': // TTA v3.x // "This is a first stable release of the TTA format. It will be supported by the encoders v3 or higher." $getid3->info['tta']['major_version'] = 3; $getid3->info['avdataoffset'] += 26; getid3_lib::ReadSequence('LittleEndian2Int', $getid3->info['tta'], $tta_header, 4, array('audio_format' => 2, 'channels' => 2, 'bits_per_sample' => 2, 'sample_rate' => 4, 'data_length' => 4, 'crc32_footer' => -4, 'seek_point' => 4)); $getid3->info['playtime_seconds'] = $getid3->info['tta']['data_length'] / $getid3->info['tta']['sample_rate']; break; default: throw new getid3_exception('This version of getID3() only knows how to handle TTA v1, v2 and v3 - it may not work correctly with this file which appears to be TTA v' . $tta_header[3]); return false; break; } $getid3->info['audio']['encoder'] = 'TTA v' . $getid3->info['tta']['major_version']; $getid3->info['audio']['bits_per_sample'] = $getid3->info['tta']['bits_per_sample']; $getid3->info['audio']['sample_rate'] = $getid3->info['tta']['sample_rate']; $getid3->info['audio']['channels'] = $getid3->info['tta']['channels']; $getid3->info['audio']['bitrate'] = ($getid3->info['avdataend'] - $getid3->info['avdataoffset']) * 8 / $getid3->info['playtime_seconds']; return true; }
public function Analyze() { $getid3 = $this->getid3; fseek($getid3->fp, $getid3->info['avdataoffset'], SEEK_SET); $szip_rkau = fread($getid3->fp, 6); // Magic bytes: 'SZ'."\x0A\x04" $getid3->info['fileformat'] = 'szip'; $getid3->info['szip']['major_version'] = getid3_lib::BigEndian2Int(substr($szip_rkau, 4, 1)); $getid3->info['szip']['minor_version'] = getid3_lib::BigEndian2Int(substr($szip_rkau, 5, 1)); while (!feof($getid3->fp)) { $next_block_id = fread($getid3->fp, 2); switch ($next_block_id) { case 'SZ': // Note that szip files can be concatenated, this has the same effect as // concatenating the files. this also means that global header blocks // might be present between directory/data blocks. fseek($getid3->fp, 4, SEEK_CUR); break; case 'BH': $bh_header_bytes = getid3_lib::BigEndian2Int(fread($getid3->fp, 3)); $bh_header_data = fread($getid3->fp, $bh_header_bytes); $bh_header_offset = 0; while (strpos($bh_header_data, "", $bh_header_offset) > 0) { //filename as \0 terminated string (empty string indicates end) //owner as \0 terminated string (empty is same as last file) //group as \0 terminated string (empty is same as last file) //3 byte filelength in this block //2 byte access flags //4 byte creation time (like in unix) //4 byte modification time (like in unix) //4 byte access time (like in unix) $bh_data_array['filename'] = substr($bh_header_data, $bh_header_offset, strcspn($bh_header_data, "")); $bh_header_offset += strlen($bh_data_array['filename']) + 1; $bh_data_array['owner'] = substr($bh_header_data, $bh_header_offset, strcspn($bh_header_data, "")); $bh_header_offset += strlen($bh_data_array['owner']) + 1; $bh_data_array['group'] = substr($bh_header_data, $bh_header_offset, strcspn($bh_header_data, "")); $bh_header_offset += strlen($bh_data_array['group']) + 1; $bh_data_array['filelength'] = getid3_lib::BigEndian2Int(substr($bh_header_data, $bh_header_offset, 3)); $bh_header_offset += 3; $bh_data_array['access_flags'] = getid3_lib::BigEndian2Int(substr($bh_header_data, $bh_header_offset, 2)); $bh_header_offset += 2; $bh_data_array['creation_time'] = getid3_lib::BigEndian2Int(substr($bh_header_data, $bh_header_offset, 4)); $bh_header_offset += 4; $bh_data_array['modification_time'] = getid3_lib::BigEndian2Int(substr($bh_header_data, $bh_header_offset, 4)); $bh_header_offset += 4; $bh_data_array['access_time'] = getid3_lib::BigEndian2Int(substr($bh_header_data, $bh_header_offset, 4)); $bh_header_offset += 4; $getid3->info['szip']['BH'][] = $bh_data_array; } break; default: break 2; } } return true; }
public function init() { global $getID3; if (file_exists($this->filename) && !isset($this->_id3)) { $this->_id3 = $getID3->analyze($this->filename); getid3_lib::CopyTagsToComments($this->_id3); $this->_url = WEB_ROOT . str_replace(array(DOC_ROOT, '\\'), array('', '/'), $this->filename); $this->_imageUrl = isset($this->_id3['comments']['picture'][0]) ? WEB_ROOT . '/image/' . $this->id : ''; } }
/** * Get the ID3v2.x tag from an mp3 file. * * @param string $file * @return array * @access public */ function getid3($file) { global $mosConfig_absolute_path, $database; require_once $mosConfig_absolute_path . "/components/com_zoom/lib/getid3/getid3.php"; require_once $mosConfig_absolute_path . "/components/com_zoom/lib/getid3/extension.cache.mysql.php"; $getid3 = new getID3_cached_mysql($database); $fileInfo = $getid3->analyze($file); getid3_lib::CopyTagsToComments($fileInfo); return $fileInfo; }
public function Analyze() { $info =& $this->getid3->info; $this->fseek($info['avdataoffset']); $DSSheader = $this->fread(1540); if (!preg_match('#^[\\x02-\\x06]ds[s2]#', $DSSheader)) { $info['error'][] = 'Expecting "[02-06] 64 73 [73|32]" at offset ' . $info['avdataoffset'] . ', found "' . getid3_lib::PrintHexBytes(substr($DSSheader, 0, 4)) . '"'; return false; } // some structure information taken from http://cpansearch.perl.org/src/RGIBSON/Audio-DSS-0.02/lib/Audio/DSS.pm $info['encoding'] = 'ISO-8859-1'; // not certain, but assumed $info['dss'] = array(); $info['fileformat'] = 'dss'; $info['mime_type'] = 'audio/x-' . substr($DSSheader, 1, 3); // "audio/x-dss" or "audio/x-ds2" $info['audio']['dataformat'] = substr($DSSheader, 1, 3); // "dss" or "ds2" $info['audio']['bitrate_mode'] = 'cbr'; $info['dss']['version'] = ord(substr($DSSheader, 0, 1)); $info['dss']['hardware'] = trim(substr($DSSheader, 12, 16)); // identification string for hardware used to create the file, e.g. "DPM 9600", "DS2400" $info['dss']['unknown1'] = getid3_lib::LittleEndian2Int(substr($DSSheader, 28, 4)); // 32-37 = "FE FF FE FF F7 FF" in all the sample files I've seen $info['dss']['date_create_unix'] = $this->DSSdateStringToUnixDate(substr($DSSheader, 38, 12)); $info['dss']['date_complete_unix'] = $this->DSSdateStringToUnixDate(substr($DSSheader, 50, 12)); $info['dss']['playtime_sec'] = intval(substr($DSSheader, 62, 2) * 3600 + substr($DSSheader, 64, 2) * 60 + substr($DSSheader, 66, 2)); // approximate file playtime in HHMMSS if ($info['dss']['version'] <= 3) { $info['dss']['playtime_ms'] = getid3_lib::LittleEndian2Int(substr($DSSheader, 512, 4)); // exact file playtime in milliseconds. Has also been observed at offset 530 in one sample file, with something else (unknown) at offset 512 $info['dss']['priority'] = ord(substr($DSSheader, 793, 1)); $info['dss']['comments'] = trim(substr($DSSheader, 798, 100)); $info['dss']['sample_rate_index'] = ord(substr($DSSheader, 1538, 1)); // this isn't certain, this may or may not be where the sample rate info is stored, but it seems consistent on my small selection of sample files $info['audio']['sample_rate'] = $this->DSSsampleRateLookup($info['dss']['sample_rate_index']); } else { $this->getid3->warning('DSS above version 3 not fully supported in this version of getID3. Any additional documentation or format specifications would be welcome. This file is version ' . $info['dss']['version']); } $info['audio']['bits_per_sample'] = 16; // maybe, maybe not -- most compressed audio formats don't have a fixed bits-per-sample value, but this is a reasonable approximation $info['audio']['channels'] = 1; if (!empty($info['dss']['playtime_ms']) && floor($info['dss']['playtime_ms'] / 1000) == $info['dss']['playtime_sec']) { // *should* just be playtime_ms / 1000 but at least one sample file has playtime_ms at offset 530 instead of offset 512, so safety check $info['playtime_seconds'] = $info['dss']['playtime_ms'] / 1000; } else { $info['playtime_seconds'] = $info['dss']['playtime_sec']; if (!empty($info['dss']['playtime_ms'])) { $this->getid3->warning('playtime_ms (' . number_format($info['dss']['playtime_ms'] / 1000, 3) . ') does not match playtime_sec (' . number_format($info['dss']['playtime_sec']) . ') - using playtime_sec value'); } } $info['audio']['bitrate'] = $info['filesize'] * 8 / $info['playtime_seconds']; return true; }
function getid3_jpg(&$fd, &$ThisFileInfo) { $ThisFileInfo['fileformat'] = 'jpg'; $ThisFileInfo['video']['dataformat'] = 'jpg'; $ThisFileInfo['video']['lossless'] = false; $ThisFileInfo['video']['bits_per_sample'] = 24; $ThisFileInfo['video']['pixel_aspect_ratio'] = (double) 1; fseek($fd, $ThisFileInfo['avdataoffset'], SEEK_SET); $imageinfo = array(); list($width, $height, $type) = getid3_lib::GetDataImageSize(fread($fd, $ThisFileInfo['filesize']), $imageinfo); if (isset($imageinfo['APP13'])) { // http://php.net/iptcparse // http://www.sno.phy.queensu.ca/~phil/exiftool/TagNames/IPTC.html $iptc_parsed = iptcparse($imageinfo['APP13']); if (is_array($iptc_parsed)) { foreach ($iptc_parsed as $iptc_key_raw => $iptc_values) { list($iptc_record, $iptc_tagkey) = explode('#', $iptc_key_raw); $iptc_tagkey = intval(ltrim($iptc_tagkey, '0')); foreach ($iptc_values as $key => $value) { @($ThisFileInfo['iptc'][$this->IPTCrecordName($iptc_record)][$this->IPTCrecordTagName($iptc_record, $iptc_tagkey)][] = $value); } } } //echo '<pre>'.htmlentities(print_r($iptc_parsed, true)).'</pre>'; } switch ($type) { case 2: // JPEG $ThisFileInfo['video']['resolution_x'] = $width; $ThisFileInfo['video']['resolution_y'] = $height; if (version_compare(phpversion(), '4.2.0', '>=')) { if (function_exists('exif_read_data')) { ob_start(); $ThisFileInfo['jpg']['exif'] = exif_read_data($ThisFileInfo['filenamepath'], '', true, false); $errors = ob_get_contents(); if ($errors) { $ThisFileInfo['warning'][] = strip_tags($errors); unset($ThisFileInfo['jpg']['exif']); } ob_end_clean(); } else { $ThisFileInfo['warning'][] = 'EXIF parsing only available when ' . (GETID3_OS_ISWINDOWS ? 'php_exif.dll enabled' : 'compiled with --enable-exif'); } } else { $ThisFileInfo['warning'][] = 'EXIF parsing only available in PHP v4.2.0 and higher compiled with --enable-exif (or php_exif.dll enabled for Windows). You are using PHP v' . phpversion(); } return true; break; default: break; } unset($ThisFileInfo['fileformat']); return false; }
/** * Method to Analyze a Media File * @param string $file Path to File * @return array Media Information */ public function analyze($file) { // Turn Off Errors $displayErrors = ini_get('display_errors'); error_reporting(0); $getID3 = new getID3(); $ThisFileInfo = $getID3->analyze($file); getid3_lib::CopyTagsToComments($ThisFileInfo); // Turn Errors back On error_reporting($displayErrors); return $ThisFileInfo; }
/** * @param object element model * @param object element params * @param string row data for this element */ function render(&$model, &$params, $file) { $src = str_replace("\\", "/", COM_FABRIK_LIVESITE . $file); ini_set('display_errors', true); require_once COM_FABRIK_FRONTEND . DS . 'libs' . DS . 'getid3' . DS . 'getid3' . DS . 'getid3.php'; require_once COM_FABRIK_FRONTEND . DS . 'libs' . DS . 'getid3' . DS . 'getid3' . DS . 'getid3.lib.php'; getid3_lib::IncludeDependency(COM_FABRIK_FRONTEND . DS . 'libs' . DS . 'getid3' . DS . 'getid3' . DS . 'extension.cache.mysql.php', __FILE__, true); $config = JFactory::getConfig(); $host = $config->getValue('host'); $database = $config->getValue('db'); $username = $config->getValue('user'); $password = $config->getValue('password'); $getID3 = new getID3_cached_mysql($host, $database, $username, $password); // Analyze file and store returned data in $ThisFileInfo $relPath = JPATH_SITE . "{$file}"; $thisFileInfo = $getID3->analyze($relPath); if (array_key_exists('video', $thisFileInfo)) { if (array_key_exists('resolution_x', $thisFileInfo['video'])) { $w = $thisFileInfo['video']['resolution_x']; $h = $thisFileInfo['video']['resolution_y']; } else { $w = $thisFileInfo['video']['streams']['2']['resolution_x']; //for wmv files $h = $thisFileInfo['video']['streams']['2']['resolution_y']; } switch ($thisFileInfo['fileformat']) { //add in space for controller case 'quicktime': $h += 16; break; default: $h += 64; } } $file = str_replace("\\", "/", COM_FABRIK_LIVESITE . $file); switch ($thisFileInfo['fileformat']) { case 'asf': $this->output = '<object id="MediaPlayer" width=' . $w . ' height=' . $h . ' classid="CLSID:22D6f312-B0F6-11D0-94AB-0080C74C7E95" standby="Loading Windows Media Player components�" type="application/x-oleobject" codebase="http://activex.microsoft.com/activex/controls/mplayer/en/nsmp2inf.cab#Version=6,4,7,1112"> <param name="filename" value="http://yourdomain/yourmovie.wmv"> <param name="Showcontrols" value="true"> <param name="autoStart" value="false"> <embed type="application/x-mplayer2" src="' . $src . '" name="MediaPlayer" width=' . $w . ' height=' . $h . '></embed> </object> '; break; default: $this->output = "<object width=\"{$w}\" height=\"{$h}\"\n\t\t\tclassid=\"clsid:02BF25D5-8C17-4B23-BC80-D3488ABDDC6B\"\n\t\t\tcodebase=\"http://www.apple.com/qtactivex/qtplugin.cab\">\n\t\t\t<param name=\"src\" value=\"{$src}\">\n\t\t\t<param name=\"autoplay\" value=\"false\">\n\t\t\t<param name=\"controller\" value=\"true\">\n\t\t\t<embed src=\"{$src}\" width=\"{$w}\" height=\"{$h}\"\n\t\t\tautoplay=\"false\" controller=\"true\"\n\t\t\tpluginspage=\"http://www.apple.com/quicktime/download/\">\n\t\t\t</embed>\n\t\t\t\n\t\t\t</object>"; break; } }
/** * retourne le tableau de l'analyse du film * * @return array */ private function _id3() { require_once 'getid3/getid3.php'; if (!$this->_id3 instanceof getID3) { $this->_id3 = new getID3(); } if (!is_array($this->_t_id3)) { $this->_t_id3 = $this->_id3->analyze($this->getPath()); getid3_lib::CopyTagsToComments($this->_t_id3); } return $this->_t_id3; }
function ParseBink(&$fd, &$ThisFileInfo) { $ThisFileInfo['fileformat'] = 'bink'; $ThisFileInfo['video']['dataformat'] = 'bink'; $fileData = 'BIK' . fread($fd, 13); $ThisFileInfo['bink']['data_size'] = getid3_lib::LittleEndian2Int(substr($fileData, 4, 4)); $ThisFileInfo['bink']['frame_count'] = getid3_lib::LittleEndian2Int(substr($fileData, 8, 2)); if ($ThisFileInfo['avdataend'] - $ThisFileInfo['avdataoffset'] != $ThisFileInfo['bink']['data_size'] + 8) { $ThisFileInfo['error'][] = 'Probably truncated file: expecting ' . $ThisFileInfo['bink']['data_size'] . ' bytes, found ' . ($ThisFileInfo['avdataend'] - $ThisFileInfo['avdataoffset']); } return true; }