function extract($full_name)
 {
     $getid3 = new getID3();
     $getid3->encoding = 'UTF-8';
     if (!is_file($full_name)) {
         return "ERROR: file ({$full_name}) does not exists";
     }
     //$g = new xml_gen;
     try {
         $time = getmicrotime();
         $getid3->Analyze($full_name);
         //die;
         $time = getmicrotime() - $time;
         $this->result['filename'] = basename($getid3->filename);
         $this->result['filesize'] = @$getid3->info['filesize'];
         $this->result['fileformat'] = @$getid3->info['fileformat'];
         if (@$getid3->info['audio']['dataformat'] && $getid3->info['audio']['dataformat'] != $getid3->info['fileformat']) {
             $this->result['audio']['dataformat'] = @$getid3->info['fileformat'];
         }
         if (@$getid3->info['video']['dataformat'] && $getid3->info['video']['dataformat'] != $getid3->info['fileformat'] && $getid3->info['video']['dataformat'] != @$getid3->info['audio']['dataformat']) {
             $this->result['video']['dataformat'] = @$getid3->info['fileformat'];
         }
         $this->result['length'] = @$getid3->info['playtime_string'];
         $this->result['bitrate'] = @$getid3->info['bitrate'] ? number_format($getid3->info['bitrate'] / 1000) . 'k' : '';
         $this->result['audio']['sample_rate'] = @$getid3->info['audio']['sample_rate'] ? number_format($getid3->info['audio']['sample_rate']) . '/' . (@$getid3->info['audio']['bits_per_sample'] ? $getid3->info['audio']['bits_per_sample'] . '/' : '') . @$getid3->info['audio']['channels'] : '';
         $this->result['artist'] = $this->result['title'] = $this->result['album'] = '';
         if (@$getid3->info['tags']) {
             foreach ($getid3->info['tags'] as $tag => $tag_info) {
                 if (@$getid3->info['tags'][$tag]['artist'] || @$getid3->info['tags'][$tag]['title'] || @$getid3->info['tags'][$tag]['album'] || @$getid3->info['tags'][$tag]['genre']) {
                     $this->result['artist'] = @implode('', @$getid3->info['tags'][$tag]['artist']);
                     $this->result['title'] = @implode('', @$getid3->info['tags'][$tag]['title']);
                     $this->result['album'] = @implode('', @$getid3->info['tags'][$tag]['album']);
                     $this->result['genre'] = @implode('', @$getid3->info['tags'][$tag]['genre']);
                     break;
                 }
             }
         }
         $this->result['tags'] = @implode(", ", @array_keys(@$getid3->info['tags']));
         $this->result['warning'] = @implode("", @$getid3->info['warning']);
         return $this->result;
     } catch (Exception $e) {
         return 'ERROR: ' . $e->message;
     }
 }
Esempio n. 2
0
 public function detect($file)
 {
     if (!extension_loaded('exif')) {
         // The getid3 library requires the exif extension.
         return false;
     }
     require_once 'getid3/getid3.php';
     $id3 = new getID3();
     $id3->encoding = 'UTF-8';
     try {
         $id3->Analyze($file);
     } catch (getid3_exception $e) {
         return false;
     }
     if (isset($id3->info['mime_type'])) {
         return $id3->info['mime_type'];
     }
     return false;
 }
Esempio n. 3
0
 function mp3titles($file)
 {
     // Title the mp3s
     // Create ID3 object
     $getid3 = new getID3();
     $getid3->encoding = 'ISO 8859-1';
     $getid3->Analyze(realpath(APPPATH . "../../") . "/" . $file);
     $artist = $title = '';
     if (@$getid3->info['tags']) {
         foreach ($getid3->info['tags'] as $tag => $tag_info) {
             if (@$getid3->info['tags'][$tag]['artist'] || @$getid3->info['tags'][$tag]['title']) {
                 $artist = @$getid3->info['tags'][$tag]['artist'][0];
                 $title = @$getid3->info['tags'][$tag]['title'][0];
                 $album = @$getid3->info['tags'][$tag]['album'][0];
                 break;
             }
         }
     }
     if (isset($album)) {
         return array("artist" => $artist, "title" => $title, "album" => $album);
     } else {
         return array("artist" => $artist, "title" => $title);
     }
 }
Esempio n. 4
0
    protected function onDetail()
    {
        if (empty($this->post['directory']) || empty($this->post['file'])) {
            return;
        }
        $file = realpath($this->path . '/' . $this->post['directory'] . '/' . $this->post['file']);
        if (!$this->checkFile($file)) {
            return;
        }
        require_once $this->options['id3Path'];
        // Xinha: The URL is weird in the standard distribution of filemanager, it seems to expect
        // that the files directory (where you are selecting/uploading) is always within the filemanager
        // directory itself somewhere.
        //
        // Also the 'baseURL' seems to be wanted as the parent of the 'basedir' ("directory" option)
        // Xinha is supplying both the same (eg url = /foo/test and dir = /home/bar/public_html/foo/test )
        // so we will rip off the first part of directory, below.
        $url = $this->options['baseURL'] . '/' . preg_replace('/^[^\\/]*\\//', '', $this->post['directory'] . '/' . $this->post['file']);
        $mime = $this->getMimeType($file);
        $content = null;
        // Xinha: We want to get some more information about what has been selected in a way
        // we can use it.  Effectively what gets put in here will be passed into the
        // 'onDetails' event handler of your FileManager object (if any).
        $extra_return_detail = array('url' => $url, 'mime' => $mime);
        if (FileManagerUtility::startsWith($mime, 'image/')) {
            $size = getimagesize($file);
            $content = '<img src="' . $url . '" class="preview" alt="" />
				<h2>${more}</h2>
				<dl>
					<dt>${width}</dt><dd>' . $size[0] . 'px</dd>
					<dt>${height}</dt><dd>' . $size[1] . 'px</dd>
				</dl>';
            // Xinha: Return some information about the image which can be access
            // from the onDetails event handler in FileManager
            $extra_return_detail['width'] = $size[0];
            $extra_return_detail['height'] = $size[1];
        } elseif (FileManagerUtility::startsWith($mime, 'text/') || $mime == 'application/x-javascript') {
            $filecontent = file_get_contents($file, null, null, 0, 300);
            if (!FileManagerUtility::isBinary($filecontent)) {
                $content = '<div class="textpreview">' . nl2br(str_replace(array('$', "\t"), array('&#36;', '&nbsp;&nbsp;'), htmlentities($filecontent))) . '</div>';
            }
        } elseif ($mime == 'application/zip') {
            $out = array(array(), array());
            $getid3 = new getID3();
            $getid3->Analyze($file);
            foreach ($getid3->info['zip']['files'] as $name => $size) {
                $icon = is_array($size) ? 'dir' : $this->getIcon($name);
                $out[$icon == 'dir' ? 0 : 1][$name] = '<li><a><img src="' . $this->options['assetBasePath'] . '/Icons/' . $icon . '.png" alt="" /> ' . $name . '</a></li>';
            }
            natcasesort($out[0]);
            natcasesort($out[1]);
            $content = '<ul>' . implode(array_merge($out[0], $out[1])) . '</ul>';
        } elseif (FileManagerUtility::startsWith($mime, 'audio/')) {
            $getid3 = new getID3();
            $getid3->Analyze($file);
            $content = '<div class="object">
					<object type="application/x-shockwave-flash" data="' . $this->options['assetBasePath'] . '/dewplayer.swf?mp3=' . rawurlencode($url) . '&volume=30" width="200" height="20">
						<param name="movie" value="' . $this->options['assetBasePath'] . '/dewplayer.swf?mp3=' . rawurlencode($url) . '&volume=30" />
					</object>
				</div>
				<h2>${more}</h2>
				<dl>
					<dt>${title}</dt><dd>' . $getid3->info['comments']['title'][0] . '</dd>
					<dt>${artist}</dt><dd>' . $getid3->info['comments']['artist'][0] . '</dd>
					<dt>${album}</dt><dd>' . $getid3->info['comments']['album'][0] . '</dd>
					<dt>${length}</dt><dd>' . $getid3->info['playtime_string'] . '</dd>
					<dt>${bitrate}</dt><dd>' . round($getid3->info['bitrate'] / 1000) . 'kbps</dd>
				</dl>';
        }
        echo json_encode(array_merge(array('content' => $content ? $content : '<div class="margin">
				${nopreview}<br/><button value="' . $url . '">${download}</button>
			</div>'), $extra_return_detail));
    }
 public function Analyze($filename)
 {
     if (file_exists($filename)) {
         // Short-hands
         $filetime = filemtime($filename);
         $filesize = filesize($filename);
         // Loopup file
         $this->cursor = mysql_query("SELECT `value` FROM `getid3_cache` WHERE (`filename` = '" . mysql_real_escape_string($filename) . "') AND (`filesize` = '" . mysql_real_escape_string($filesize) . "') AND (`filetime` = '" . mysql_real_escape_string($filetime) . "')", $this->connection);
         list($result) = @mysql_fetch_array($this->cursor);
         // Hit
         if ($result) {
             return unserialize(base64_decode($result));
         }
     }
     // Miss
     $result = parent::Analyze($filename);
     // Save result
     if (file_exists($filename)) {
         $this->cursor = mysql_query("INSERT INTO `getid3_cache` (`filename`, `filesize`, `filetime`, `analyzetime`, `value`) VALUES ('" . mysql_real_escape_string($filename) . "', '" . mysql_real_escape_string($filesize) . "', '" . mysql_real_escape_string($filetime) . "', '" . mysql_real_escape_string(time()) . "', '" . mysql_real_escape_string(base64_encode(serialize($result))) . "')", $this->connection);
     }
     return $result;
 }
Esempio n. 6
0
 /**
  * Read the file's embedded metadata with the getID3 library.
  *
  * @return getID3|bool Returns getID3 object, or false if there was an
  *  exception.
  */
 private function _getId3()
 {
     if (!$this->_id3) {
         require_once 'getid3/getid3.php';
         $id3 = new getID3();
         $id3->encoding = 'UTF-8';
         try {
             $id3->Analyze($this->getPath('original'));
             $this->_id3 = $id3;
         } catch (getid3_exception $e) {
             $message = $e->getMessage();
             _log("getID3: {$message}");
             return false;
         }
     }
     return $this->_id3;
 }
// | http://www.gnu.org/copyleft/gpl.html                                 |
// +----------------------------------------------------------------------+
// | getID3() - http://getid3.sourceforge.net or http://www.getid3.org    |
// +----------------------------------------------------------------------+
// | Authors: James Heinrich <infoØgetid3*org>                            |
// |          Allan Hansen <ahØartemis*dk>                                |
// +----------------------------------------------------------------------+
// | demo.basic.php                                                       |
// | getID3() demo file - showing the most basic use of getID3().         |
// +----------------------------------------------------------------------+
//
// $Id: demo.basic.php,v 1.3 2006/11/16 22:11:58 ah Exp $
// Enter your filename here
$filename = '/data/getid3/aiff_wave.aiff';
// Include getID3() library (can be in a different directory if full path is specified)
require_once '../getid3/getid3.php';
// Initialize getID3 engine
$getid3 = new getID3();
// Tell getID3() to use UTF-8 encoding - must send proper header as well.
$getid3->encoding = 'UTF-8';
// Tell browser telling it use UTF-8 encoding as well.
header('Content-Type: text/html; charset=UTF-8');
// Analyze file
try {
    $getid3->Analyze($filename);
    // Show audio bitrate and length
    echo 'Bitrate:  ' . @$getid3->info['audio']['bitrate'] . '<br>';
    echo 'Playtime: ' . @$getid3->info['playtime_string'] . '<br>';
} catch (Exception $e) {
    echo 'An error occured: ' . $e->message;
}
function AnalyzeDirectory()
{
    global $audio_path, $dbh;
    // Scan $audio_path
    try {
        // Build array containing filenames
        $files = array();
        ScanDirectory($audio_path, $files);
        // Initialize getID3 engine
        $getid3 = new getID3();
        $getid3->encoding = 'UTF-8';
        $getid3->option_md5_data = true;
        $getid3->option_md5_data_source = true;
        // Scan all files
        foreach ($files as $filename => $name) {
            try {
                $getid3->Analyze($filename);
                if (!@$getid3->info['audio']) {
                    xml_gen::p($name . ' skipped - not an audio file.');
                    continue;
                }
                // Extract data
                $filemtime = filemtime($filename);
                $filesize = filesize($filename);
                $filename_sls = addslashes(utf8_encode($filename));
                $format_name = @$getid3->info['fileformat'] . (@$getid3->info['audio']['dataformat'] != @$getid3->info['fileformat'] ? '/' . @$getid3->info['audio']['dataformat'] : '');
                $format_name_id = Lookup($format_name, 'format_name');
                $encoder_version_id = Lookup(@$getid3->info['audio']['encoder'], 'encoder_version');
                $encoder_options_id = Lookup(@$getid3->info['audio']['encoder_options'], 'encoder_options');
                $bitrate_mode_id = Lookup(@$getid3->info['audio']['bitrate_mode'], 'bitrate_mode');
                $channel_mode_id = Lookup(@$getid3->info['audio']['channelmode'], 'channel_mode');
                $sample_rate = (int) @$getid3->info['audio']['sample_rate'];
                $bits_per_sample = (int) @$getid3->info['audio']['bits_per_sample'];
                $lossless = (int) @$getid3->info['audio']['lossless'];
                $playtime = (double) @$getid3->info['playtime_seconds'];
                $avg_bit_rate = (double) @$getid3->info['bitrate'];
                $rg_track_gain = (double) @$getid3->info['replay_gain']['track']['adjustment'];
                $rg_album_gain = (double) @$getid3->info['replay_gain']['album']['adjustment'];
                $md5data = addslashes(@$getid3->info['md5_data_source'] ? @$getid3->info['md5_data_source'] : @$getid3->info['md5_data']);
                // Insert file entry
                $dbh->query("insert into getid3_file (filename, filemtime, filesize, format_name_id, encoder_version_id, encoder_options_id, bitrate_mode_id, channel_mode_id, sample_rate, bits_per_sample, lossless, playtime, avg_bit_rate, md5data, replaygain_track_gain, replaygain_album_gain) values ('{$filename_sls}', {$filemtime}, {$filesize}, {$format_name_id}, {$encoder_version_id}, {$encoder_options_id}, {$bitrate_mode_id}, {$channel_mode_id}, {$sample_rate}, {$bits_per_sample}, {$lossless}, {$playtime}, {$avg_bit_rate}, '{$md5data}', {$rg_track_gain}, {$rg_album_gain})");
                $file_id = $dbh->insert_id();
                // Loop thru tags
                if (@$getid3->info['tags']) {
                    foreach ($getid3->info['tags'] as $tag_name => $tag_data) {
                        // Loop thru fields
                        foreach ($tag_data as $field_name => $values) {
                            // Loop thru values
                            foreach ($values as $value) {
                                $tag_id = Lookup($tag_name, 'tag');
                                $field_id = Lookup($field_name, 'field');
                                $value_id = Lookup($value, 'value');
                                // Insert comments entry
                                $dbh->query("insert into getid3_comment (file_id, tag_id, field_id, value_id) values ({$file_id}, {$tag_id}, {$field_id}, {$value_id})");
                            }
                        }
                    }
                }
                echo xml_gen::p('#' . $file_id . ' - ' . utf8_encode($filename) . ' OK.');
                flush();
            } catch (Exception $e) {
                echo xml_gen::p_err($name . ' skipped - getID3() threw the exception: ' . $e->getmessage());
            }
        }
    } catch (Exception $e) {
        echo xml_gen::p_err('An error occured: ' . $e->getmessage());
    }
}
Esempio n. 9
0
	<!-- Playlist generated automatically using script from www.lasmit.com -->
    
    <trackList>

END_HEADER;

	if ($_REQUEST['shuffle']=="true") {
		shuffle($files);
	} else {
    	asort($files);
	}
	
	$counter = $i = 0;
    foreach ($files as $full_name => $short_name) {

	    $getid3->Analyze($dir . "/" . $short_name);	
	    
        $artist = $title = '';
            if (@$getid3->info['tags']) {
            foreach ($getid3->info['tags'] as $tag => $tag_info) {
                if (@$getid3->info['tags'][$tag]['title']) {
                    $artist = @$getid3->info['tags'][$tag]['artist'][0];
                    $title  = @$getid3->info['tags'][$tag]['title'][0];
                    $album  = @$getid3->info['tags'][$tag]['album'][0];
                    break;
                } else {
				$title  = basename($short_name, ".mp3");
				}
            }
        } else {
		$title = basename($short_name, ".mp3");
 protected function cacheAudioData()
 {
     $this->loadGetID3();
     $file = $this->FileData->fetchFilePath();
     $getid3 = new getID3();
     $getid3->Analyze($file);
     $length = $getid3->info['playtime_seconds'];
     $this->setMeta('length', $length);
     $this->setMeta('sha1', sha1_file($file));
     $this->FileData->unlinkFilePath();
 }
Esempio n. 11
0
 $filesize = $_FILES[$index]["size"];
 $tmpname = $_FILES[$index]["tmp_name"];
 $fullname = $path . $separator . $filename;
 if (preg_match('/\\.mp3$/', $filename)) {
     echo "catfolder: " . $cat_folder . "\n";
     echo "folder: " . $path . "\n";
     echo "fullname: " . $fullname . "\n";
     if (!is_dir($path)) {
         mkdir($path);
     }
     if (move_uploaded_file($tmpname, $fullname)) {
         $getid3 = new getID3();
         // Tell getID3() to use UTF-8 encoding - must send proper header as well.
         $getid3->encoding = 'UTF-8';
         try {
             $getid3->Analyze($fullname);
             $bitrate = $getid3->info['audio']['bitrate'];
             $rate = $getid3->info['audio']['sample_rate'];
             $year = $getid3->info['id3v1']['year'];
             $artist = $getid3->info['id3v1']['artist'];
             $album = $getid3->info['id3v1']['album'];
             $track = $getid3->info['id3v1']['track'];
             $title = $getid3->info['id3v1']['title'];
             $time = round($getid3->info['playtime_seconds']);
             $size = filesize($fullname);
             $addtime = time();
             $sqlfullname = str_replace("\\", "\\\\", $fullname);
             if ($title == "") {
                 $title = $filename;
             }
             $catalog_obj = $as->getCatalogFromName($user, $password, $catalog);
Esempio n. 12
0
             if ($key == 'data' && isset($var['image_mime']) && isset($var['dataoffset'])) {
                 if (md5($value) == $md5) {
                     header("Content-type: " . $var['image_mime']);
                     echo $value;
                     break;
                 }
             }
             dump_img($value, $md5);
         }
     }
 }
 $getid3->option_tags_images = true;
 // Show embedded cover
 if (@$_GET["show_img"]) {
     try {
         $getid3->Analyze($_GET['filename']);
         dump_img($getid3->info, $_GET["show_img"]);
         die;
     } catch (Exception $e) {
         echo xml_gen::p('ERROR: ' . $e->message);
     }
 }
 // Show file info
 CommonHeader($_GET['filename']);
 $pd = pathinfo($_GET['filename']);
 $pd = $pd['dirname'];
 echo xml_gen::p('Browse: ' . xml_gen::a($_SERVER['SCRIPT_NAME'] . '?directory=' . urlencode($pd), $pd));
 try {
     $getid3->Analyze($_GET['filename']);
     dump($getid3->info);
 } catch (Exception $e) {
Esempio n. 13
0
 /**
  * Analyze file with getid3 and return mysql file_id.
  */
 protected function analyze_file($filename)
 {
     // get filesize (>2Gb files not supported)
     if (!($filesize = @filesize($filename))) {
         return 0;
     }
     // get date file last modified
     $filemtime = filemtime($filename);
     // extract dir- and basename in utf8 and add slashes for mysql
     $path_info = pathinfo(@iconv($this->server_cp, 'UTF-8', $filename));
     $filename_sls = addslashes($path_info['basename']);
     $dirname_sls = addslashes($path_info['dirname']);
     // get directory_id from dirname_sls
     $this->dbh->query("select id from getid3_directory where filename='{$dirname_sls}'");
     if ($this->dbh->next_record()) {
         $directory_id = $this->dbh->f('id');
     } else {
         $root_id = $this->get_root_id($filename);
         $this->dbh->query("insert into getid3_directory (root_id, filename) values ({$root_id}, '{$dirname_sls}')");
         $directory_id = $this->dbh->insert_id();
     }
     // cached? - determined by directory_id, filename and filemtime
     $this->dbh->query("select id from getid3_file where directory_id = {$directory_id} and filename = '{$filename_sls}' and filemtime = {$filemtime} and filesize = {$filesize}");
     if ($this->dbh->next_record()) {
         // great - return id
         return $this->dbh->f('id');
     }
     // not cached - analyze file with getid3
     require_once 'getid3/getid3.php';
     // initialize getID3 engine
     $getid3 = new getID3();
     $getid3->encoding = 'UTF-8';
     $getid3->option_md5_data = true;
     $getid3->option_md5_data_source = true;
     try {
         $getid3->Analyze($filename);
     } catch (getid3_exception $e) {
         // non media files (garbage)
         if ($e->getmessage() == 'Unable to determine file format') {
             // insert in database - no need to analyse again
             $this->dbh->query("replace into getid3_file (filemtime, directory_id, filename) values ({$filemtime}, {$directory_id}, '{$filename_sls}')");
             return $this->dbh->insert_id();
         } else {
             throw $e;
         }
     }
     $format_name = @$getid3->info['fileformat'] . (@$getid3->info['audio']['dataformat'] != @$getid3->info['fileformat'] ? '/' . @$getid3->info['audio']['dataformat'] : '');
     $format_name_id = $this->getid3_lookup_format_name_id($format_name, @$getid3->info['mime_type']);
     // skip for non audio files - i.e. images
     if (@$getid3->info['audio']) {
         $encoder_version_id = $this->getid3_lookup_id(@$getid3->info['audio']['encoder'], 'encoder_version');
         $encoder_options_id = $this->getid3_lookup_id(@$getid3->info['audio']['encoder_options'], 'encoder_options');
         $bitrate_mode_id = $this->getid3_lookup_id(@$getid3->info['audio']['bitrate_mode'], 'bitrate_mode');
         $channel_mode_id = $this->getid3_lookup_id(@$getid3->info['audio']['channelmode'], 'channel_mode');
         $sample_rate = (int) @$getid3->info['audio']['sample_rate'];
         $bits_per_sample = (int) @$getid3->info['audio']['bits_per_sample'];
         $channels = (int) @$getid3->info['audio']['channels'];
         $lossless = (int) @$getid3->info['audio']['lossless'];
         $playtime = (double) @$getid3->info['playtime_seconds'];
         $avg_bit_rate = (double) @$getid3->info['bitrate'];
         $rg_track_gain = isset($getid3->info['replay_gain']['track']['adjustment']) ? (double) $getid3->info['replay_gain']['track']['adjustment'] : 'null';
         $rg_album_gain = isset($getid3->info['replay_gain']['album']['adjustment']) ? (double) $getid3->info['replay_gain']['album']['adjustment'] : 'null';
         $md5_data = $getid3->info['md5_data'];
         // insert audio file entry
         $this->dbh->query("replace into getid3_file (directory_id, filename, filemtime, filesize, format_name_id, encoder_version_id, encoder_options_id, bitrate_mode_id, channel_mode_id, sample_rate, bits_per_sample, channels, lossless, playtime, avg_bit_rate, replaygain_track_gain, replaygain_album_gain, md5_data) values ({$directory_id}, '{$filename_sls}', {$filemtime}, {$filesize}, {$format_name_id}, 0{$encoder_version_id}, 0{$encoder_options_id}, 0{$bitrate_mode_id}, 0{$channel_mode_id}, {$sample_rate}, {$bits_per_sample}, {$channels}, {$lossless}, {$playtime}, {$avg_bit_rate}, {$rg_track_gain}, {$rg_album_gain}, '{$md5_data}')");
     } else {
         // insert audio file entry
         $this->dbh->query("replace into getid3_file (directory_id, filename, filemtime, filesize, format_name_id) values ({$directory_id}, '{$filename_sls}', {$filemtime}, {$filesize}, {$format_name_id})");
     }
     $file_id = $this->dbh->insert_id();
     // loop thru tags
     if (@$getid3->info['tags']) {
         foreach ($getid3->info['tags'] as $tag_name => $tag_data) {
             // loop thru fields
             foreach ($tag_data as $field_name => $values) {
                 // loop thru values
                 foreach ($values as $value) {
                     $field_id = $this->getid3_lookup_id($field_name, 'field');
                     $value_id = $this->getid3_lookup_id($value, 'value');
                     // insert comments entry
                     $this->dbh->query("replace into getid3_comment (file_id, field_id, value_id) values ({$file_id}, {$field_id}, {$value_id})");
                 }
             }
         }
     }
     return $file_id;
 }
Esempio n. 14
0
function getPlaytimeID3($file)
{
    // Initialize getID3 engine
    $getid3 = new getID3();
    // Tell getID3() to use UTF-8 encoding - must send proper header as well.
    $getid3->encoding = 'UTF-8';
    $result = array();
    try {
        $info = $getid3->Analyze($file);
        if (isset($info["playtime_seconds"])) {
            $result[0] = true;
            $result[1] = $info["playtime_seconds"];
        } else {
            $result[0] = false;
            $result[1] = "file format doesnt have playtime";
        }
        return $result;
    } catch (Exception $e) {
        $result[0] = false;
        $result[1] = $e->message;
        return $result;
    }
}
Esempio n. 15
0
 protected function onDetail()
 {
     if (empty($this->post['file'])) {
         return;
     }
     $file = $this->basedir . $this->post['directory'] . $this->post['file'];
     if (!$this->checkFile($file)) {
         return;
     }
     $url = str_replace($_SERVER['DOCUMENT_ROOT'], '', $this->normalize($file));
     $mime = $this->getMimeType($file);
     $content = null;
     // image
     if (FileManagerUtility::startsWith($mime, 'image/')) {
         // generates a random number to put on the end of the image, to prevent caching
         $randomImage = '?' . md5(uniqid(rand(), 1));
         $size = getimagesize($file);
         $content = '<dl>
       <dt>${width}</dt><dd>' . $size[0] . 'px</dd>
       <dt>${height}</dt><dd>' . $size[1] . 'px</dd>
     </dl>
     <h2>${preview}</h2>
     <a href="' . $url . '" data-milkbox="preview" title="' . str_replace($_SERVER['DOCUMENT_ROOT'], '', $file) . '"><img src="' . $this->options['thumbnailPath'] . $this->getThumb($this->normalize($file)) . $randomImage . '" class="preview" alt="preview" /></a>
     ';
         // text preview
     } elseif (FileManagerUtility::startsWith($mime, 'text/') || $mime == 'application/x-javascript') {
         $filecontent = file_get_contents($file, false, null, 0);
         if (!FileManagerUtility::isBinary($filecontent)) {
             $content = '<div class="textpreview"><pre>' . str_replace(array('$', "\t"), array('&#36;', '&nbsp;&nbsp;'), htmlentities($filecontent, ENT_QUOTES, 'UTF-8')) . '</pre></div>';
         }
         // zip
     } elseif ($mime == 'application/zip') {
         require_once dirname(__FILE__) . '/Assets/getid3/getid3.php';
         $out = array(array(), array());
         $getid3 = new getID3();
         $getid3->Analyze($file);
         foreach ($getid3->info['zip']['files'] as $name => $size) {
             $dir = is_array($size) ? true : true;
             $out[$dir ? 0 : 1][$name] = '<li><a><img src="' . $this->getIcon($name, true) . '" alt="" /> ' . $name . '</a></li>';
         }
         natcasesort($out[0]);
         natcasesort($out[1]);
         $content = '<ul>' . implode(array_merge($out[0], $out[1])) . '</ul>';
         // swf
     } elseif ($mime == 'application/x-shockwave-flash') {
         require_once dirname(__FILE__) . '/Assets/getid3/getid3.php';
         $getid3 = new getID3();
         $getid3->Analyze($file);
         $content = '<dl>
       <dt>${width}</dt><dd>' . $getid3->info['swf']['header']['frame_width'] / 10 . 'px</dd>
       <dt>${height}</dt><dd>' . $getid3->info['swf']['header']['frame_height'] / 10 . 'px</dd>
       <dt>${length}</dt><dd>' . round($getid3->info['swf']['header']['length'] / $getid3->info['swf']['header']['frame_count']) . 's</dd>
     </dl>
     <h2>${preview}</h2>
     <div class="object">
       <object type="application/x-shockwave-flash" data="' . str_replace($_SERVER['DOCUMENT_ROOT'], '', $file) . '" width="500" height="400">
         <param name="scale" value="noscale" />
         <param name="movie" value="' . str_replace($_SERVER['DOCUMENT_ROOT'], '', $file) . '" />
       </object>
     </div>';
         // audio
     } elseif (FileManagerUtility::startsWith($mime, 'audio/')) {
         require_once dirname(__FILE__) . '/Assets/getid3/getid3.php';
         $getid3 = new getID3();
         $getid3->encoding = "UTF-8";
         $getid3->Analyze($file);
         $title = str_replace("\$", "&#36;", !empty($getid3->info['tags']['id3v2']['title'][0]) ? $getid3->info['tags']['id3v2']['title'][0] : (!empty($getid3->info['tags']['id3v1']['title'][0]) ? $getid3->info['tags']['id3v1']['title'][0] : "-"));
         $artist = str_replace("\$", "&#36;", !empty($getid3->info['tags']['id3v2']['artist'][0]) ? $getid3->info['tags']['id3v2']['artist'][0] : (!empty($getid3->info['tags']['id3v1']['artist'][0]) ? $getid3->info['tags']['id3v1']['artist'][0] : "-"));
         $album = str_replace("\$", "&#36;", !empty($getid3->info['tags']['id3v2']['album'][0]) ? $getid3->info['tags']['id3v2']['album'][0] : (!empty($getid3->info['tags']['id3v1']['album'][0]) ? $getid3->info['tags']['id3v1']['album'][0] : "-"));
         $content = '<dl>
       <dt>${title}</dt><dd>' . $title . '</dd>
       <dt>${artist}</dt><dd>' . $artist . '</dd>
       <dt>${album}</dt><dd>' . $album . '</dd>
       <dt>${length}</dt><dd>' . (!empty($getid3->info['playtime_string']) ? $getid3->info['playtime_string'] : "-") . '</dd>
       <dt>${bitrate}</dt><dd>' . (!empty($getid3->info['bitrate']) ? round($getid3->info['bitrate'] / 1000) . "kbps" : "-") . '</dd>
     </dl>
     <h2>${preview}</h2>
     <div class="object">
       <object type="application/x-shockwave-flash" data="' . $this->options['assetBasePath'] . '/dewplayer.swf" width="200" height="20" id="dewplayer" name="dewplayer">
         <param name="wmode" value="transparent" />
         <param name="movie" value="' . $this->options['assetBasePath'] . '/dewplayer.swf" />
         <param name="flashvars" value="mp3=' . rawurlencode($url) . '&amp;volume=50&amp;showtime=1" />
       </object>
     </div>';
     }
     echo json_encode(array('content' => $content ? $content : '<div class="margin">
     ${nopreview}
   </div>'));
 }
Esempio n. 16
0
    protected function onDetail()
    {
        if (empty($this->post['directory']) || empty($this->post['file'])) {
            return;
        }
        $file = realpath($this->path . '/' . $this->post['directory'] . '/' . $this->post['file']);
        if (!$this->checkFile($file)) {
            return;
        }
        require_once $this->options['id3Path'];
        $url = $this->options['baseURL'] . $this->normalize(substr($file, strlen($this->path) + 1));
        $mime = $this->getMimeType($file);
        $content = null;
        if (FileManagerUtility::startsWith($mime, 'image/')) {
            $size = getimagesize($file);
            $content = '<img src="' . $url . '" class="preview" alt="" />
				<h2>${more}</h2>
				<dl>
					<dt>${width}</dt><dd>' . $size[0] . 'px</dd>
					<dt>${height}</dt><dd>' . $size[1] . 'px</dd>
				</dl>';
        } elseif (FileManagerUtility::startsWith($mime, 'text/') || $mime == 'application/x-javascript') {
            $filecontent = file_get_contents($file, null, null, 0, 300);
            if (!FileManagerUtility::isBinary($filecontent)) {
                $content = '<div class="textpreview">' . nl2br(str_replace(array('$', "\t"), array('&#36;', '&nbsp;&nbsp;'), htmlentities($filecontent))) . '</div>';
            }
        } elseif ($mime == 'application/zip') {
            $out = array(array(), array());
            $getid3 = new getID3();
            $getid3->Analyze($file);
            foreach ($getid3->info['zip']['files'] as $name => $size) {
                $icon = is_array($size) ? 'dir' : $this->getIcon($name);
                $out[$icon == 'dir' ? 0 : 1][$name] = '<li><a><img src="' . $this->options['assetBasePath'] . '/Icons/' . $icon . '.png" alt="" /> ' . $name . '</a></li>';
            }
            natcasesort($out[0]);
            natcasesort($out[1]);
            $content = '<ul>' . implode(array_merge($out[0], $out[1])) . '</ul>';
        } elseif (FileManagerUtility::startsWith($mime, 'audio/')) {
            $getid3 = new getID3();
            $getid3->Analyze($file);
            $content = '<div class="object">
					<object type="application/x-shockwave-flash" data="' . $this->options['assetBasePath'] . '/dewplayer.swf?mp3=' . rawurlencode($url) . '&volume=30" width="200" height="20">
						<param name="movie" value="' . $this->options['assetBasePath'] . '/dewplayer.swf?mp3=' . rawurlencode($url) . '&volume=30" />
					</object>
				</div>
				<h2>${more}</h2>
				<dl>
					<dt>${title}</dt><dd>' . $getid3->info['comments']['title'][0] . '</dd>
					<dt>${artist}</dt><dd>' . $getid3->info['comments']['artist'][0] . '</dd>
					<dt>${album}</dt><dd>' . $getid3->info['comments']['album'][0] . '</dd>
					<dt>${length}</dt><dd>' . $getid3->info['playtime_string'] . '</dd>
					<dt>${bitrate}</dt><dd>' . round($getid3->info['bitrate'] / 1000) . 'kbps</dd>
				</dl>';
        }
        echo json_encode(array('content' => $content ? $content : '<div class="margin">
				${nopreview}<br/><button value="' . $url . '">${download}</button>
			</div>'));
    }
Esempio n. 17
0
    /**
     * Produce a HTML snippet detailing the given file.
     *
     * Return NULL on error.
     */
    public function extractDetailInfo($legal_url, $file, $mime)
    {
        $url = $this->legal2abs_url_path($legal_url);
        $filename = pathinfo($url, PATHINFO_BASENAME);
        $content = null;
        if (FileManagerUtility::startsWith($mime, 'image/')) {
            // generates a random number to put on the end of the image, to prevent caching
            //$randomImage = '?'.md5(uniqid(rand(),1));
            // getID3 is slower as it *copies* the image to the temp dir before processing: see GetDataImageSize().
            // This is done as getID3 can also analyze *embedded* images, for which this approach is required.
            $getid3 = new getID3();
            $getid3->encoding = 'UTF-8';
            $getid3->Analyze($file);
            //$size = @getimagesize($file);
            //// check for badly formatted image files (corruption); we'll handle the overly large ones next
            //if (!$size)
            //  throw new FileManagerException('corrupt_img:' . $url);
            $sw_make = $this->getID3infoItem($getid3, null, 'jpg', 'exif', 'IFD0', 'Software');
            $time_make = $this->getID3infoItem($getid3, null, 'jpg', 'exif', 'IFD0', 'DateTime');
            $content = '<dl>
						<dt>${width}</dt><dd>' . $this->getID3infoItem($getid3, 0, 'video', 'resolution_x') . 'px</dd>
						<dt>${height}</dt><dd>' . $this->getID3infoItem($getid3, 0, 'video', 'resolution_y') . 'px</dd>
					</dl>';
            if (!empty($sw_make) || !empty($time_make)) {
                $content .= '<p>Made with ' . (empty($sw_make) ? '???' : $sw_make) . ' @ ' . (empty($time_make) ? '???' : $time_make) . '</p>';
            }
            $content .= '
					<h2>${preview}</h2>
					';
            $emsg = null;
            try {
                $thumbfile = $this->getThumb($legal_url, $file);
            } catch (Exception $e) {
                $emsg = $e->getMessage();
                $thumbfile = $this->getIconForError($emsg, $legal_url, false);
            }
            $content .= '<a href="' . FileManagerUtility::rawurlencode_path($url) . '" data-milkbox="preview" title="' . htmlentities($filename, ENT_QUOTES, 'UTF-8') . '">
							   <img src="' . FileManagerUtility::rawurlencode_path($thumbfile) . '" class="preview" alt="preview" />
							 </a>';
            if (!empty($emsg) && strpos($emsg, 'img_will_not_fit') !== false) {
                $earr = explode(':', $e->getMessage(), 2);
                $content .= "\n" . '<p class="tech_info">Estimated minimum memory requirements to create thumbnails for this image: ' . $earr[1] . '</p>';
            }
            $finfo = Image::guestimateRequiredMemorySpace($file);
            if (!empty($finfo['usage_guestimate']) && !empty($finfo['usage_min_advised'])) {
                $content .= "\n" . '<p class="tech_info">memory used: ' . number_format(memory_get_peak_usage() / 1000000.0, 1) . ' MB / estimated: ' . number_format($finfo['usage_guestimate'] / 1000000.0, 1) . ' MB / suggested: ' . number_format($finfo['usage_min_advised'] / 1000000.0, 1) . ' MB</p>';
            }
            $exif_data = $this->getID3infoItem($getid3, null, 'jpg', 'exif');
            try {
                if (!empty($exif_data)) {
                    /*
                     * before dumping the EXIF data array (which may carry binary content and MAY CRASH the json_encode()r >:-((
                     * we filter it to prevent such crashes and oddly looking (diagnostic) presentation of values.
                     */
                    self::clean_EXIF_results($exif_data);
                    ob_start();
                    var_dump($exif_data);
                    //return $content;
                    $dump = ob_get_clean();
                    $content .= $dump;
                }
            } catch (Exception $e) {
                $content .= 'kleppertje: ' . $e->getMessage();
            }
        } elseif (FileManagerUtility::startsWith($mime, 'text/') || $mime == 'application/x-javascript') {
            // text preview:
            $filecontent = @file_get_contents($file, false, null, 0);
            if ($filecontent === false) {
                throw new FileManagerException('nofile');
            }
            if (!FileManagerUtility::isBinary($filecontent)) {
                $content = '<div class="textpreview"><pre>' . str_replace(array('$', "\t"), array('&#36;', '&nbsp;&nbsp;'), htmlentities($filecontent, ENT_NOQUOTES, 'UTF-8')) . '</pre></div>';
            }
            // else: fall back to 'no preview available'
        } elseif ($mime == 'application/zip') {
            $out = array(array(), array());
            $getid3 = new getID3();
            $getid3->Analyze($file);
            $info = $this->getID3infoItem($getid3, null, 'zip', 'files');
            if (is_array($info)) {
                foreach ($info as $name => $size) {
                    $isdir = is_array($size) ? true : false;
                    $out[$isdir ? 0 : 1][$name] = '<li><a><img src="' . FileManagerUtility::rawurlencode_path($this->getIcon($name, true)) . '" alt="" /> ' . $name . '</a></li>';
                }
                natcasesort($out[0]);
                natcasesort($out[1]);
                $content = '<ul>' . implode(array_merge($out[0], $out[1])) . '</ul>';
            }
        } elseif ($mime == 'application/x-shockwave-flash') {
            $getid3 = new getID3();
            $getid3->Analyze($file);
            $info = $this->getID3infoItem($getid3, null, 'swf', 'header');
            if (is_array($info)) {
                // Note: preview data= urls were formatted like this in CCMS:
                // $this->options['assetBasePath'] . 'dewplayer.swf?mp3=' . rawurlencode($url) . '&volume=30'
                $content = '<dl>
							<dt>${width}</dt><dd>' . $this->getID3infoItem($getid3, 0, 'swf', 'header', 'frame_width') / 10 . 'px</dd>
							<dt>${height}</dt><dd>' . $this->getID3infoItem($getid3, 0, 'swf', 'header', 'frame_height') / 10 . 'px</dd>
							<dt>${length}</dt><dd>' . round($this->getID3infoItem($getid3, 0, 'swf', 'header', 'length') / $this->getID3infoItem($getid3, 25, 'swf', 'header', 'frame_count')) . 's</dd>
						</dl>
						<h2>${preview}</h2>
						<div class="object">
							<object type="application/x-shockwave-flash" data="' . FileManagerUtility::rawurlencode_path($url) . '" width="500" height="400">
								<param name="scale" value="noscale" />
								<param name="movie" value="' . FileManagerUtility::rawurlencode_path($url) . '" />
							</object>
						</div>';
            }
        } elseif (FileManagerUtility::startsWith($mime, 'audio/')) {
            $getid3 = new getID3();
            $getid3->Analyze($file);
            getid3_lib::CopyTagsToComments($getid3->info);
            $dewplayer = FileManagerUtility::rawurlencode_path($this->options['assetBasePath'] . 'dewplayer.swf');
            // Note: these next several indexed array fetches were marked with @ in CCMS to catch some failures...
            //
            // TODO: do it cleaner then that!
            //
            // DONE!
            $content = '<dl>
						<dt>${title}</dt><dd>' . $this->getID3infoItem($getid3, '???', 'comments', 'title', 0) . '</dd>
						<dt>${artist}</dt><dd>' . $this->getID3infoItem($getid3, '???', 'comments', 'artist', 0) . '</dd>
						<dt>${album}</dt><dd>' . $this->getID3infoItem($getid3, '???', 'comments', 'album', 0) . '</dd>
						<dt>${length}</dt><dd>' . $this->getID3infoItem($getid3, '???', 'playtime_string') . '</dd>
						<dt>${bitrate}</dt><dd>' . round($this->getID3infoItem($getid3, 0, 'bitrate') / 1000) . 'kbps</dd>
					</dl>
					<h2>${preview}</h2>
					<div class="object">
						<object type="application/x-shockwave-flash" data="' . $dewplayer . '" width="200" height="20" id="dewplayer" name="dewplayer">
							<param name="wmode" value="transparent" />
							<param name="movie" value="' . $dewplayer . '" />
							<param name="flashvars" value="mp3=' . FileManagerUtility::rawurlencode_path($url) . '&amp;volume=50&amp;showtime=1" />
						</object>
					</div>';
        } else {
            // else: fall back to 'no preview available'
            try {
                $getid3 = new getID3();
                $getid3->encoding = 'UTF-8';
                $getid3->Analyze($file);
                ob_start();
                var_dump($getid3->info);
                $dump = ob_get_clean();
                // $dump may dump object IDs and other binary stuff, which will completely b0rk json_encode: make it palatable:
                // strip the NULs out:
                $dump = str_replace('&#0;', '?', $dump);
                //$dump = html_entity_decode(strip_tags($dump), ENT_QUOTES, 'UTF-8');
                //@file_put_contents('getid3.raw.log', $dump);
                // since the regex matcher leaves NUL bytes alone, we do those above in undecoded form; the rest is treated here
                $dump = preg_replace("/[^ -~\n\r\t]/", '?', $dump);
                // remove everything outside ASCII range; some of the high byte values seem to crash json_encode()!
                // and reduce long sequences of unknown charcodes:
                $dump = preg_replace('/\\?{8,}/', '???????', $dump);
                //$dump = html_entity_encode(strip_tags($dump), ENT_NOQUOTES, 'UTF-8');
                $content = '<div class="margin">
								<h2>${preview}</h2>
								<pre>' . "\n" . $dump . "\n" . '</pre></div>';
                //@file_put_contents('getid3.log', $dump);
                return $content;
            } catch (Exception $e) {
                // ignore
                $content = $e->getMessage();
            }
            $content = '<div class="margin">
							${nopreview} ' . $content . '
						</div>';
        }
        return self::compressHTML($content);
    }
Esempio n. 18
-1
function getFLVDuration($flv_path)
{
    $getid3 = new getID3();
    $getid3->encoding = 'UTF-8';
    try {
        $getid3->Analyze($flv_path);
        return $getid3->info['playtime_seconds'];
    } catch (Exception $e) {
        return 0;
    }
}