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

Move to core.

parent a6fd60cc
No related branches found
No related tags found
No related merge requests found
# #
# engine # Aura Engine
#
# Playout Daemon for autoradio project
#
#
# Copyright (C) 2017-2018 Gottfried Gaisbauer <gottfried.gaisbauer@servus.at>
#
# This file is part of engine.
#
# engine is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# any later version.
#
# engine is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with engine. If not, see <http://www.gnu.org/licenses/>.
# #
# Copyright (C) 2017-2020
# David Trattnig <david.trattnig@subsquare.at>
# Gottfried Gaisbauer <gottfried.gaisbauer@servus.at>
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Affero General Public License for more details.
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
import time import time
import logging import logging
import datetime import datetime
import threading import threading
import meta
from libraries.enum.auraenumerations import ScheduleEntryType, TerminalColors from modules.base.enum import Channel, ChannelType
from modules.base.utils import TerminalColors, SimpleUtil, EngineUtil
"""
LiquidSoapInitThread class.
Starts the LiquidSoap player including the current show. class StartupThread(threading.Thread):
""" """
StartupThread class.
class LiquidSoapInitThread(threading.Thread):
Boots the mixer and starts playing the current schedule.
"""
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. Initialize the thread.
...@@ -67,13 +64,23 @@ class LiquidSoapInitThread(threading.Thread): ...@@ -67,13 +64,23 @@ class LiquidSoapInitThread(threading.Thread):
# 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)
self.logger.info(SimpleUtil.green("Engine Core ------[ connected ]-------- Liquidsoap"))
self.set_start_parameters() self.set_start_parameters()
self.set_active_show() self.logger.info(EngineUtil.engine_info("Engine Core", meta.__version__))
# Display the current programme
programme = self.liquidsoapcommunicator.scheduler.get_ascii_programme()
self.logger.info(programme)
# Start playing
self.set_active_show()
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(TerminalColors.RED.value+"Liquidsoap connection ERROR! Restart LQ Server! Reason: "+str(e)+TerminalColors.ENDC.value) self.logger.critical(TerminalColors.RED.value+"Liquidsoap connection ERROR! Restart LQ Server! Reason: "+str(e)+TerminalColors.ENDC.value)
...@@ -85,22 +92,15 @@ class LiquidSoapInitThread(threading.Thread): ...@@ -85,22 +92,15 @@ class LiquidSoapInitThread(threading.Thread):
the LiquidSoap player. the LiquidSoap player.
""" """
if self.active_entry is not None: if self.active_entry is not None:
channel = self.active_entry.type channel_type = self.active_entry.type
self.logger.info("LiquidSoapInitThread sets activechannel '%s' for entry '%s'" % (channel, str(self.active_entry))) self.logger.info("Engine Startup: Play '%s' via channel type '%s'" % (str(self.active_entry), channel_type))
if channel == ScheduleEntryType.FILESYSTEM: # TODO Skip active entry if not enough time left; wait and play next one instead
self.liquidsoapcommunicator.play(self.active_entry, False)
# TODO For some reason LiquidSoap cue-points don't work. Actually,
# this would be the ideal approach to seek. Investigate some solution! if channel_type == ChannelType.FILESYSTEM:
# if seconds_to_seek < 0:
# seconds_to_seek = 0
# self.liquidsoapcommunicator.activate(self.active_entry, seconds_to_seek)
self.liquidsoapcommunicator.activate(self.active_entry)
# rest_of_playlist = self.active_entry.get_next_entries()
# for entry in rest_of_playlist:
# self.logger.info("ACTIVATING NEXT ENTRY: %s" %entry)
# self.liquidsoapcommunicator.activate(entry)
# Have to seek? 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())
...@@ -111,40 +111,25 @@ class LiquidSoapInitThread(threading.Thread): ...@@ -111,40 +111,25 @@ class LiquidSoapInitThread(threading.Thread):
# Without plenty of timeout (10s) the seek doesn't work # Without plenty of timeout (10s) the seek doesn't work
seconds_to_seek += 10 seconds_to_seek += 10
time.sleep(10) time.sleep(10)
response = self.liquidsoapcommunicator.playlist_seek(seconds_to_seek) channel = self.liquidsoapcommunicator.active_channel[ChannelType.FILESYSTEM]
response = self.liquidsoapcommunicator.playlist_seek(channel, seconds_to_seek)
self.logger.info("LiquidSoap seek response: " + response) self.logger.info("LiquidSoap seek response: " + response)
# Finally make something hearable :-)
if channel:
# Activate HTTP stream if needed
self.liquidsoapcommunicator.http_start_stop(channel == ScheduleEntryType.STREAM)
# Finally set the volume up
self.liquidsoapcommunicator.channel_volume(channel.value, self.active_entry.volume)
else:
self.logger.error("Channel is NULL or empty! Cannot set ")
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):
""" """
Set initial parameters for the LiquidSoap player startup. Set initial parameters for the LiquidSoap player startup.
""" """
# Reset channels and reload them self.liquidsoapcommunicator.mixer_start()
channels = self.liquidsoapcommunicator.reload_channels()
# For all available channels
for c in channels:
# Set volume to zero
self.liquidsoapcommunicator.channel_volume(c, "0")
# And activate this channel
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") channel = self.liquidsoapcommunicator.active_channel[ChannelType.FILESYSTEM]
self.liquidsoapcommunicator.playlist_push(channel, 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)
#self.liquidsoapcommunicator.set_http_url("http://stream.fro.at/fro-128.ogg") #self.liquidsoapcommunicator.set_http_url("http://stream.fro.at/fro-128.ogg")
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment