CC-430: Audio normalization (Replaygain Support)
make code simpler (don't download database to file)
This commit is contained in:
parent
0e98bc75c8
commit
b4f1cc13c0
|
@ -954,7 +954,6 @@ class ApiController extends Zend_Controller_Action
|
||||||
$dir_id = $this->_getParam('dir_id');
|
$dir_id = $this->_getParam('dir_id');
|
||||||
|
|
||||||
//connect to db and get get sql
|
//connect to db and get get sql
|
||||||
$this->view->rows = Application_Model_StoredFile::listAllFiles2($dir_id, 0);
|
$this->view->rows = Application_Model_StoredFile::listAllFiles2($dir_id, 100);
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -975,13 +975,11 @@ Logging::log("getting media! - 2");
|
||||||
." FROM CC_FILES"
|
." FROM CC_FILES"
|
||||||
." WHERE directory = $dir_id"
|
." WHERE directory = $dir_id"
|
||||||
." AND file_exists = 'TRUE'";
|
." AND file_exists = 'TRUE'";
|
||||||
|
|
||||||
if (!is_null($limit) && is_int($limit)) {
|
if (!is_null($limit) && is_int($limit)) {
|
||||||
$sql .= " LIMIT $limit";
|
$sql .= " LIMIT $limit";
|
||||||
}
|
}
|
||||||
|
|
||||||
$rows = $con->query($sql, PDO::FETCH_ASSOC);
|
$rows = $con->query($sql, PDO::FETCH_ASSOC)->fetchAll();
|
||||||
|
|
||||||
return $rows;
|
return $rows;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,8 +1,3 @@
|
||||||
<?php
|
<?php
|
||||||
|
|
||||||
//disable buffering so that data is sent as we retrieve it from the database
|
echo json_encode($this->rows);
|
||||||
while (@ob_end_flush());
|
|
||||||
|
|
||||||
foreach($this->rows as $row) {
|
|
||||||
echo json_encode($row)."\n";
|
|
||||||
}
|
|
||||||
|
|
|
@ -113,5 +113,5 @@ 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_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%%'
|
||||||
|
|
||||||
|
|
|
@ -381,7 +381,11 @@ class AirTimeApiClient():
|
||||||
self.logger.debug("Warning: Sending a request element without a 'mode'")
|
self.logger.debug("Warning: Sending a request element without a 'mode'")
|
||||||
self.logger.debug("Here is the the request: '%s'" % str(action) )
|
self.logger.debug("Here is the the request: '%s'" % str(action) )
|
||||||
else: valid_actions.append(action)
|
else: valid_actions.append(action)
|
||||||
md_list = { i : json.dumps(convert_dict_value_to_utf8(md)) for i,md in enumerate(valid_actions) }
|
|
||||||
|
md_list = dict((i, json.dumps(convert_dict_value_to_utf8(md))) for i,md in enumerate(valid_actions))
|
||||||
|
#Doesn't work in Python 2.6
|
||||||
|
#md_list = {i : json.dumps(convert_dict_value_to_utf8(md)) for i,md in enumerate(valid_actions) }
|
||||||
|
|
||||||
data = urllib.urlencode(md_list)
|
data = urllib.urlencode(md_list)
|
||||||
req = urllib2.Request(url, data)
|
req = urllib2.Request(url, data)
|
||||||
response = self.get_response_from_server(req)
|
response = self.get_response_from_server(req)
|
||||||
|
@ -625,12 +629,15 @@ class AirTimeApiClient():
|
||||||
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("%%api_key%%", self.config["api_key"])
|
||||||
url = url.replace("%%dir_id%%", dir_id)
|
url = url.replace("%%dir_id%%", dir_id)
|
||||||
|
response = self.get_response_from_server(url)
|
||||||
|
|
||||||
file_path = self.get_response_into_file(url)
|
logger.info("update file system mount: %s", response)
|
||||||
|
response = json.loads(response)
|
||||||
|
#file_path = self.get_response_into_file(url)
|
||||||
except Exception, e:
|
except Exception, e:
|
||||||
file_path = None
|
response = None
|
||||||
logger.error('Exception: %s', e)
|
logger.error('Exception: %s', e)
|
||||||
logger.error("traceback: %s", traceback.format_exc())
|
logger.error("traceback: %s", traceback.format_exc())
|
||||||
|
|
||||||
return file_path
|
return response
|
||||||
|
|
||||||
|
|
|
@ -12,10 +12,10 @@ import replaygain
|
||||||
class ReplayGainUpdater(Thread):
|
class ReplayGainUpdater(Thread):
|
||||||
"""
|
"""
|
||||||
The purpose of the class is to query the server for a list of files which do not have a ReplayGain
|
The purpose of the class is to query the server for a list of files which do not have a ReplayGain
|
||||||
value calculated. This class will iterate over the list calculate the values, update the server and
|
value calculated. This class will iterate over the list calculate the values, update the server and
|
||||||
repeat the process until the the server reports there are no files left.
|
repeat the process until the the server reports there are no files left.
|
||||||
|
|
||||||
This class will see heavy activity right after a 2.1->2.2 upgrade since 2.2 introduces ReplayGain
|
This class will see heavy activity right after a 2.1->2.2 upgrade since 2.2 introduces ReplayGain
|
||||||
normalization. A fresh install of Airtime 2.2 will see this class not used at all since a file
|
normalization. A fresh install of Airtime 2.2 will see this class not used at all since a file
|
||||||
imported in 2.2 will automatically have its ReplayGain value calculated.
|
imported in 2.2 will automatically have its ReplayGain value calculated.
|
||||||
"""
|
"""
|
||||||
|
@ -27,42 +27,35 @@ class ReplayGainUpdater(Thread):
|
||||||
|
|
||||||
def main(self):
|
def main(self):
|
||||||
|
|
||||||
#TODO
|
#TODO make sure object has 'dirs' attr
|
||||||
directories = self.api_client.list_all_watched_dirs()['dirs']
|
directories = self.api_client.list_all_watched_dirs()['dirs']
|
||||||
|
|
||||||
for dir_id, dir_path in directories.iteritems():
|
for dir_id, dir_path in directories.iteritems():
|
||||||
try:
|
try:
|
||||||
processed_data = []
|
processed_data = []
|
||||||
|
|
||||||
#keep getting 100 rows at a time for current music_dir (stor or watched folder).
|
#keep getting few rows at a time for current music_dir (stor or watched folder).
|
||||||
#When we get a response with 0 rows, then we will set response to True.
|
#When we get a response with 0 rows, then we will set 'finished' to True.
|
||||||
finished = False
|
finished = False
|
||||||
|
|
||||||
while not finished:
|
while not finished:
|
||||||
# return a list of pairs where the first value is the file's database row id
|
# return a list of pairs where the first value is the file's database row id
|
||||||
# and the second value is the filepath
|
# and the second value is the filepath
|
||||||
file_path = self.api_client.get_files_without_replay_gain_value(dir_id)
|
files = self.api_client.get_files_without_replay_gain_value(dir_id)
|
||||||
print "temp file saved to %s" % file_path
|
self.logger.debug(files)
|
||||||
|
|
||||||
num_lines = 0
|
for f in files:
|
||||||
|
full_path = os.path.join(dir_path, f['fp'])
|
||||||
|
processed_data.append((f['id'], replaygain.calculate_replay_gain(full_path)))
|
||||||
|
|
||||||
with open(file_path) as f:
|
#finished = (len(files) == 0)
|
||||||
for line in f:
|
finished = True
|
||||||
num_lines += 1
|
|
||||||
data = json.loads(line.strip())
|
|
||||||
track_path = os.path.join(dir_path, data['fp'])
|
|
||||||
processed_data.append((data['id'], replaygain.calculate_replay_gain(track_path)))
|
|
||||||
|
|
||||||
if num_lines == 0:
|
|
||||||
finished = True
|
|
||||||
|
|
||||||
os.remove(file_path)
|
|
||||||
|
|
||||||
#send data here
|
#send data here
|
||||||
pass
|
print processed_data
|
||||||
except Exception, e:
|
except Exception, e:
|
||||||
print e
|
print e
|
||||||
|
print traceback.format_exc()
|
||||||
def run(self):
|
def run(self):
|
||||||
try: self.main()
|
try: self.main()
|
||||||
except Exception, e:
|
except Exception, e:
|
||||||
|
|
Loading…
Reference in New Issue