Pony.fm/app/Library/getid3/demos/demo.audioinfo.class.php

317 lines
7.6 KiB
PHP
Raw Normal View History

<?php
// +----------------------------------------------------------------------+
// | PHP version 4.1.0 |
// +----------------------------------------------------------------------+
// | Placed in public domain by Allan Hansen, 2002. Share and enjoy! |
// +----------------------------------------------------------------------+
// | /demo/demo.audioinfo.class.php |
// | |
// | Example wrapper class to extract information from audio files |
// | through getID3(). |
// | |
// | getID3() returns a lot of information. Much of this information is |
// | not needed for the end-application. It is also possible that some |
// | users want to extract specific info. Modifying getID3() files is a |
// | bad idea, as modifications needs to be done to future versions of |
// | getID3(). |
// | |
// | Modify this wrapper class instead. This example extracts certain |
// | fields only and adds a new root value - encoder_options if possible. |
// | It also checks for mp3 files with wave headers. |
// +----------------------------------------------------------------------+
// | Example code: |
// | $au = new AudioInfo(); |
// | print_r($au->Info('file.flac'); |
// +----------------------------------------------------------------------+
// | Authors: Allan Hansen <ahØartemis*dk> |
// +----------------------------------------------------------------------+
//
/**
* getID3() settings
*/
require_once('../getid3/getid3.php');
/**
* Class for extracting information from audio files with getID3().
*/
2017-05-15 20:37:10 +02:00
class AudioInfo {
2017-05-15 20:37:10 +02:00
/**
* Private variables
*/
var $result = NULL;
var $info = NULL;
2017-05-15 20:37:10 +02:00
/**
* Constructor
*/
2017-05-15 20:37:10 +02:00
function AudioInfo() {
2017-05-15 20:37:10 +02:00
// Initialize getID3 engine
$this->getID3 = new getID3;
$this->getID3->option_md5_data = true;
$this->getID3->option_md5_data_source = true;
$this->getID3->encoding = 'UTF-8';
}
2017-05-15 20:37:10 +02:00
/**
* Extract information - only public function
*
* @access public
* @param string file Audio file to extract info from.
*/
2017-05-15 20:37:10 +02:00
function Info($file) {
2017-05-15 20:37:10 +02:00
// Analyze file
$this->info = $this->getID3->analyze($file);
2017-05-15 20:37:10 +02:00
// Exit here on error
if (isset($this->info['error'])) {
return array ('error' => $this->info['error']);
}
2017-05-15 20:37:10 +02:00
// 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['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'] : '');
2017-05-15 20:37:10 +02:00
// 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();
}
2017-05-15 20:37:10 +02:00
return $this->result;
}
2017-05-15 20:37:10 +02:00
/**
* post-getID3() data handling for AAC files.
*
* @access private
*/
2017-05-15 20:37:10 +02:00
function aacInfo() {
$this->result['format_name'] = 'AAC';
}
2017-05-15 20:37:10 +02:00
/**
* post-getID3() data handling for Wave files.
*
* @access private
*/
2017-05-15 20:37:10 +02:00
function riffInfo() {
if ($this->info['audio']['dataformat'] == 'wav') {
2017-05-15 20:37:10 +02:00
$this->result['format_name'] = 'Wave';
2017-05-15 20:37:10 +02:00
} elseif (preg_match('#^mp[1-3]$#', $this->info['audio']['dataformat'])) {
2017-05-15 20:37:10 +02:00
$this->result['format_name'] = strtoupper($this->info['audio']['dataformat']);
2017-05-15 20:37:10 +02:00
} else {
2017-05-15 20:37:10 +02:00
$this->result['format_name'] = 'riff/'.$this->info['audio']['dataformat'];
2017-05-15 20:37:10 +02:00
}
}
2017-05-15 20:37:10 +02:00
/**
* * post-getID3() data handling for FLAC files.
*
* @access private
*/
2017-05-15 20:37:10 +02:00
function flacInfo() {
$this->result['format_name'] = 'FLAC';
}
2017-05-15 20:37:10 +02:00
/**
* post-getID3() data handling for Monkey's Audio files.
*
* @access private
*/
2017-05-15 20:37:10 +02:00
function macInfo() {
$this->result['format_name'] = 'Monkey\'s Audio';
}
2017-05-15 20:37:10 +02:00
/**
* post-getID3() data handling for Lossless Audio files.
*
* @access private
*/
2017-05-15 20:37:10 +02:00
function laInfo() {
$this->result['format_name'] = 'La';
}
2017-05-15 20:37:10 +02:00
/**
* post-getID3() data handling for Ogg Vorbis files.
*
* @access private
*/
2017-05-15 20:37:10 +02:00
function oggInfo() {
if ($this->info['audio']['dataformat'] == 'vorbis') {
2017-05-15 20:37:10 +02:00
$this->result['format_name'] = 'Ogg Vorbis';
2017-05-15 20:37:10 +02:00
} else if ($this->info['audio']['dataformat'] == 'flac') {
2017-05-15 20:37:10 +02:00
$this->result['format_name'] = 'Ogg FLAC';
2017-05-15 20:37:10 +02:00
} else if ($this->info['audio']['dataformat'] == 'speex') {
2017-05-15 20:37:10 +02:00
$this->result['format_name'] = 'Ogg Speex';
2017-05-15 20:37:10 +02:00
} else {
2017-05-15 20:37:10 +02:00
$this->result['format_name'] = 'Ogg '.$this->info['audio']['dataformat'];
2017-05-15 20:37:10 +02:00
}
}
2017-05-15 20:37:10 +02:00
/**
* post-getID3() data handling for Musepack files.
*
* @access private
*/
2017-05-15 20:37:10 +02:00
function mpcInfo() {
$this->result['format_name'] = 'Musepack';
}
2017-05-15 20:37:10 +02:00
/**
* post-getID3() data handling for MPEG files.
*
* @access private
*/
2017-05-15 20:37:10 +02:00
function mp3Info() {
$this->result['format_name'] = 'MP3';
}
2017-05-15 20:37:10 +02:00
/**
* post-getID3() data handling for MPEG files.
*
* @access private
*/
2017-05-15 20:37:10 +02:00
function mp2Info() {
$this->result['format_name'] = 'MP2';
}
2017-05-15 20:37:10 +02:00
/**
* post-getID3() data handling for MPEG files.
*
* @access private
*/
2017-05-15 20:37:10 +02:00
function mp1Info() {
$this->result['format_name'] = 'MP1';
}
/**
* post-getID3() data handling for WMA files.
*
* @access private
*/
function asfInfo() {
$this->result['format_name'] = strtoupper($this->info['audio']['dataformat']);
}
/**
* post-getID3() data handling for Real files.
*
* @access private
*/
function realInfo() {
$this->result['format_name'] = 'Real';
}
/**
* post-getID3() data handling for VQF files.
*
* @access private
*/
function vqfInfo() {
$this->result['format_name'] = 'VQF';
}
}