Skip to content
Snippets Groups Projects
Commit da0e198b authored by David Trattnig's avatar David Trattnig
Browse files

Run player with workaround to FFWD per schedule.

parent 474a8b6e
No related branches found
No related tags found
No related merge requests found
...@@ -29,67 +29,92 @@ import threading ...@@ -29,67 +29,92 @@ import threading
from libraries.enum.auraenumerations import ScheduleEntryType from libraries.enum.auraenumerations import ScheduleEntryType
"""
LiquidSoapInitThread class.
Starts the LiquidSoap player including the current show.
"""
class LiquidSoapInitThread(threading.Thread): class LiquidSoapInitThread(threading.Thread):
logger = None logger = None
active_entry = None active_entry = None
liquidsoapcommunicator = None liquidsoapcommunicator = None
# ------------------------------------------------------------------------------------------ #
def __init__(self, liquidsoapcommunicator, active_entry): def __init__(self, liquidsoapcommunicator, active_entry):
"""
Initialize the thread.
"""
threading.Thread.__init__(self) threading.Thread.__init__(self)
self.logger = logging.getLogger("AuraEngine") self.logger = logging.getLogger("AuraEngine")
self.liquidsoapcommunicator = liquidsoapcommunicator self.liquidsoapcommunicator = liquidsoapcommunicator
self.active_entry = active_entry self.active_entry = active_entry
# ------------------------------------------------------------------------------------------ #
def run(self): def run(self):
"""
Starts the LiquidSoap player including the current show.
"""
try: try:
# sleep needed, because the socket is created too slow by liquidsoap # Sleep needed, because the socket is created too slow by liquidsoap
time.sleep(1) time.sleep(1)
self.logger.info("Waited 1s for liquidsoap. Jez soit a si gspian") self.logger.info("Waited 1s for liquidsoap. Jez soit a si gspian")
# enable lqs transaction
self.liquidsoapcommunicator.enable_transaction() self.liquidsoapcommunicator.enable_transaction()
# wait another second. lqs really starts slow.. be prepared you liquidsoap you! # Wait another second. lqs really starts slow.. be prepared you liquidsoap you!
time.sleep(1) time.sleep(1)
# set some parameters
self.set_start_parameters() self.set_start_parameters()
# set active
self.set_active_show() self.set_active_show()
# disable lqs transaction again
self.liquidsoapcommunicator.disable_transaction() self.liquidsoapcommunicator.disable_transaction()
# The rest of the system now can use liquidsoap connection
# the rest of the system now can use liquidsoap connection
self.liquidsoapcommunicator.is_liquidsoap_running = True self.liquidsoapcommunicator.is_liquidsoap_running = True
except Exception as e: except Exception as e:
self.logger.critical("Liquidsoap connection ERROR! Restart LQ Server! Reason: "+str(e)) self.logger.critical("Liquidsoap connection ERROR! Restart LQ Server! Reason: "+str(e), e)
def set_active_show(self): def set_active_show(self):
"""
Sets and resumes the show which should be playing at the time of starting
the LiquidSoap player.
"""
if self.active_entry is not None: if self.active_entry is not None:
self.logger.info("LiquidSoapInitThread sets activechannel: " + str(self.active_entry))
channel = self.active_entry.type channel = self.active_entry.type
self.logger.info("LiquidSoapInitThread sets activechannel '%s' for entry '%s'" % (channel, str(self.active_entry)))
# have to seek?
if channel == ScheduleEntryType.FILESYSTEM: if channel == ScheduleEntryType.FILESYSTEM:
# calc how many seconds were missed
# Have to seek? Calc how many seconds were missed
now_unix = time.mktime(datetime.datetime.now().timetuple()) now_unix = time.mktime(datetime.datetime.now().timetuple())
seconds_to_seek = now_unix - self.active_entry.start_unix seconds_to_seek = now_unix - self.active_entry.start_unix
# and seek these seconds forward # TODO For some reason LiquidSoap cue-points don't work. Actually,
# this would be the ideal approach to seek. Investigate some solution!
# if seconds_to_seek < 0:
# seconds_to_seek = 0
# self.liquidsoapcommunicator.activate(self.active_entry, seconds_to_seek)
self.liquidsoapcommunicator.activate(self.active_entry, seconds_to_seek)
# And seek these seconds forward
if seconds_to_seek > 0: if seconds_to_seek > 0:
self.liquidsoapcommunicator.playlist_seek(seconds_to_seek) # Without plenty of timeout (10s) the seek doesn't work
seconds_to_seek += 10
time.sleep(10)
response = self.liquidsoapcommunicator.playlist_seek(seconds_to_seek)
self.logger.info("LiquidSoap seek response: " + response)
# finally make something hearable :-) # Finally make something hearable :-)
if channel != "" and channel is not None: if channel:
# activate http stream if needed # Activate HTTP stream if needed
self.liquidsoapcommunicator.http_start_stop(channel == ScheduleEntryType.STREAM) self.liquidsoapcommunicator.http_start_stop(channel == ScheduleEntryType.STREAM)
# finally set the volume up # Finally set the volume up
self.liquidsoapcommunicator.channel_volume(channel.value, self.active_entry.volume) self.liquidsoapcommunicator.channel_volume(channel.value, self.active_entry.volume)
else: else:
self.logger.error("Channel is NULL or empty! Cannot set ") self.logger.error("Channel is NULL or empty! Cannot set ")
...@@ -97,18 +122,23 @@ class LiquidSoapInitThread(threading.Thread): ...@@ -97,18 +122,23 @@ class LiquidSoapInitThread(threading.Thread):
else: else:
self.logger.warning("No active entry in the scheduler! Is a programme loaded?") self.logger.warning("No active entry in the scheduler! Is a programme loaded?")
def set_start_parameters(self): def set_start_parameters(self):
# reset channels and reload them """
Set initial parameters for the LiquidSoap player startup.
"""
# Reset channels and reload them
channels = self.liquidsoapcommunicator.reload_channels() channels = self.liquidsoapcommunicator.reload_channels()
# for all available channels # For all available channels
for c in channels: for c in channels:
# set volume to zero # Set volume to zero
self.liquidsoapcommunicator.channel_volume(c, "0") self.liquidsoapcommunicator.channel_volume(c, "0")
# and activate this channel # And activate this channel
self.liquidsoapcommunicator.channel_activate(c, True) self.liquidsoapcommunicator.channel_activate(c, True)
# setting init params like a blank file.. # Setting init params like a blank file..
install_dir = self.liquidsoapcommunicator.config.get("install_dir") install_dir = self.liquidsoapcommunicator.config.get("install_dir")
self.liquidsoapcommunicator.playlist_push(install_dir + "/configuration/blank.flac") self.liquidsoapcommunicator.playlist_push(install_dir + "/configuration/blank.flac")
# .. or the radio fro stream (it is overwritten as soon as one http overtake is planned) # .. or the radio fro stream (it is overwritten as soon as one http overtake is planned)
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment