feat(playout): load config using shared helpers
- backport >=py38 Literal type - update configuration sample - add missing config filepath to systemd service - make config sections optional BREAKING CHANGE: the playout config schema has been changed like the following: - the top section 'pypo' was renamed to 'playout' - the 'playout.ls_*' entries were renamed to 'playout.liquidsoap_*' - the 'playout.*_dir' entries were removed - the 'playout.api_client' entry was removed - the 'playout.record_file_type' entry was renamed to 'playout.record_file_format' - the 'playout.base_recorded_files' entry was removed - the 'playout.poll_interval' entry was removed - the 'playout.push_interval' entry was removed - the 'playout.cue_style' entry was removed
This commit is contained in:
parent
12f96f5043
commit
fa7692071c
12 changed files with 142 additions and 214 deletions
|
@ -16,15 +16,14 @@ from threading import Lock
|
|||
from typing import Optional
|
||||
|
||||
import click
|
||||
from configobj import ConfigObj
|
||||
from libretime_api_client.version1 import AirtimeApiClient as ApiClient
|
||||
from libretime_shared.cli import cli_logging_options
|
||||
from libretime_shared.cli import cli_config_options, cli_logging_options
|
||||
from libretime_shared.config import DEFAULT_ENV_PREFIX
|
||||
from libretime_shared.logging import level_from_name, setup_logger
|
||||
from loguru import logger
|
||||
|
||||
from . import pure
|
||||
from .config import CACHE_DIR, RECORD_DIR
|
||||
from .config import CACHE_DIR, RECORD_DIR, Config
|
||||
from .listenerstat import ListenerStat
|
||||
from .pypofetch import PypoFetch
|
||||
from .pypofile import PypoFile
|
||||
|
@ -81,15 +80,23 @@ def get_liquidsoap_version(version_string):
|
|||
return None
|
||||
|
||||
|
||||
def liquidsoap_startup_test(telnet_lock, ls_host, ls_port):
|
||||
def liquidsoap_startup_test(telnet_lock, liquidsoap_host, liquidsoap_port):
|
||||
|
||||
liquidsoap_version_string = liquidsoap_get_info(telnet_lock, ls_host, ls_port)
|
||||
liquidsoap_version_string = liquidsoap_get_info(
|
||||
telnet_lock,
|
||||
liquidsoap_host,
|
||||
liquidsoap_port,
|
||||
)
|
||||
while not liquidsoap_version_string:
|
||||
logger.warning(
|
||||
"Liquidsoap doesn't appear to be running!, " + "Sleeping and trying again"
|
||||
)
|
||||
time.sleep(1)
|
||||
liquidsoap_version_string = liquidsoap_get_info(telnet_lock, ls_host, ls_port)
|
||||
liquidsoap_version_string = liquidsoap_get_info(
|
||||
telnet_lock,
|
||||
liquidsoap_host,
|
||||
liquidsoap_port,
|
||||
)
|
||||
|
||||
while pure.version_cmp(liquidsoap_version_string, LIQUIDSOAP_MIN_VERSION) < 0:
|
||||
logger.warning(
|
||||
|
@ -98,24 +105,24 @@ def liquidsoap_startup_test(telnet_lock, ls_host, ls_port):
|
|||
% LIQUIDSOAP_MIN_VERSION
|
||||
)
|
||||
time.sleep(1)
|
||||
liquidsoap_version_string = liquidsoap_get_info(telnet_lock, ls_host, ls_port)
|
||||
liquidsoap_version_string = liquidsoap_get_info(
|
||||
telnet_lock,
|
||||
liquidsoap_host,
|
||||
liquidsoap_port,
|
||||
)
|
||||
|
||||
logger.info("Liquidsoap version string found %s" % liquidsoap_version_string)
|
||||
|
||||
|
||||
@click.command()
|
||||
@cli_logging_options()
|
||||
def cli(log_level: str, log_filepath: Optional[Path]):
|
||||
@cli_config_options()
|
||||
def cli(log_level: str, log_filepath: Optional[Path], config_filepath: Optional[Path]):
|
||||
"""
|
||||
Run playout.
|
||||
"""
|
||||
setup_logger(level_from_name(log_level), log_filepath)
|
||||
|
||||
# loading config file
|
||||
try:
|
||||
config = ConfigObj("/etc/airtime/airtime.conf")
|
||||
except Exception as e:
|
||||
logger.error("Error loading config file: %s", e)
|
||||
config = Config(filepath=config_filepath)
|
||||
|
||||
try:
|
||||
for dir_path in [CACHE_DIR, RECORD_DIR]:
|
||||
|
@ -154,16 +161,16 @@ def cli(log_level: str, log_filepath: Optional[Path]):
|
|||
|
||||
telnet_lock = Lock()
|
||||
|
||||
ls_host = config["pypo"]["ls_host"]
|
||||
ls_port = config["pypo"]["ls_port"]
|
||||
liquidsoap_host = config.playout.liquidsoap_host
|
||||
liquidsoap_port = config.playout.liquidsoap_port
|
||||
|
||||
liquidsoap_startup_test(telnet_lock, ls_host, ls_port)
|
||||
liquidsoap_startup_test(telnet_lock, liquidsoap_host, liquidsoap_port)
|
||||
|
||||
pypoFetch_q = Queue()
|
||||
recorder_q = Queue()
|
||||
pypoPush_q = Queue()
|
||||
|
||||
pypo_liquidsoap = PypoLiquidsoap(telnet_lock, ls_host, ls_port)
|
||||
pypo_liquidsoap = PypoLiquidsoap(telnet_lock, liquidsoap_host, liquidsoap_port)
|
||||
|
||||
"""
|
||||
This queue is shared between pypo-fetch and pypo-file, where pypo-file
|
||||
|
@ -174,25 +181,30 @@ def cli(log_level: str, log_filepath: Optional[Path]):
|
|||
media_q = Queue()
|
||||
|
||||
# Pass only the configuration sections needed; PypoMessageHandler only needs rabbitmq settings
|
||||
pmh = PypoMessageHandler(pypoFetch_q, recorder_q, config["rabbitmq"])
|
||||
pmh = PypoMessageHandler(pypoFetch_q, recorder_q, config.rabbitmq)
|
||||
pmh.daemon = True
|
||||
pmh.start()
|
||||
|
||||
pfile = PypoFile(media_q, config["pypo"])
|
||||
pfile = PypoFile(media_q)
|
||||
pfile.daemon = True
|
||||
pfile.start()
|
||||
|
||||
pf = PypoFetch(
|
||||
pypoFetch_q, pypoPush_q, media_q, telnet_lock, pypo_liquidsoap, config["pypo"]
|
||||
pypoFetch_q,
|
||||
pypoPush_q,
|
||||
media_q,
|
||||
telnet_lock,
|
||||
pypo_liquidsoap,
|
||||
config,
|
||||
)
|
||||
pf.daemon = True
|
||||
pf.start()
|
||||
|
||||
pp = PypoPush(pypoPush_q, telnet_lock, pypo_liquidsoap, config["pypo"])
|
||||
pp = PypoPush(pypoPush_q, telnet_lock, pypo_liquidsoap, config)
|
||||
pp.daemon = True
|
||||
pp.start()
|
||||
|
||||
recorder = Recorder(recorder_q)
|
||||
recorder = Recorder(recorder_q, config)
|
||||
recorder.daemon = True
|
||||
recorder.start()
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue