feat(playout): use shared app for cli commands
This commit is contained in:
parent
a71606d39c
commit
78c74f47ca
|
@ -18,69 +18,91 @@ from typing import Optional
|
|||
|
||||
import click
|
||||
from libretime_api_client.v1 import ApiClient as LegacyClient
|
||||
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 setup_logger
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
from ..config import Config
|
||||
|
||||
def api_client():
|
||||
return LegacyClient()
|
||||
|
||||
class App:
|
||||
config: Config
|
||||
api_client: LegacyClient
|
||||
|
||||
def __init__(self, config: Config) -> None:
|
||||
self.config = config
|
||||
self.api_client = LegacyClient()
|
||||
|
||||
|
||||
pass_app = click.make_pass_decorator(App)
|
||||
|
||||
|
||||
@click.group(context_settings={"auto_envvar_prefix": DEFAULT_ENV_PREFIX})
|
||||
@cli_logging_options()
|
||||
def cli(log_level: str, log_filepath: Optional[Path]):
|
||||
@cli_config_options()
|
||||
@click.pass_context
|
||||
def cli(
|
||||
ctx: click.Context,
|
||||
log_level: str,
|
||||
log_filepath: Optional[Path],
|
||||
config_filepath: Optional[Path],
|
||||
):
|
||||
"""
|
||||
A gateway between Liquidsoap and the API.
|
||||
"""
|
||||
setup_logger(log_level, log_filepath, rotate=False)
|
||||
ctx.obj = App(config=Config(config_filepath))
|
||||
|
||||
|
||||
@cli.command()
|
||||
@click.argument("media_id")
|
||||
def media(media_id):
|
||||
@pass_app
|
||||
def media(app: App, media_id):
|
||||
"""
|
||||
Notify currently playing media.
|
||||
|
||||
Replaces: notify --media-id=#{m['schedule_table_id']}
|
||||
"""
|
||||
logger.info("Sending currently playing media id '%s'", media_id)
|
||||
api_client().notify_media_item_start_playing(media_id)
|
||||
app.api_client.notify_media_item_start_playing(media_id)
|
||||
|
||||
|
||||
@cli.command()
|
||||
@click.argument("media_id")
|
||||
@click.argument("data")
|
||||
def webstream(media_id, data):
|
||||
@pass_app
|
||||
def webstream(app: App, media_id, data):
|
||||
"""
|
||||
Notify currently playing webstream.
|
||||
|
||||
Replaces: notify --webstream='#{json_str}' --media-id=#{!current_dyn_id}
|
||||
"""
|
||||
logger.info("Sending currently playing webstream '%s' data '%s'", media_id, data)
|
||||
api_client().notify_webstream_data(data, media_id)
|
||||
app.api_client.notify_webstream_data(data, media_id)
|
||||
|
||||
|
||||
@cli.command()
|
||||
@click.argument("name")
|
||||
@click.argument("status")
|
||||
def live(name, status):
|
||||
@pass_app
|
||||
def live(app: App, name, status):
|
||||
"""
|
||||
Notify currently playing live input.
|
||||
|
||||
Replaces: notify --source-name=#{sourcename} --source-status=#{status}
|
||||
"""
|
||||
logger.info("Sending currently playing live source '%s' status '%s'", name, status)
|
||||
api_client().notify_source_status(name, status)
|
||||
app.api_client.notify_source_status(name, status)
|
||||
|
||||
|
||||
@cli.command()
|
||||
@click.argument("stream_id")
|
||||
@click.argument("time")
|
||||
@click.option("--error", help="Error message if any occurred.")
|
||||
def stream(stream_id, time, error):
|
||||
@pass_app
|
||||
def stream(app: App, stream_id, time, error):
|
||||
"""
|
||||
Notify about output stream status.
|
||||
|
||||
|
@ -92,15 +114,16 @@ def stream(stream_id, time, error):
|
|||
status = error
|
||||
|
||||
logger.info("Sending output stream '%s' status '%s'", stream_id, status)
|
||||
api_client().notify_liquidsoap_status(status, stream_id, time)
|
||||
app.api_client.notify_liquidsoap_status(status, stream_id, time)
|
||||
|
||||
|
||||
@cli.command()
|
||||
def started():
|
||||
@pass_app
|
||||
def started(app: App):
|
||||
"""
|
||||
Notify liquidsoap startup status.
|
||||
|
||||
Replaces: notify --liquidsoap-started
|
||||
"""
|
||||
logger.debug("Notifying server that Liquidsoap has started")
|
||||
api_client().notify_liquidsoap_started()
|
||||
app.api_client.notify_liquidsoap_started()
|
||||
|
|
Loading…
Reference in New Issue