removed wrong comments
This commit is contained in:
commit
3e24b71436
49 changed files with 2098 additions and 1978 deletions
|
@ -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%%'
|
||||
|
|
|
@ -381,7 +381,9 @@ class AirTimeApiClient():
|
|||
self.logger.debug("Warning: Sending a request element without a 'mode'")
|
||||
self.logger.debug("Here is the the request: '%s'" % str(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))
|
||||
|
||||
data = urllib.urlencode(md_list)
|
||||
req = urllib2.Request(url, data)
|
||||
response = self.get_response_from_server(req)
|
||||
|
@ -621,15 +623,35 @@ 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)
|
||||
|
||||
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:
|
||||
file_path = None
|
||||
response = None
|
||||
logger.error('Exception: %s', e)
|
||||
logger.error("traceback: %s", traceback.format_exc())
|
||||
|
||||
return file_path
|
||||
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:
|
||||
self.logger.error("Exception: %s", e)
|
||||
raise
|
||||
|
|
|
@ -10,5 +10,6 @@ class Loggable(object):
|
|||
# TODO : replace this boilerplate with LazyProperty
|
||||
@LazyProperty
|
||||
def logger(self):
|
||||
# TODO : Clean this up
|
||||
if not hasattr(self,"_logger"): self._logger = logging.getLogger('mediamonitor2')
|
||||
return self._logger
|
||||
|
|
0
python_apps/media-monitor2/media/update/__init__.py
Normal file
0
python_apps/media-monitor2/media/update/__init__.py
Normal file
|
@ -6,16 +6,16 @@ import logging
|
|||
import json
|
||||
|
||||
from api_clients import api_client
|
||||
import replaygain
|
||||
from media.update import replaygain
|
||||
|
||||
|
||||
class ReplayGainUpdater(Thread):
|
||||
"""
|
||||
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
|
||||
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
|
||||
value calculated. This class will iterate over the list calculate the values, update the server and
|
||||
repeat the process until 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
|
||||
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.
|
||||
"""
|
||||
|
@ -27,42 +27,32 @@ class ReplayGainUpdater(Thread):
|
|||
|
||||
def main(self):
|
||||
|
||||
#TODO
|
||||
#TODO make sure object has 'dirs' attr
|
||||
directories = self.api_client.list_all_watched_dirs()['dirs']
|
||||
|
||||
for dir_id, dir_path in directories.iteritems():
|
||||
try:
|
||||
processed_data = []
|
||||
|
||||
#keep getting 100 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.
|
||||
#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 'finished' to True.
|
||||
finished = False
|
||||
|
||||
while not finished:
|
||||
# return a list of pairs where the first value is the file's database row id
|
||||
# and the second value is the filepath
|
||||
file_path = self.api_client.get_files_without_replay_gain_value(dir_id)
|
||||
print "temp file saved to %s" % file_path
|
||||
files = self.api_client.get_files_without_replay_gain_value(dir_id)
|
||||
|
||||
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:
|
||||
for line in f:
|
||||
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)))
|
||||
self.api_client.update_replay_gain_values(processed_data)
|
||||
finished = (len(files) == 0)
|
||||
|
||||
if num_lines == 0:
|
||||
finished = True
|
||||
|
||||
os.remove(file_path)
|
||||
|
||||
#send data here
|
||||
pass
|
||||
except Exception, e:
|
||||
print e
|
||||
|
||||
self.logger.error(e)
|
||||
self.logger.debug(traceback.format_exc())
|
||||
def run(self):
|
||||
try: self.main()
|
||||
except Exception, e:
|
||||
|
@ -72,7 +62,7 @@ class ReplayGainUpdater(Thread):
|
|||
if __name__ == "__main__":
|
||||
try:
|
||||
rgu = ReplayGainUpdater(logging)
|
||||
print rgu.main()
|
||||
rgu.main()
|
||||
except Exception, e:
|
||||
print e
|
||||
print traceback.format_exc()
|
Loading…
Add table
Add a link
Reference in a new issue