From e98eda144af30711b0b40f74b59ae73fd4c6050a Mon Sep 17 00:00:00 2001 From: Rudi Grinberg Date: Wed, 8 Aug 2012 15:55:58 -0400 Subject: [PATCH] cc-4105: removed naive replaygain again. added micro optimization to Insert into cc_files --- .../application/controllers/ApiController.php | 6 ++--- airtime_mvc/application/models/StoredFile.php | 27 +++++++++---------- .../media-monitor2/media/monitor/metadata.py | 3 --- 3 files changed, 15 insertions(+), 21 deletions(-) diff --git a/airtime_mvc/application/controllers/ApiController.php b/airtime_mvc/application/controllers/ApiController.php index 5ccbfba4a..1684e9b1d 100644 --- a/airtime_mvc/application/controllers/ApiController.php +++ b/airtime_mvc/application/controllers/ApiController.php @@ -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; diff --git a/airtime_mvc/application/models/StoredFile.php b/airtime_mvc/application/models/StoredFile.php index 5e44fbb6f..144cfef73 100644 --- a/airtime_mvc/application/models/StoredFile.php +++ b/airtime_mvc/application/models/StoredFile.php @@ -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; } /** diff --git a/python_apps/media-monitor2/media/monitor/metadata.py b/python_apps/media-monitor2/media/monitor/metadata.py index a1d01712a..9433443d4 100644 --- a/python_apps/media-monitor2/media/monitor/metadata.py +++ b/python_apps/media-monitor2/media/monitor/metadata.py @@ -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 )