cc-4105: removed naive replaygain again. added micro optimization to Insert into cc_files

This commit is contained in:
Rudi Grinberg 2012-08-08 15:55:58 -04:00
parent 91145a3f16
commit e98eda144a
3 changed files with 15 additions and 21 deletions

View File

@ -456,8 +456,8 @@ class ApiController extends Zend_Controller_Action
$this->view->watched_dirs = $watchedDirsPath;
}
public function dispatchMetadataAction($md, $mode, $dry_run=false)
{
public function dispatchMetadata($md, $mode, $dry_run=false)
{
// Replace this compound result in a hash with proper error handling later on
$return_hash = array();
if ( $dry_run ) { // for debugging we return garbage not to screw around with the db
@ -587,7 +587,7 @@ class ApiController extends Zend_Controller_Action
// Removing 'mode' key from $info_json might not be necessary...
$mode = $info_json['mode'];
unset( $info_json['mode'] );
$response = $this->dispatchMetadataAction($info_json, $mode, $dry_run=$dry);
$response = $this->dispatchMetadata($info_json, $mode, $dry_run=$dry);
// We tack on the 'key' back to every request in case the would like to associate
// his requests with particular responses
$response['key'] = $k;

View File

@ -451,8 +451,13 @@ class Application_Model_StoredFile
return $baseUrl."/api/get-media/file/".$this->getId().".".$this->getFileExtension();
}
public static function Insert($md=null)
public static function Insert($md)
{
// save some work by checking if filepath is given right away
if( !isset($md['MDATA_KEY_FILEPATH']) ) {
return null;
}
$file = new CcFiles();
$file->setDbUtime(new DateTime("now", new DateTimeZone("UTC")));
$file->setDbMtime(new DateTime("now", new DateTimeZone("UTC")));
@ -460,22 +465,14 @@ class Application_Model_StoredFile
$storedFile = new Application_Model_StoredFile();
$storedFile->_file = $file;
if (isset($md['MDATA_KEY_FILEPATH'])) {
// removed "//" in the path. Always use '/' for path separator
$filepath = str_replace("//", "/", $md['MDATA_KEY_FILEPATH']);
$res = $storedFile->setFilePath($filepath);
if ($res === -1) {
return null;
}
} else {
// removed "//" in the path. Always use '/' for path separator
$filepath = str_replace("//", "/", $md['MDATA_KEY_FILEPATH']);
$res = $storedFile->setFilePath($filepath);
if ($res === -1) {
return null;
}
if (isset($md)) {
$storedFile->setMetadata($md);
}
return $storedFile;
$storedFile->setMetadata($md);
return $storedFile;
}
/**

View File

@ -4,7 +4,6 @@ import math
import os
import copy
import media.update.replaygain as gain
from media.monitor.exceptions import BadSongFile
from media.monitor.log import Loggable
import media.monitor.pure as mmp
@ -161,8 +160,6 @@ class Metadata(Loggable):
self.__metadata = mmp.normalized_metadata(self.__metadata, fpath)
# Now we must load the md5:
self.__metadata['MDATA_KEY_MD5'] = mmp.file_md5(fpath,max_length=100)
self.__metadata['MDATA_KEY_REPLAYGAIN'] = \
gain.calculate_replay_gain(fpath)
def is_recorded(self):
return mmp.is_airtime_recorded( self.__metadata )