2023-02-26 01:27:00 +01:00
|
|
|
import logging
|
2021-06-03 15:20:39 +02:00
|
|
|
import os
|
2022-01-13 16:11:37 +01:00
|
|
|
from pathlib import Path
|
|
|
|
from typing import Optional
|
2021-06-03 15:20:39 +02:00
|
|
|
|
2022-01-13 16:11:37 +01:00
|
|
|
import click
|
2022-08-10 17:33:22 +02:00
|
|
|
from libretime_api_client.v2 import ApiClient
|
|
|
|
from libretime_shared.cli import cli_config_options, cli_logging_options
|
2022-05-05 09:41:32 +02:00
|
|
|
from libretime_shared.config import DEFAULT_ENV_PREFIX
|
2023-02-26 01:27:00 +01:00
|
|
|
from libretime_shared.logging import setup_logger
|
2015-01-28 00:43:36 +01:00
|
|
|
|
2022-08-10 17:33:22 +02:00
|
|
|
from ..config import Config
|
2022-07-16 23:11:20 +02:00
|
|
|
from .entrypoint import generate_entrypoint
|
2022-08-10 17:33:22 +02:00
|
|
|
from .models import Info, StreamPreferences
|
2022-07-16 23:22:55 +02:00
|
|
|
from .version import get_liquidsoap_version
|
2021-06-03 15:20:39 +02:00
|
|
|
|
2023-02-26 01:27:00 +01:00
|
|
|
logger = logging.getLogger(__name__)
|
|
|
|
|
2022-07-16 23:24:29 +02:00
|
|
|
here = Path(__file__).parent
|
|
|
|
|
2015-01-28 00:43:36 +01:00
|
|
|
|
2022-05-05 09:41:32 +02:00
|
|
|
@click.command(context_settings={"auto_envvar_prefix": DEFAULT_ENV_PREFIX})
|
2022-01-20 06:30:35 +01:00
|
|
|
@cli_logging_options()
|
2022-08-10 17:33:22 +02:00
|
|
|
@cli_config_options()
|
|
|
|
def cli(log_level: str, log_filepath: Optional[Path], config_filepath: Optional[Path]):
|
2022-01-13 16:11:37 +01:00
|
|
|
"""
|
|
|
|
Run liquidsoap.
|
|
|
|
"""
|
2023-02-26 01:27:00 +01:00
|
|
|
setup_logger(log_level, log_filepath)
|
2022-08-10 17:33:22 +02:00
|
|
|
config = Config(config_filepath)
|
2020-01-23 11:37:49 +01:00
|
|
|
|
2022-08-10 17:33:22 +02:00
|
|
|
api_client = ApiClient(
|
|
|
|
base_url=config.general.public_url,
|
|
|
|
api_key=config.general.api_key,
|
|
|
|
)
|
2022-07-16 23:11:20 +02:00
|
|
|
|
2022-07-16 23:22:55 +02:00
|
|
|
version = get_liquidsoap_version()
|
|
|
|
|
2022-08-10 17:33:22 +02:00
|
|
|
info = Info(**api_client.get_info().json())
|
|
|
|
preferences = StreamPreferences(**api_client.get_stream_preferences().json())
|
|
|
|
|
|
|
|
entrypoint_filepath = Path.cwd() / "radio.liq"
|
2023-03-01 17:59:27 +01:00
|
|
|
entrypoint_filepath.write_text(
|
|
|
|
generate_entrypoint(
|
|
|
|
log_filepath,
|
|
|
|
config,
|
|
|
|
preferences,
|
|
|
|
info,
|
|
|
|
version,
|
|
|
|
),
|
|
|
|
encoding="utf-8",
|
2022-08-10 17:33:22 +02:00
|
|
|
)
|
|
|
|
|
2020-12-26 13:44:14 +01:00
|
|
|
exec_args = [
|
|
|
|
"/usr/bin/liquidsoap",
|
2021-10-03 16:12:04 +02:00
|
|
|
"libretime-liquidsoap",
|
2020-12-26 13:44:14 +01:00
|
|
|
"--verbose",
|
2022-08-10 17:33:22 +02:00
|
|
|
str(entrypoint_filepath),
|
2020-12-26 13:44:14 +01:00
|
|
|
]
|
2023-02-26 01:27:00 +01:00
|
|
|
if log_level == "debug":
|
2020-12-26 13:44:14 +01:00
|
|
|
exec_args.append("--debug")
|
2022-01-13 16:11:37 +01:00
|
|
|
|
2023-02-26 12:01:59 +01:00
|
|
|
logger.debug("liquidsoap %s using script: %s", version, entrypoint_filepath)
|
2020-12-26 13:44:14 +01:00
|
|
|
os.execl(*exec_args)
|