CC-430: Audio normalization (Replaygain Support)

-values are now written through to database
This commit is contained in:
Martin Konecny 2012-07-15 20:57:40 -04:00
parent b4f1cc13c0
commit 632f039977
6 changed files with 43 additions and 6 deletions

View File

@ -956,4 +956,22 @@ class ApiController extends Zend_Controller_Action
//connect to db and get get sql
$this->view->rows = Application_Model_StoredFile::listAllFiles2($dir_id, 100);
}
public function updateReplayGainValueAction()
{
$this->checkAuth();
// disable layout
$this->view->layout()->disableLayout();
$request = $this->getRequest();
$data = json_decode($request->getParam('data'));
foreach ($data as $pair) {
list($id, $gain) = $pair;
$file = Application_Model_StoredFile::Recall($p_id = $id)->getPropelOrm();
Logging::log("Setting $gain for file id $id");
$file->setDbReplayGain($gain);
}
}
}

View File

@ -96,9 +96,6 @@ update_item_url = 'notify-schedule-group-play/api_key/%%api_key%%/schedule_id/%%
# Update whether an audio clip is currently playing.
update_start_playing_url = 'notify-media-item-start-play/api_key/%%api_key%%/media_id/%%media_id%%/schedule_id/%%schedule_id%%'
# ???
generate_range_url = 'generate_range_dp.php'
# URL to tell Airtime we want to get stream setting
get_stream_setting = 'get-stream-setting/format/json/api_key/%%api_key%%/'
@ -113,5 +110,6 @@ update_source_status = 'update-source-status/format/json/api_key/%%api_key%%/sou
get_bootstrap_info = 'get-bootstrap-info/format/json/api_key/%%api_key%%'
get-files-without-replay-gain = 'get-files-without-replay-gain/api_key/%%api_key%%/dir_id/%%dir_id%%'
get_files_without_replay_gain = 'get-files-without-replay-gain/api_key/%%api_key%%/dir_id/%%dir_id%%'
update_replay_gain_value = 'update-replay-gain-value/api_key/%%api_key%%'

View File

@ -626,7 +626,7 @@ class AirTimeApiClient():
logger = self.logger
try:
url = "http://%(base_url)s:%(base_port)s/%(api_base)s/%(get-files-without-replay-gain)s/" % (self.config)
url = "http://%(base_url)s:%(base_port)s/%(api_base)s/%(get_files_without_replay_gain)s/" % (self.config)
url = url.replace("%%api_key%%", self.config["api_key"])
url = url.replace("%%dir_id%%", dir_id)
response = self.get_response_from_server(url)
@ -641,3 +641,20 @@ class AirTimeApiClient():
return response
def update_replay_gain_values(self, pairs):
"""
'pairs' is a list of pairs in (x, y), where x is the file's database row id
and y is the file's replay_gain value in dB
"""
#http://localhost/api/update-replay-gain-value/
try:
url = "http://%(base_url)s:%(base_port)s/%(api_base)s/%(update_replay_gain_value)s/" % (self.config)
url = url.replace("%%api_key%%", self.config["api_key"])
data = urllib.urlencode({'data': json.dumps(pairs)})
request = urllib2.Request(url, data)
self.get_response_from_server(request)
except Exception, e:
response = None

View File

@ -5,8 +5,11 @@ import os
import logging
import json
import sys
sys.path.append('/home/martin/workspace/airtime/python_apps/media-monitor2/')
from api_clients import api_client
import replaygain
from media.update import replaygain
class ReplayGainUpdater(Thread):
@ -52,6 +55,7 @@ class ReplayGainUpdater(Thread):
finished = True
#send data here
self.api_client.update_replay_gain_values(processed_data)
print processed_data
except Exception, e:
print e