diff --git a/aura.py b/aura.py index addb0edf8d2f1b2820fd6e3a714d6ccfa3f759f8..6364eab293972e4eb2244d4a351179e07d57c84e 100755 --- a/aura.py +++ b/aura.py @@ -80,7 +80,7 @@ class Aura: Starts the Engine Core. """ from modules.scheduling.scheduler import AuraScheduler - from modules.communication.liquidsoap.communicator import LiquidSoapCommunicator + from modules.core.engine import SoundSystem from modules.communication.redis.adapter import ServerRedisAdapter # Check if the database has to be re-created @@ -88,16 +88,16 @@ class Aura: AuraScheduler(self.config, None) # Create scheduler and Liquidsoap communicator - self.liquidsoapcommunicator = LiquidSoapCommunicator(self.config) - self.scheduler = AuraScheduler(self.config, self.liquidsoapcommunicator) + self.soundsystem = SoundSystem(self.config) + self.scheduler = AuraScheduler(self.config, self.soundsystem) # Create the Redis adapter self.messenger = ServerRedisAdapter(self.config) self.messenger.scheduler = self.scheduler - self.messenger.liquidsoapcommunicator = self.liquidsoapcommunicator + self.messenger.soundsystem = self.soundsystem # TODO Check if it's working / needed. - #self.diskspace_watcher = DiskSpaceWatcher(self.config, self.logger, self.liquidsoapcommunicator) + #self.diskspace_watcher = DiskSpaceWatcher(self.config, self.logger, self.soundsystem) #self.diskspace_watcher.start() # And finally wait for redis message / start listener thread diff --git a/modules/cli_tool/padavan.py b/modules/cli_tool/padavan.py index 93e1d32f361fb943ed89cca2d0868e616b6e4ea8..a81033f306358686ca74fdfa1991c6ece718d5d7 100644 --- a/modules/cli_tool/padavan.py +++ b/modules/cli_tool/padavan.py @@ -35,7 +35,7 @@ class Padavan: args = None config = None - lsc = None + ss = None zmqclient = None redisclient = None stringreply = "" @@ -105,17 +105,17 @@ class Padavan: # ------------------------------------------------------------------------------------------ # def init_liquidsoap_communication(self): # import - from modules.communication.liquidsoap.communicator import LiquidSoapCommunicator + from modules.core.engine import SoundSystem # init liquidsoap communication - self.lsc = LiquidSoapCommunicator(self.config) + self.ss = SoundSystem(self.config) # enable connection - self.lsc.enable_transaction() + self.ss.enable_transaction() # ------------------------------------------------------------------------------------------ # def destroy_liquidsoap_communication(self): # enable connection - self.lsc.disable_transaction() + self.ss.disable_transaction() # ------------------------------------------------------------------------------------------ # def init_redis_communication(self, with_server=False): @@ -248,7 +248,7 @@ class Padavan: self.init_liquidsoap_communication() # select mixer and return the feedback - self.stringreply = self.lsc.channel_activate(mixername, activate) + self.stringreply = self.ss.channel_activate(mixername, activate) # disable connection self.destroy_liquidsoap_communication() @@ -257,14 +257,14 @@ class Padavan: def set_volume(self, mixernumber, volume): # init lqs and enable comm self.init_liquidsoap_communication() - self.stringreply = self.lsc.channel_volume(mixernumber, volume) + self.stringreply = self.ss.channel_volume(mixernumber, volume) # disable connection self.destroy_liquidsoap_communication() # ------------------------------------------------------------------------------------------ # def get_active_mixer(self): self.init_liquidsoap_communication() - am = self.lsc.get_active_mixer() + am = self.ss.get_active_mixer() if len(am) == 0: self.destroy_liquidsoap_communication() @@ -279,7 +279,7 @@ class Padavan: def get_mixer_status(self): self.init_liquidsoap_communication() - status = self.lsc.get_mixer_status() + status = self.ss.get_mixer_status() for k, v in status.items(): self.stringreply += "source: " + k + "\t status: " + v + "\n" diff --git a/modules/communication/redis/adapter.py b/modules/communication/redis/adapter.py index ab53544e2a3c8438f9e98be3e8da58a1011e783a..48db04bb0e50f4f07904af5bf714d1d70f750633 100644 --- a/modules/communication/redis/adapter.py +++ b/modules/communication/redis/adapter.py @@ -49,7 +49,7 @@ class ServerRedisAdapter(threading.Thread, RedisMessenger): scheduler = None redisclient = None # connection_tester = None - liquidsoapcommunicator = None + soundsystem = None socket = None # ------------------------------------------------------------------------------------------ # @@ -154,7 +154,7 @@ class ServerRedisAdapter(threading.Thread, RedisMessenger): self.logger.info("shutdown event received. Bye bye...") elif item["data"] == "init_player": - self.execute(RedisChannel.IP_REPLY.value, self.liquidsoapcommunicator.init_player) + self.execute(RedisChannel.IP_REPLY.value, self.soundsystem.init_player) elif item["data"] == "get_act_programme": self.execute(RedisChannel.GAP_REPLY.value, self.scheduler.get_act_programme_as_string) @@ -177,7 +177,7 @@ class ServerRedisAdapter(threading.Thread, RedisMessenger): elif item["data"].find("on_play") >= 0: source = item["data"].split("on_play ")[1] - self.execute(RedisChannel.TS_REPLY.value, self.scheduler.liquidsoapcommunicator.on_play, source) + self.execute(RedisChannel.TS_REPLY.value, self.scheduler.soundsystem.on_play, source) elif item["data"] == "recreate_db": self.execute(RedisChannel.RDB_REPLY.value, self.scheduler.recreate_database) diff --git a/modules/communication/liquidsoap/communicator.py b/modules/core/engine.py similarity index 99% rename from modules/communication/liquidsoap/communicator.py rename to modules/core/engine.py index eccf3f8458ab209134c373dc3f661c470fba6ed7..8462ab306471de26c643c0b3b5cdedbcc37fbff9 100644 --- a/modules/communication/liquidsoap/communicator.py +++ b/modules/core/engine.py @@ -38,9 +38,9 @@ from modules.base.exceptions import LQConnectionError, InvalidChannelException, from libraries.exceptions.exception_logger import ExceptionLogger -class LiquidSoapCommunicator(ExceptionLogger): +class SoundSystem(ExceptionLogger): """ - LiquidSoapCommunicator Class + SoundSystem Class Uses LiquidSoapClient, but introduces more complex commands, transactions and error handling. """ diff --git a/modules/core/startup.py b/modules/core/startup.py index 6787554e61c319b238a7bf49da3502e2585ab5c2..66c7bde66dddb33a5677e8965a8f04c25190cb08 100644 --- a/modules/core/startup.py +++ b/modules/core/startup.py @@ -37,18 +37,18 @@ class StartupThread(threading.Thread): """ logger = None active_entry = None - liquidsoapcommunicator = None + soundsystem = None scheduler = None - def __init__(self, liquidsoapcommunicator): + def __init__(self, soundsystem): """ Initialize the thread. """ threading.Thread.__init__(self) self.logger = logging.getLogger("AuraEngine") - self.liquidsoapcommunicator = liquidsoapcommunicator - self.scheduler = liquidsoapcommunicator.scheduler + self.soundsystem = soundsystem + self.scheduler = soundsystem.scheduler @@ -57,7 +57,7 @@ class StartupThread(threading.Thread): Boots the soundsystem. """ try: - self.liquidsoapcommunicator.start() + self.soundsystem.start() self.logger.info(EngineUtil.engine_info("Engine Core", meta.__version__)) self.scheduler.on_ready() diff --git a/modules/monitoring/diskspace_watcher.py b/modules/monitoring/diskspace_watcher.py index 3c157de309ec50a4440ddf7c187bd6bf96075d9c..7f3f5a72c823ac38d98af284a57c1dda5efb8d1a 100644 --- a/modules/monitoring/diskspace_watcher.py +++ b/modules/monitoring/diskspace_watcher.py @@ -34,7 +34,7 @@ from modules.base.exceptions import DiskSpaceException # ------------------------------------------------------------------------------------------ # class DiskSpaceWatcher(threading.Thread): - liquidsoapcommunicator = None + soundsystem = None exit_event = None config = None logger = None @@ -43,9 +43,9 @@ class DiskSpaceWatcher(threading.Thread): is_critical = False # ------------------------------------------------------------------------------------------ # - def __init__(self, config, logger, liquidsoapcommunicator): + def __init__(self, config, logger, soundsystem): threading.Thread.__init__(self) - self.liquidsoapcommunicator = liquidsoapcommunicator + self.soundsystem = soundsystem self.config = config self.logger = logger @@ -113,15 +113,15 @@ class DiskSpaceWatcher(threading.Thread): try: self.check_disk_space_of_folder(folder) # ensure recorder is running - if self.liquidsoapcommunicator.is_liquidsoap_running: - self.liquidsoapcommunicator.recorder_start(num) + if self.soundsystem.is_liquidsoap_running: + self.soundsystem.recorder_start(num) else: self.logger.warning("Cannot enable recorder. Liquidsoap is not running!") except DiskSpaceException as e: self.logger.critical(str(e)) # stop recorder when diskspace is critical - if self.liquidsoapcommunicator.is_liquidsoap_running: - self.liquidsoapcommunicator.recorder_stop(num) + if self.soundsystem.is_liquidsoap_running: + self.soundsystem.recorder_stop(num) else: self.logger.warning("Cannot stop recorder. Liquidsoap is not running!") @@ -160,8 +160,8 @@ class DiskSpaceWatcher(threading.Thread): subj = "Diskspace warning" msg = "Free space in " + folder + " under " + warning_value_raw + ". " + str(usage(total, used, free)) self.send_mail(subj, msg) - if self.liquidsoapcommunicator.is_liquidsoap_running: - self.liquidsoapcommunicator.recorder_start() + if self.soundsystem.is_liquidsoap_running: + self.soundsystem.recorder_start() else: self.logger.warning("Cannot enable recorder. Liquidsoap is not running!") self.sent_a_mail = True diff --git a/modules/scheduling/scheduler.py b/modules/scheduling/scheduler.py index cd336ef9fc61f28c6b45ad6d4e1a2de57d6b8963..722c94571fdbcf1020a1ab20528dd74aa3f8aa7f 100644 --- a/modules/scheduling/scheduler.py +++ b/modules/scheduling/scheduler.py @@ -71,7 +71,7 @@ class AuraScheduler(ExceptionLogger, threading.Thread): config (AuraConfig): Holds the Engine Configuration logger: The logger exit_event(threading.Event): Used to exit the thread if requested - liquidsoapcommunicator: Stores the connection to LiquidSoap + soundsystem: Manages the audio streams via LiquidSoap last_successful_fetch (datetime): Stores the last time a fetch from Steering/Tank was successful programme: The current radio programme to be played as defined in the local engine database @@ -84,7 +84,7 @@ class AuraScheduler(ExceptionLogger, threading.Thread): config = None logger = None exit_event = None - liquidsoapcommunicator = None + soundsystem = None last_successful_fetch = None programme = None message_timer = [] @@ -93,7 +93,7 @@ class AuraScheduler(ExceptionLogger, threading.Thread): - def __init__(self, config, liquidsoapcommunicator): + def __init__(self, config, soundsystem): """ Constructor @@ -107,8 +107,8 @@ class AuraScheduler(ExceptionLogger, threading.Thread): self.init_database() self.fallback_manager = FallbackManager(config, self.logger, self) self.redismessenger = RedisMessenger(config) - self.liquidsoapcommunicator = liquidsoapcommunicator - self.liquidsoapcommunicator.scheduler = self + self.soundsystem = soundsystem + self.soundsystem.scheduler = self # init threading threading.Thread.__init__(self) @@ -138,7 +138,7 @@ class AuraScheduler(ExceptionLogger, threading.Thread): self.logger.info("Fetch new programmes every %ss. Next fetching in %ss." % (str(seconds_to_wait), str(next_time))) self.fetch_new_programme() - if self.liquidsoapcommunicator.is_ready(): + if self.soundsystem.is_ready(): self.queue_programme() self.print_message_queue() @@ -183,7 +183,7 @@ class AuraScheduler(ExceptionLogger, threading.Thread): self.logger.info("The FFWD [>>] range exceeds the length of the entry. Drink some tea and wait for the sound of the next entry.") else: # Play active entry - self.liquidsoapcommunicator.play(active_entry, TransitionType.FADE) + self.soundsystem.play(active_entry, TransitionType.FADE) # Check if this is the last item of the schedule if active_entry.end_unix > active_entry.playlist.schedule.end_unix: @@ -198,9 +198,9 @@ class AuraScheduler(ExceptionLogger, threading.Thread): seconds_to_seek += sleep_offset time.sleep(sleep_offset) self.logger.info("Going to fast-forward %s seconds" % seconds_to_seek) - self.liquidsoapcommunicator.enable_transaction() - response = self.liquidsoapcommunicator.playlist_seek(active_entry.channel, seconds_to_seek) - self.liquidsoapcommunicator.disable_transaction() + self.soundsystem.enable_transaction() + response = self.soundsystem.playlist_seek(active_entry.channel, seconds_to_seek) + self.soundsystem.disable_transaction() self.logger.info("LiquidSoap seek response: " + response) @@ -553,7 +553,7 @@ class AuraScheduler(ExceptionLogger, threading.Thread): transition_type = TransitionType.INSTANT if fade_in: transition_type = TransitionType.FADE - self.liquidsoapcommunicator.play(entry, transition_type) + self.soundsystem.play(entry, transition_type) self.logger.info(self.get_ascii_programme()) @@ -636,7 +636,7 @@ class AuraScheduler(ExceptionLogger, threading.Thread): transition_type = TransitionType.INSTANT if fade_out: transition_type = TransitionType.FADE - self.liquidsoapcommunicator.stop(entry, transition_type) + self.soundsystem.stop(entry, transition_type) if fade_out == True: fade_out_time = int(round(float(self.config.get("fade_out_time")))) #FIXME Use float @@ -752,7 +752,7 @@ class AuraScheduler(ExceptionLogger, threading.Thread): # """ # self.logger.critical("ENABLING SWITCHTIMER FOR " + str(entry)) - # entry.switchtimer = self.add_or_update_timer(diff, self.liquidsoapcommunicator.play, [entry]) + # entry.switchtimer = self.add_or_update_timer(diff, self.soundsystem.play, [entry]) # # FIXME Fade In/Out logic: Not sure if that's functional # #self.enable_fading(diff, entry, old_entry) @@ -765,14 +765,14 @@ class AuraScheduler(ExceptionLogger, threading.Thread): # # enable fading when entry types are different # if old_entry is not None: # if old_entry.type != new_entry.type: - # #self.add_or_update_timer(diff, self.liquidsoapcommunicator.fade_out, [old_entry]) - # old_entry.fadeouttimer = self.create_timer(diff-fade_out_time, self.liquidsoapcommunicator.fade_out, [old_entry], fadeout=True) + # #self.add_or_update_timer(diff, self.soundsystem.fade_out, [old_entry]) + # old_entry.fadeouttimer = self.create_timer(diff-fade_out_time, self.soundsystem.fade_out, [old_entry], fadeout=True) # self.logger.critical("ENABLING FADEOUTTIMER FOR " + str(old_entry)) # # same for fadein except old_entry can be None # else: - # #self.add_or_update_timer(diff, self.liquidsoapcommunicator.fade_in, [new_entry]) - # new_entry.fadeintimer = self.create_timer(diff, self.liquidsoapcommunicator.fade_in, [new_entry], fadein=True) + # #self.add_or_update_timer(diff, self.soundsystem.fade_in, [new_entry]) + # new_entry.fadeintimer = self.create_timer(diff, self.soundsystem.fade_in, [new_entry], fadein=True) # self.logger.critical("ENABLING FADEINTIMER FOR " + str(new_entry)) diff --git a/testing/connection_tester.py b/testing/connection_tester.py index d508df7093e575feac42b0208f777c7e32373093..c156b7d22de7d6d831575ef78b9b25a37df06ee8 100644 --- a/testing/connection_tester.py +++ b/testing/connection_tester.py @@ -26,7 +26,7 @@ import urllib import logging import json -from modules.communication.liquidsoap.communicator import LiquidSoapCommunicator +from modules.core.engine import SoundSystem #from libraries.database.broadcasts import ScheduleEntry from modules.base.config import AuraConfig @@ -62,7 +62,7 @@ class ConnectionTester(AuraConfig): # ------------------------------------------------------------------------------------------ # def test_lqs_conn(self): try: - lsc = LiquidSoapCommunicator(self.config) + lsc = soundsystem(self.config) lsc.get_mixer_status() return True @@ -72,7 +72,7 @@ class ConnectionTester(AuraConfig): # ------------------------------------------------------------------------------------------ # def test_lqsr_conn(self): try: - lsc = LiquidSoapCommunicator(self.config) + lsc = soundsystem(self.config) lsc.get_recorder_status() return True diff --git a/testing/test.py b/testing/test.py index d2f19d27b3fab546208de370e4709c6ec070b0e2..06e047ac94b5642d2579247b317654117c79e3c0 100644 --- a/testing/test.py +++ b/testing/test.py @@ -13,7 +13,7 @@ from libraries.database.broadcasts import Schedule, TrackService # from libraries.security.user import AuraUser # modules -from modules.communication.liquidsoap.communicator import LiquidSoapCommunicator +from modules.core.engine import SoundSystem from modules.scheduling.scheduler import AuraScheduler class TestLogger(unittest.TestCase): @@ -128,10 +128,10 @@ class TestLQSComm(unittest.TestCase): # wosn do passiert? p = AuraConfig().config - self.comm = LiquidSoapCommunicator(p) - self.comm.scheduler = AuraScheduler(p) + self.soundsystem = SoundSystem(p) + self.soundsystem.scheduler = AuraScheduler(p) - self.comm.init_player() + self.soundsystem.init_player() def test_get_active_channel(self): diff --git a/testing/tests.py b/testing/tests.py index 1e05f9548ddb04e1be82479f9e2ee624b0ec3d56..db893cc6934927f927a422f16cf9b4165500034f 100755 --- a/testing/tests.py +++ b/testing/tests.py @@ -30,7 +30,7 @@ import logging import sqlalchemy import decimal -from modules.communication.liquidsoap.communicator import LiquidSoapCommunicator +from modules.core.engine import SoundSystem from modules.monitoring.diskspace_watcher import DiskSpaceWatcher from modules.base.config import AuraConfig from libraries.database.broadcasts import Schedule, ScheduleEntry @@ -55,7 +55,7 @@ def alchemyencoder(obj): def start_diskspace_watcher(): config = AuraConfig() config.read_config() - diskspace_watcher = DiskSpaceWatcher(config.config, logging.getLogger("AuraEngine"), LiquidSoapCommunicator(config.config)) + diskspace_watcher = DiskSpaceWatcher(config.config, logging.getLogger("AuraEngine"), SoundSystem(config.config)) diskspace_watcher.run() def select_current_programme(): @@ -64,11 +64,11 @@ def select_current_programme(): config = AuraConfig() config.read_config() - liquidsoapcommunicator = LiquidSoapCommunicator(config.config) + soundsystem = SoundSystem(config.config) sched = AuraScheduler(config.config) - liquidsoapcommunicator.scheduler = sched - sched.liquidsoapcommunicator = liquidsoapcommunicator + soundsystem.scheduler = sched + sched.soundsystem = soundsystem programme = sched.load_programme_from_db()