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; }
/** * get metadata info for a media file * * @param $path * @return array */ public function extract($path) { if (ini_get('allow_url_fopen')) { $file = \OC\Files\Filesystem::getView()->getAbsolutePath($path); $data = @$this->getID3->analyze('oc://' . $file); } else { // Fallback to the local FS $file = \OC\Files\Filesystem::getLocalFile($path); } \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; }
public function getImageData($filename, $callback) { global $getID3; // Get sound meta try { $id3 = $getID3->analyze($filename); getid3_lib::CopyTagsToComments($id3); } catch (Exception $e) { $callback(json_encode((object) array('result' => 'error', 'file' => $filename, 'error' => $e->getMessage())), ''); return; } if (isset($id3['comments']['picture'][0])) { $callback(base64_encode($id3['comments']['picture'][0]['data']), $id3['comments']['picture'][0]['image_mime']); } else { $callback('', ''); } }
/** * 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 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; }
/** * 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 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 : ''; } }
/** * 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; }
/** * 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; }
/** * Intesive analysis of file contents. Does _not_ make changes to the file or store anything in the DB! * * @param type $file * @return type */ private static function AnalyzeFile($file) { @ini_set('max_execution_time', '0'); @set_time_limit(0); $filename = is_string($file) ? $file : $file->GetLocalPath(); $info = WPFB_Core::$settings->disable_id3 ? array() : self::GetEngine()->analyze($filename); getid3_lib::CopyTagsToComments($info); if (!empty($_GET['debug'])) { wpfb_loadclass('Sync'); WPFB_Sync::PrintDebugTrace("file_analyzed_" . $file->GetLocalPathRel()); } return $info; }
public function analyze($filename) { if (!file_exists($filename)) { $this->setError("File Doesn't Exist!"); return FALSE; } if ($this->getid3->Analyze($filename)) { getid3_lib::CopyTagsToComments($this->getid3->info); } $this->analyzed = TRUE; $this->info = $this->getid3->info; return TRUE; }
/** * get metadata info for a media file * * @param $path the path to the file * @return array extracted data */ public function extract($path) { $metadata = $this->getID3->analyze($path); // TODO make non static \getid3_lib::CopyTagsToComments($metadata); if (array_key_exists('error', $metadata)) { foreach ($metadata['error'] as $error) { // TODO $error is base64 encoded but it wasn't possible to add the decoded part to the log message $this->logger->log('getID3 error occured', 'debug'); // sometimes $error is string but can't be concatenated to another string and weirdly just hide the log message $this->logger->log('getID3 error message: ' . $error, 'debug'); } } return $metadata; }
/** * {@inheritDoc} */ public function getThumbnail($path, $maxX, $maxY, $scalingup, $fileview) { $getID3 = new \getID3(); $tmpPath = $fileview->toTmpFile($path); $tags = $getID3->analyze($tmpPath); \getid3_lib::CopyTagsToComments($tags); if (isset($tags['id3v2']['APIC'][0]['data'])) { $picture = @$tags['id3v2']['APIC'][0]['data']; unlink($tmpPath); $image = new \OC_Image(); $image->loadFromData($picture); return $image->valid() ? $image : $this->getNoCoverThumbnail(); } return $this->getNoCoverThumbnail(); }
public function getMetadata() { $output = array(); $getID3 = new getID3(); $target = $this->source; $content = $getID3->analyze($target); getid3_lib::CopyTagsToComments($content); if (array_key_exists('error', $content)) { foreach ($content['error'] as $error) { trigger_error($error); } return false; } else { $metaArrays = array('comments_html', 'comments', 'tags_html', 'tags'); $contentKeys = array_keys($content); $key = false; $output['duration'] = $content['playtime_seconds']; $output['md5'] = $content['md5_data_source']; // foreach($content as $k => $v) { // ifecho($k); // } foreach ($metaArrays as $meta) { if (array_key_exists($meta, $content)) { $key = $meta; break; } } if ($key === false) { return false; } foreach ($content[$key] as $k => $v) { if ($k === 'picture') { file_put_contents($GLOBALS['cfg_tmp_folder'] . DIRECTORY_SEPARATOR . md5($this->source) . 'jpg', base64_decode($v)); } if ($k !== 'picture') { if (is_array($v)) { foreach ($v as $kx => $vx) { if ($kx !== 'picture') { $output[$k] = $vx; } } } } } $this->metadata = $output; return $this->metadata; } }
/** * 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) { global $config; $path = realpath(trim($path)); if (is_file($path)) { if (!$this->pathExist($path)) { $oggaudio = false; $getid3_skipped = false; if (sotf_File::getExtension($path) == 'ogg') { $getID3 = new getID3(); $fileinfo = $getID3->analyze($path); getid3_lib::CopyTagsToComments($fileinfo); if (isset($fileinfo['audio']) && !isset($fileinfo['video'])) { $oggaudio = true; } else { $getid3_skipped = true; } } else { if (!in_array(sotf_File::getExtension($path), $config['skipGetID3FileTypes'])) { // CHANGED BY BUDDHAFLY 06-02-14 $getID3 = new getID3(); $fileinfo = $getID3->analyze($path); getid3_lib::CopyTagsToComments($fileinfo); //$fileinfo = GetAllFileInfo($this->path); } else { $getid3_skipped = true; } } if (!$oggaudio && $getid3_skipped) { $fileinfo['video'] = true; } //$audioinfo = GetAllFileInfo($path); if (isset($fileinfo["video"])) { $this->list[] =& new sotf_VideoFile($path, $fileinfo); } else { if (isset($fileinfo["audio"])) { $this->list[] =& new sotf_AudioFile($path, $fileinfo); } else { $this->list[] =& new sotf_File($path); } } // if-elseif-else } //if } //if return false; }
public function __construct($filepath) { // force string on filename (when using recursive file iterator, // objects are returned) $filepath = (string) $filepath; if (!extension_loaded('Imagick')) { throw new Exception("Imagic extension required. Not loaded"); } if (!file_exists($filepath)) { throw new Exception("{$filepath} not found"); } if (!is_readable($filepath)) { throw new Exception("permission denied reading {$filepath}"); } $this->path = $filepath; $this->dir = dirname($filepath) . '/'; $getID3 = new getID3(); $this->analysis = $getID3->analyze($filepath); if (@isset($this->analysis['error'])) { throw new Exception($this->analysis['error'][0]); } if (!isset($this->analysis['id3v1']) and !isset($this->analysis['id3v2'])) { throw new Exception("no ID3v1 or ID3v2 tags in {$filepath}"); } // aggregate both tag formats (clobbering other metadata) getid3_lib::CopyTagsToComments($this->analysis); @($this->title = $this->analysis['comments']['title'][0]); @($this->artist = $this->analysis['comments']['artist'][0]); @($this->year = $this->analysis['comments']['year'][0]); @($this->genre = $this->analysis['comments']['genre'][0]); @($this->album = $this->analysis['comments']['album'][0]); @($seconds = ceil($this->analysis['playtime_seconds'])); @($this->time = floor($seconds / 60) . ':' . str_pad($seconds % 60, 2, "0", STR_PAD_LEFT)); if (!$this->title) { throw new Exception("No title found in {$filepath}"); } if (!$this->album) { $this->album = 'Various artists'; } $this->assignAlbumArt(); // set an ID relative to metadata $this->id = md5($this->artist . $this->album . $this->title); // let's guess quality is proportional to bitrate @($this->quality = floor($this->analysis['audio']['bitrate'] / 1000)); // remove the getID3 analysis -- it's massive. It should not be indexed! unset($this->analysis); }
function analyzeFile($file, $playlist_data) { global $validExtensions, $getID3; $fileURL = BASE_URL . '/files/' . $file; $file = FILE_DIR . '/' . $file; // use cache, if available $cachefile = 'cache/' . md5($file) . '.cache.php'; if (file_exists($cachefile)) { require $cachefile; $row = array_merge($row, $playlist_data); return $row; } // Get ID3 tags and whatnot $data = $getID3->analyze($file); getid3_lib::CopyTagsToComments($data); // We need a playtime. Abort if not found. if (!isset($data['playtime_seconds'])) { echo "<h2>{$file}</h2>"; var_dump($data); return; } //@formatter:off $row = array('title' => '???', 'artist' => 'Unknown', 'album' => '', 'url' => $fileURL, 'length' => '' . (int) ($data['playtime_seconds'] * 10)); //@formatter:on if (isset($data['comments_html']) && (array_key_exists('artist', $data['comments_html']) || array_key_exists('album', $data['comments_html']))) { $row['title'] = $data['comments_html']['title'][0]; if (isset($data['comments']['artist'])) { $row['artist'] = $data['comments']['artist'][0]; } if (isset($data['comments']['album'])) { $row['album'] = $data['comments']['album'][0]; } } else { $matches = array(); // Search for something of the form "artist - title (album).ext" if (preg_match('/([^\\-]+)\\-([^\\(\\.]+)(\\(([^\\)])\\))?\\.([a-z0-9]{3})/', $file, $matches) !== FALSE) { if (count($matches) >= 2) { $row['artist'] = trim($matches[1]); $row['title'] = trim($matches[2]); $row['album'] = trim($matches[3]); } } } file_put_contents($cachefile, '<?php $row=' . var_export($row, true) . ';'); $row = array_merge($row, $playlist_data); return $row; }
function initialize($Media) { if (isset($Media->objects['getID3'])) { return true; } if (!isset($Media->file)) { return false; } $Object = new getID3(); $Object->encoding = 'UTF-8'; $Object->analyze($Media->file); if (isset($Object->info['error'])) { return false; } getid3_lib::CopyTagsToComments($Object->info); $Media->objects['getID3'] =& $Object; return true; }
private function _getNewPathname($pathname) { require_once $this->_getId3Pathname; $getId3 = new getID3(); $info = $getId3->analyze($pathname); getid3_lib::CopyTagsToComments($info); if (null !== $info['error']) { return false; } $artist = $info['comments_html']['artist'][0]; $title = $info['tags']['id3v2']['title'][0]; $newFilename = $this->_formatFilename($artist) . '_' . $this->_formatFilename($title); if ('_' == $newFilename) { $newFilename = $info['filename']; } else { $newFilename .= '.' . $info['fileformat']; } return $info['filepath'] . DIRECTORY_SEPARATOR . $newFilename; }
/** * Show the application welcome screen to the user. * * @return Response */ public function index() { $dir = '/var/lib/openshift/56843b142d5271dd4900010b/app-root/repo/public/music/'; $getID3 = new \getID3(); $DirectoryToScan = $dir; $dir = opendir($DirectoryToScan); $cnt = 1; $musicArray = $music = array(); while (($file = readdir($dir)) !== false) { $FullFileName = realpath($DirectoryToScan . '/' . $file); if (substr($FullFileName, 0, 1) != '.' && is_file($FullFileName)) { $ThisFileInfo = $getID3->analyze($FullFileName); \getid3_lib::CopyTagsToComments($ThisFileInfo); $values = explode(":", $ThisFileInfo['playtime_string']); $musicArray['music-' . $file] = ($values[0] * 60 + $values[1]) * 1000 - 1000; $music[] = $ThisFileInfo; } } return view('welcome', ['music' => $music, 'musicArray' => $musicArray]); }
/** * 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)) { //CHANGED BY BUDDHAFLY 06-05-12 //echo $path; $getID3 = new getID3(); $audioinfo = $getID3->analyze($path); getid3_lib::CopyTagsToComments($audioinfo); //print_r ($fileinfo); //$audioinfo = GetAllFileInfo($path); if (isset($audioinfo["audio"])) { $this->list[] =& new sotf_AudioFile($path); } else { $this->list[] =& new sotf_File($path); } } } return false; }
/** * Intesive analysis of file contents. Does _not_ make changes to the file or store anything in the DB! * * @param type $file * @return type */ private static function analyzeFile($file) { @ini_set('max_execution_time', '0'); @set_time_limit(0); $filename = is_string($file) ? $file : $file->GetLocalPath(); $times = array(); $times['analyze'] = microtime(true); $info = WPFB_Core::$settings->disable_id3 ? array() : self::GetEngine()->analyze($filename); if (!WPFB_Core::$settings->disable_id3 && class_exists('getid3_lib')) { getid3_lib::CopyTagsToComments($info); } if (!empty($_GET['debug'])) { wpfb_loadclass('Sync'); WPFB_Sync::PrintDebugTrace("file_analyzed_" . $file->GetLocalPathRel()); } $times['end'] = microtime(true); $t_keys = array_keys($times); $into['debug'] = array('timestamp' => $times[$t_keys[0]], 'timings' => array()); for ($i = 1; $i < count($t_keys); $i++) { $info['debug']['timings'][$t_keys[$i - 1]] = round(($times[$t_keys[$i]] - $times[$t_keys[$i - 1]]) * 1000); } return $info; }