Created a new Metadata class to hold static functions which parse audio
file metadata. This got rid of the "camp_" prefixes on the function names.
This commit is contained in:
parent
1c2ff6c150
commit
95a4694b5a
|
@ -124,7 +124,7 @@ class PluploadController extends Zend_Controller_Action
|
|||
}
|
||||
}
|
||||
|
||||
$metadata = camp_get_audio_metadata($audio_file);
|
||||
$metadata = Metadata::LoadFromFile($audio_file);
|
||||
|
||||
if (PEAR::isError($metadata)) {
|
||||
die('{"jsonrpc" : "2.0", "error" : {"code": 101, "message": ' + $metadata->getMessage() + '}}');
|
||||
|
|
|
@ -52,7 +52,9 @@ $g_metadata_xml_to_db_mapping = array(
|
|||
"dc:contributor" => "contributor",
|
||||
"dc:language" => "language");
|
||||
|
||||
/**
|
||||
class Metadata {
|
||||
|
||||
/**
|
||||
* Track numbers in metadata tags can come in many formats:
|
||||
* "1 of 20", "1/20", "20/1". This function parses the track
|
||||
* number and gets the real number so that we can sort by it
|
||||
|
@ -61,8 +63,8 @@ $g_metadata_xml_to_db_mapping = array(
|
|||
* @param string $p_trackNumber
|
||||
* @return int
|
||||
*/
|
||||
function camp_parse_track_number($p_trackNumber)
|
||||
{
|
||||
public static function ParseTrackNumber($p_trackNumber)
|
||||
{
|
||||
$num = trim($p_trackNumber);
|
||||
if (!is_numeric($num)) {
|
||||
$matches = preg_match("/\s*([0-9]+)([^0-9]*)([0-9]*)\s*/", $num, $results);
|
||||
|
@ -80,12 +82,11 @@ function camp_parse_track_number($p_trackNumber)
|
|||
$trackNum = $num;
|
||||
}
|
||||
return $trackNum;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Add data to the global array $mdata, also sets global variables
|
||||
* $titleHaveSet and $titleKey.
|
||||
/**
|
||||
* Add data to the array $p_mdata.
|
||||
*
|
||||
* Converts the given string ($val) into UTF-8.
|
||||
*
|
||||
|
@ -98,8 +99,8 @@ function camp_parse_track_number($p_trackNumber)
|
|||
* @param string $p_inputEncoding
|
||||
* Encoding type of the input value.
|
||||
*/
|
||||
function camp_add_metadata(&$p_mdata, $p_key, $p_val, $p_inputEncoding='iso-8859-1')
|
||||
{
|
||||
public static function AddToArray(&$p_mdata, $p_key, $p_val, $p_inputEncoding='iso-8859-1')
|
||||
{
|
||||
if (!is_null($p_val)) {
|
||||
$data = $p_val;
|
||||
$outputEncoding = 'UTF-8';
|
||||
|
@ -115,10 +116,10 @@ function camp_add_metadata(&$p_mdata, $p_key, $p_val, $p_inputEncoding='iso-8859
|
|||
}
|
||||
$p_mdata[$p_key] = trim($data);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
/**
|
||||
* Return an array with the given audio file's ID3 tags. The keys in the
|
||||
* array can be:
|
||||
* <pre>
|
||||
|
@ -143,8 +144,8 @@ function camp_add_metadata(&$p_mdata, $p_key, $p_val, $p_inputEncoding='iso-8859
|
|||
* to the return array.
|
||||
* @return array|PEAR_Error
|
||||
*/
|
||||
function camp_get_audio_metadata($p_filename, $p_testonly = false)
|
||||
{
|
||||
public static function LoadFromFile($p_filename, $p_testonly = false)
|
||||
{
|
||||
$getID3 = new getID3();
|
||||
$infoFromFile = $getID3->analyze($p_filename);
|
||||
if (PEAR::isError($infoFromFile)) {
|
||||
|
@ -289,9 +290,9 @@ function camp_get_audio_metadata($p_filename, $p_testonly = false)
|
|||
|
||||
// Special case handling for track number
|
||||
if ($key == "ls:track_num") {
|
||||
$data = camp_parse_track_number($data);
|
||||
$data = Metadata::ParseTrackNumber($data);
|
||||
}
|
||||
camp_add_metadata($mdata, $key, $data, $enc);
|
||||
Metadata::AddToArray($mdata, $key, $data, $enc);
|
||||
if ($key == $titleKey) {
|
||||
$titleHaveSet = TRUE;
|
||||
}
|
||||
|
@ -304,9 +305,10 @@ function camp_get_audio_metadata($p_filename, $p_testonly = false)
|
|||
}
|
||||
|
||||
if (!$titleHaveSet || trim($mdata[$titleKey]) == '') {
|
||||
camp_add_metadata($mdata, $titleKey, basename($p_filename));
|
||||
Metadata::AddToArray($mdata, $titleKey, basename($p_filename));
|
||||
}
|
||||
return $mdata;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
@ -316,7 +318,7 @@ function camp_get_audio_metadata($p_filename, $p_testonly = false)
|
|||
* Airtime file storage support class.<br>
|
||||
* Represents one virtual file in storage. Virtual file has up to two parts:
|
||||
* <ul>
|
||||
* <li>metadata in database - represented by MetaData class</li>
|
||||
* <li>metadata in database </li>
|
||||
* <li>binary media data in real file</li>
|
||||
* </ul>
|
||||
*
|
||||
|
@ -607,7 +609,7 @@ class StoredFile {
|
|||
if (isset($p_values["metadata"])) {
|
||||
$metadata = $p_values['metadata'];
|
||||
} else {
|
||||
$metadata = camp_get_audio_metadata($p_values["filepath"]);
|
||||
$metadata = Metadata::LoadFromFile($p_values["filepath"]);
|
||||
}
|
||||
|
||||
$storedFile->name = isset($p_values['filename']) ? $p_values['filename'] : $p_values["filepath"];
|
||||
|
@ -906,24 +908,6 @@ class StoredFile {
|
|||
}
|
||||
|
||||
|
||||
/**
|
||||
* Analyze file with getid3 module.<br>
|
||||
* Obtain some metadata stored in media file.<br>
|
||||
* This method should be used for prefilling metadata input form.
|
||||
*
|
||||
* @return array
|
||||
* hierarchical hasharray with information about media file
|
||||
*/
|
||||
public function analyzeFile()
|
||||
{
|
||||
if (!$this->exists) {
|
||||
return FALSE;
|
||||
}
|
||||
$ia = camp_get_audio_metadata($this->filepath);
|
||||
return $ia;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Create instance of StoredFile object and make copy of existing file
|
||||
*
|
||||
|
@ -1511,7 +1495,7 @@ class StoredFile {
|
|||
*/
|
||||
public function getMime()
|
||||
{
|
||||
$a = $this->analyzeFile();
|
||||
$a = Metadata::LoadFromFile($this->filepath);
|
||||
if (PEAR::isError($a)) {
|
||||
return $a;
|
||||
}
|
||||
|
|
|
@ -20,7 +20,7 @@ class StoredFileTest extends PHPUnit_TestCase {
|
|||
|
||||
function testGetAudioMetadata() {
|
||||
$filePath = dirname(__FILE__)."/ex1.mp3";
|
||||
$metadata = camp_get_audio_metadata($filePath);
|
||||
$metadata = Metadata::LoadFromFile($filePath);
|
||||
if (PEAR::isError($metadata)) {
|
||||
$this->fail($metadata->getMessage());
|
||||
return;
|
||||
|
|
Loading…
Reference in New Issue