refactor(playout): use vars setter in liq client

This commit is contained in:
jo 2022-08-17 15:44:37 +02:00 committed by Kyle Robbertze
parent fa559e2569
commit fd2381624a
1 changed files with 9 additions and 8 deletions

View File

@ -1,7 +1,7 @@
from pathlib import Path from pathlib import Path
from subprocess import CalledProcessError, check_output, run from subprocess import CalledProcessError, check_output, run
from time import sleep from time import sleep
from typing import Optional, Tuple from typing import Any, Optional, Tuple
from loguru import logger from loguru import logger
from typing_extensions import Literal from typing_extensions import Literal
@ -37,6 +37,10 @@ class LiquidsoapClient:
timeout=timeout, timeout=timeout,
) )
def _set_var(self, name: str, value: Any):
self.conn.write(f"vars.{name} {value}")
self.conn.read()
def version(self) -> Tuple[int, int, int]: def version(self) -> Tuple[int, int, int]:
with self.conn: with self.conn:
self.conn.write("version") self.conn.write("version")
@ -63,7 +67,7 @@ class LiquidsoapClient:
def queue_push(self, queue_id: int, entry: str, show_name: str) -> None: def queue_push(self, queue_id: int, entry: str, show_name: str) -> None:
with self.conn: with self.conn:
self.conn.write(f"{queue_id}.push {entry}") self.conn.write(f"{queue_id}.push {entry}")
self.conn.write(f"vars.show_name {show_name}") self._set_var("show_name", show_name)
def web_stream_get_id(self) -> str: def web_stream_get_id(self) -> str:
with self.conn: with self.conn:
@ -115,14 +119,11 @@ class LiquidsoapClient:
): ):
with self.conn: with self.conn:
if station_name is not None: if station_name is not None:
self.conn.write(f"vars.station_name {station_name}") self._set_var("station_name", station_name)
self.conn.read()
if message_format is not None: if message_format is not None:
self.conn.write(f"vars.stream_metadata_type {message_format}") self._set_var("stream_metadata_type", message_format)
self.conn.read()
if input_fade_transition is not None: if input_fade_transition is not None:
self.conn.write(f"vars.default_dj_fade {input_fade_transition}") self._set_var("default_dj_fade", input_fade_transition)
self.conn.read()
def restart(self): def restart(self):
logger.warning("restarting Liquidsoap") logger.warning("restarting Liquidsoap")