From 1158fc2c9e5046d657f22cd8e6681fc5d92fc506 Mon Sep 17 00:00:00 2001 From: Martin Konecny Date: Thu, 25 Apr 2013 22:38:06 -0400 Subject: [PATCH 1/6] more legible comment --- python_apps/pypo/media/update/replaygainupdater.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/python_apps/pypo/media/update/replaygainupdater.py b/python_apps/pypo/media/update/replaygainupdater.py index daf63d54d..c1123f4a8 100644 --- a/python_apps/pypo/media/update/replaygainupdater.py +++ b/python_apps/pypo/media/update/replaygainupdater.py @@ -11,7 +11,7 @@ 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 + 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 From f2564cf732538afe83e68911486ac67891803296 Mon Sep 17 00:00:00 2001 From: Martin Konecny Date: Thu, 2 May 2013 16:09:04 -0400 Subject: [PATCH 2/6] temporarily disable opus + aac until liquidsoap binaries are ready --- .../pypo/liquidsoap_scripts/ls_lib.liq | 20 +++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/python_apps/pypo/liquidsoap_scripts/ls_lib.liq b/python_apps/pypo/liquidsoap_scripts/ls_lib.liq index 9afa28db9..4c078914c 100644 --- a/python_apps/pypo/liquidsoap_scripts/ls_lib.liq +++ b/python_apps/pypo/liquidsoap_scripts/ls_lib.liq @@ -126,12 +126,12 @@ def output_to(output_type, type, bitrate, host, port, pass, mount_point, url, de %include "mp3.liq" elsif type == "ogg" then %include "ogg.liq" - elsif type == "opus" then - %include "opus.liq" - elsif type == "aac" then - %include "aac.liq" - else - %include "aacplus.liq" + #elsif type == "opus" then + # %include "opus.liq" + #elsif type == "aac" then + # %include "aac.liq" + #else + # %include "aacplus.liq" end else user_ref = ref user @@ -165,10 +165,10 @@ def output_to(output_type, type, bitrate, host, port, pass, mount_point, url, de if type == "mp3" then %include "mp3.liq" - elsif type == "aac" then - %include "aac.liq" - else - %include "aacplus.liq" + #elsif type == "aac" then + # %include "aac.liq" + #else + # %include "aacplus.liq" end end end From ca22a2582724633e579298e4477ed481d80a6b60 Mon Sep 17 00:00:00 2001 From: Martin Konecny Date: Thu, 2 May 2013 16:57:07 -0400 Subject: [PATCH 3/6] fix silly mistake with echoing json twice --- airtime_mvc/application/controllers/ApiController.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/airtime_mvc/application/controllers/ApiController.php b/airtime_mvc/application/controllers/ApiController.php index 1e4789747..1a810ebc5 100644 --- a/airtime_mvc/application/controllers/ApiController.php +++ b/airtime_mvc/application/controllers/ApiController.php @@ -351,7 +351,7 @@ class ApiController extends Zend_Controller_Action $data = Application_Model_Schedule::getSchedule(); header("Content-Type: application/json"); - echo json_encode($data, JSON_FORCE_OBJECT); + $data = json_encode($data, JSON_FORCE_OBJECT); $this->_helper->json->sendJson($data, false, true); } From d902d38429f8c6cd2a26d9073b0504c8d7b8a967 Mon Sep 17 00:00:00 2001 From: Martin Konecny Date: Thu, 2 May 2013 17:50:36 -0400 Subject: [PATCH 4/6] revert jsonEncode change not supported by older zend versions --- airtime_mvc/application/controllers/ApiController.php | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/airtime_mvc/application/controllers/ApiController.php b/airtime_mvc/application/controllers/ApiController.php index 1a810ebc5..8c767c0e0 100644 --- a/airtime_mvc/application/controllers/ApiController.php +++ b/airtime_mvc/application/controllers/ApiController.php @@ -288,7 +288,7 @@ class ApiController extends Zend_Controller_Action //used by caller to determine if the airtime they are running or widgets in use is out of date. $result['AIRTIME_API_VERSION'] = AIRTIME_API_VERSION; - header("Content-type: text/javascript"); + header("Content-Type: application/json"); // If a callback is not given, then just provide the raw JSON. echo isset($_GET['callback']) ? $_GET['callback'].'('.json_encode($result).')' : json_encode($result); @@ -348,11 +348,14 @@ class ApiController extends Zend_Controller_Action public function scheduleAction() { - $data = Application_Model_Schedule::getSchedule(); + $this->view->layout()->disableLayout(); + $this->_helper->viewRenderer->setNoRender(true); + header("Content-Type: application/json"); - $data = json_encode($data, JSON_FORCE_OBJECT); - $this->_helper->json->sendJson($data, false, true); + $data = Application_Model_Schedule::getSchedule(); + + echo json_encode($data, JSON_FORCE_OBJECT); } public function notifyMediaItemStartPlayAction() From 84efb4a9b7a1b5e48565499679c9b3e3823bbd3b Mon Sep 17 00:00:00 2001 From: Martin Konecny Date: Thu, 2 May 2013 17:59:03 -0400 Subject: [PATCH 5/6] work around to work with annoying static methods - should remove these later.. --- python_apps/pypo/pypofetch.py | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/python_apps/pypo/pypofetch.py b/python_apps/pypo/pypofetch.py index edb6f7d37..e0abeb317 100644 --- a/python_apps/pypo/pypofetch.py +++ b/python_apps/pypo/pypofetch.py @@ -36,15 +36,20 @@ signal.signal(signal.SIGINT, keyboardInterruptHandler) POLL_INTERVAL = 1800 +config_static = None + class PypoFetch(Thread): def __init__(self, pypoFetch_q, pypoPush_q, media_q, telnet_lock, pypo_liquidsoap, config): Thread.__init__(self) + global config_static + self.api_client = api_client.AirtimeApiClient() self.fetch_queue = pypoFetch_q self.push_queue = pypoPush_q self.media_prepare_queue = media_q self.last_update_schedule_timestamp = time.time() self.config = config + config_static = config self.listener_timeout = POLL_INTERVAL self.telnet_lock = telnet_lock @@ -134,7 +139,7 @@ class PypoFetch(Thread): try: lock.acquire() - tn = telnetlib.Telnet(self.config['ls_host'], self.config['ls_port']) + tn = telnetlib.Telnet(config_static['ls_host'], config_static['ls_port']) logger.info(command) tn.write(command) tn.write('exit\n') @@ -149,7 +154,7 @@ class PypoFetch(Thread): try: lock.acquire() - tn = telnetlib.Telnet(self.config['ls_host'], self.config['ls_port']) + tn = telnetlib.Telnet(config_static['ls_host'], config_static['ls_port']) for i in commands: logger.info(i) tn.write(i) From 6c42064c14a69129c9b916828c7d660629e13a32 Mon Sep 17 00:00:00 2001 From: Martin Konecny Date: Thu, 2 May 2013 18:46:16 -0400 Subject: [PATCH 6/6] refactor methods into appropriate locations --- python_apps/pypo/pypofetch.py | 67 +++------------------------- python_apps/pypo/pypoliquidsoap.py | 7 ++- python_apps/pypo/telnetliquidsoap.py | 54 ++++++++++++++++++++++ 3 files changed, 65 insertions(+), 63 deletions(-) diff --git a/python_apps/pypo/pypofetch.py b/python_apps/pypo/pypofetch.py index e0abeb317..90d4ee0f7 100644 --- a/python_apps/pypo/pypofetch.py +++ b/python_apps/pypo/pypofetch.py @@ -107,10 +107,13 @@ class PypoFetch(Thread): self.update_liquidsoap_transition_fade(m['transition_fade']) elif command == 'switch_source': self.logger.info("switch_on_source show command received...") - self.switch_source(self.logger, self.telnet_lock, m['sourcename'], m['status']) + self.pypo_liquidsoap.\ + get_telnet_dispatcher().\ + switch_source(m['sourcename'], m['status']) elif command == 'disconnect_source': self.logger.info("disconnect_on_source show command received...") - self.disconnect_source(self.logger, self.telnet_lock, m['sourcename']) + self.pypo_liquidsoap.get_telnet_dispatcher().\ + disconnect_source(m['sourcename']) else: self.logger.info("Unknown command: %s" % command) @@ -128,65 +131,7 @@ class PypoFetch(Thread): self.logger.error("traceback: %s", top) self.logger.error("Exception in handling Message Handler message: %s", e) - @staticmethod - def disconnect_source(logger, lock, sourcename): - logger.debug('Disconnecting source: %s', sourcename) - command = "" - if(sourcename == "master_dj"): - command += "master_harbor.kick\n" - elif(sourcename == "live_dj"): - command += "live_dj_harbor.kick\n" - try: - lock.acquire() - tn = telnetlib.Telnet(config_static['ls_host'], config_static['ls_port']) - logger.info(command) - tn.write(command) - tn.write('exit\n') - tn.read_all() - except Exception, e: - logger.error(traceback.format_exc()) - finally: - lock.release() - - @staticmethod - def telnet_send(logger, lock, commands): - try: - lock.acquire() - - tn = telnetlib.Telnet(config_static['ls_host'], config_static['ls_port']) - for i in commands: - logger.info(i) - tn.write(i) - - tn.write('exit\n') - tn.read_all() - except Exception, e: - logger.error(str(e)) - finally: - lock.release() - - - @staticmethod - def switch_source(logger, lock, sourcename, status): - logger.debug('Switching source: %s to "%s" status', sourcename, status) - command = "streams." - if sourcename == "master_dj": - command += "master_dj_" - elif sourcename == "live_dj": - command += "live_dj_" - elif sourcename == "scheduled_play": - command += "scheduled_play_" - - if status == "on": - command += "start\n" - else: - command += "stop\n" - - PypoFetch.telnet_send(logger, lock, [command]) - - - #TODO: Merge this with switch_source def switch_source_temp(self, sourcename, status): self.logger.debug('Switching source: %s to "%s" status', sourcename, status) command = "streams." @@ -227,7 +172,7 @@ class PypoFetch(Thread): commands.append(('vars.stream_metadata_type %s\n' % stream_format).encode('utf-8')) commands.append(('vars.station_name %s\n' % station_name).encode('utf-8')) commands.append(('vars.default_dj_fade %s\n' % fade).encode('utf-8')) - PypoFetch.telnet_send(self.logger, self.telnet_lock, commands) + self.pypo_liquidsoap.get_telnet_dispatcher().telnet_send(commands) def restart_liquidsoap(self): try: diff --git a/python_apps/pypo/pypoliquidsoap.py b/python_apps/pypo/pypoliquidsoap.py index 2b867a49b..7e685adae 100644 --- a/python_apps/pypo/pypoliquidsoap.py +++ b/python_apps/pypo/pypoliquidsoap.py @@ -23,6 +23,9 @@ class PypoLiquidsoap(): port,\ self.liq_queue_tracker.keys()) + def get_telnet_dispatcher(self): + return self.telnet_liquidsoap + def play(self, media_item): if media_item["type"] == eventtypes.FILE: @@ -67,9 +70,9 @@ class PypoLiquidsoap(): def handle_event_type(self, media_item): if media_item['event_type'] == "kick_out": - PypoFetch.disconnect_source(self.logger, self.telnet_lock, "live_dj") + self.telnet_liquidsoap.disconnect_source("live_dj") elif media_item['event_type'] == "switch_off": - PypoFetch.switch_source(self.logger, self.telnet_lock, "live_dj", "off") + self.telnet_liquidsoap.switch_source("live_dj", "off") def is_media_item_finished(self, media_item): diff --git a/python_apps/pypo/telnetliquidsoap.py b/python_apps/pypo/telnetliquidsoap.py index 7ce2fceb3..0cfb8709c 100644 --- a/python_apps/pypo/telnetliquidsoap.py +++ b/python_apps/pypo/telnetliquidsoap.py @@ -193,6 +193,60 @@ class TelnetLiquidsoap: finally: self.telnet_lock.release() + def disconnect_source(self, sourcename): + self.logger.debug('Disconnecting source: %s', sourcename) + command = "" + if(sourcename == "master_dj"): + command += "master_harbor.kick\n" + elif(sourcename == "live_dj"): + command += "live_dj_harbor.kick\n" + + try: + self.telnet_lock.acquire() + tn = telnetlib.Telnet(self.ls_host, self.ls_port) + self.logger.info(command) + tn.write(command) + tn.write('exit\n') + tn.read_all() + except Exception, e: + self.logger.error(traceback.format_exc()) + finally: + self.telnet_lock.release() + + def telnet_send(self, commands): + try: + self.telnet_lock.acquire() + + tn = telnetlib.Telnet(self.ls_host, self.ls_port) + for i in commands: + self.logger.info(i) + tn.write(i) + + tn.write('exit\n') + tn.read_all() + except Exception, e: + self.logger.error(str(e)) + finally: + self.telnet_lock.release() + + + def switch_source(self, sourcename, status): + self.logger.debug('Switching source: %s to "%s" status', sourcename, status) + command = "streams." + if sourcename == "master_dj": + command += "master_dj_" + elif sourcename == "live_dj": + command += "live_dj_" + elif sourcename == "scheduled_play": + command += "scheduled_play_" + + if status == "on": + command += "start\n" + else: + command += "stop\n" + + self.telnet_send([command]) + class DummyTelnetLiquidsoap: def __init__(self, telnet_lock, logger):