feat(playout): use single clients instance (#1980)
- Use legacy_client across playout code to make the difference between the old and new clients. - Setup clients during initialization, and pass clients down to the different apps.
This commit is contained in:
parent
f03605a6ce
commit
368350b269
|
@ -5,7 +5,7 @@ import traceback
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
from typing import Optional
|
from typing import Optional
|
||||||
|
|
||||||
from libretime_api_client.v1 import ApiClient
|
from libretime_api_client.v1 import ApiClient as LegacyClient
|
||||||
from loguru import logger
|
from loguru import logger
|
||||||
|
|
||||||
|
|
||||||
|
@ -50,8 +50,8 @@ def generate_entrypoint(log_filepath: Optional[Path]):
|
||||||
|
|
||||||
while not successful:
|
while not successful:
|
||||||
try:
|
try:
|
||||||
ac = ApiClient(logger)
|
legacy_client = LegacyClient(logger)
|
||||||
ss = ac.get_stream_setting()
|
ss = legacy_client.get_stream_setting()
|
||||||
generate_liquidsoap_config(ss, log_filepath)
|
generate_liquidsoap_config(ss, log_filepath)
|
||||||
successful = True
|
successful = True
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
|
|
|
@ -1,8 +1,8 @@
|
||||||
import sys
|
import sys
|
||||||
|
|
||||||
from libretime_api_client.v1 import ApiClient
|
from libretime_api_client.v1 import ApiClient as LegacyClient
|
||||||
|
|
||||||
api_client = ApiClient()
|
legacy_client = LegacyClient()
|
||||||
|
|
||||||
dj_type = sys.argv[1]
|
dj_type = sys.argv[1]
|
||||||
username = sys.argv[2]
|
username = sys.argv[2]
|
||||||
|
@ -14,7 +14,7 @@ if dj_type == "--master":
|
||||||
elif dj_type == "--dj":
|
elif dj_type == "--dj":
|
||||||
source_type = "dj"
|
source_type = "dj"
|
||||||
|
|
||||||
response = api_client.check_live_stream_auth(username, password, source_type)
|
response = legacy_client.check_live_stream_auth(username, password, source_type)
|
||||||
|
|
||||||
if "msg" in response and response["msg"] == True:
|
if "msg" in response and response["msg"] == True:
|
||||||
print(response["msg"])
|
print(response["msg"])
|
||||||
|
|
|
@ -13,7 +13,8 @@ from threading import Lock
|
||||||
from typing import Optional, Tuple
|
from typing import Optional, Tuple
|
||||||
|
|
||||||
import click
|
import click
|
||||||
from libretime_api_client.v1 import ApiClient
|
from libretime_api_client.v1 import ApiClient as LegacyClient
|
||||||
|
from libretime_api_client.v2 import ApiClient
|
||||||
from libretime_shared.cli import cli_config_options, 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.config import DEFAULT_ENV_PREFIX
|
||||||
from libretime_shared.logging import level_from_name, setup_logger
|
from libretime_shared.logging import level_from_name, setup_logger
|
||||||
|
@ -32,14 +33,14 @@ from .timeout import ls_timeout
|
||||||
|
|
||||||
|
|
||||||
class Global:
|
class Global:
|
||||||
def __init__(self, api_client):
|
def __init__(self, legacy_client: LegacyClient):
|
||||||
self.api_client = api_client
|
self.legacy_client = legacy_client
|
||||||
|
|
||||||
def selfcheck(self):
|
def selfcheck(self):
|
||||||
return self.api_client.is_server_compatible()
|
return self.legacy_client.is_server_compatible()
|
||||||
|
|
||||||
def test_api(self):
|
def test_api(self):
|
||||||
self.api_client.test()
|
self.legacy_client.test()
|
||||||
|
|
||||||
|
|
||||||
def keyboardInterruptHandler(signum, frame):
|
def keyboardInterruptHandler(signum, frame):
|
||||||
|
@ -127,8 +128,9 @@ def cli(log_level: str, log_filepath: Optional[Path], config_filepath: Optional[
|
||||||
|
|
||||||
signal.signal(signal.SIGINT, keyboardInterruptHandler)
|
signal.signal(signal.SIGINT, keyboardInterruptHandler)
|
||||||
|
|
||||||
|
legacy_client = LegacyClient()
|
||||||
api_client = ApiClient()
|
api_client = ApiClient()
|
||||||
g = Global(api_client)
|
g = Global(legacy_client)
|
||||||
|
|
||||||
while not g.selfcheck():
|
while not g.selfcheck():
|
||||||
time.sleep(5)
|
time.sleep(5)
|
||||||
|
@ -136,7 +138,7 @@ def cli(log_level: str, log_filepath: Optional[Path], config_filepath: Optional[
|
||||||
success = False
|
success = False
|
||||||
while not success:
|
while not success:
|
||||||
try:
|
try:
|
||||||
api_client.register_component("pypo")
|
legacy_client.register_component("pypo")
|
||||||
success = True
|
success = True
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
logger.error(str(e))
|
logger.error(str(e))
|
||||||
|
@ -166,7 +168,7 @@ def cli(log_level: str, log_filepath: Optional[Path], config_filepath: Optional[
|
||||||
pmh.daemon = True
|
pmh.daemon = True
|
||||||
pmh.start()
|
pmh.start()
|
||||||
|
|
||||||
pfile = PypoFile(media_q)
|
pfile = PypoFile(media_q, api_client)
|
||||||
pfile.daemon = True
|
pfile.daemon = True
|
||||||
pfile.start()
|
pfile.start()
|
||||||
|
|
||||||
|
@ -177,6 +179,8 @@ def cli(log_level: str, log_filepath: Optional[Path], config_filepath: Optional[
|
||||||
telnet_lock,
|
telnet_lock,
|
||||||
pypo_liquidsoap,
|
pypo_liquidsoap,
|
||||||
config,
|
config,
|
||||||
|
api_client,
|
||||||
|
legacy_client,
|
||||||
)
|
)
|
||||||
pf.daemon = True
|
pf.daemon = True
|
||||||
pf.start()
|
pf.start()
|
||||||
|
@ -185,11 +189,11 @@ def cli(log_level: str, log_filepath: Optional[Path], config_filepath: Optional[
|
||||||
pp.daemon = True
|
pp.daemon = True
|
||||||
pp.start()
|
pp.start()
|
||||||
|
|
||||||
recorder = Recorder(recorder_q, config)
|
recorder = Recorder(recorder_q, config, legacy_client)
|
||||||
recorder.daemon = True
|
recorder.daemon = True
|
||||||
recorder.start()
|
recorder.start()
|
||||||
|
|
||||||
stat = ListenerStat(config)
|
stat = ListenerStat(config, legacy_client)
|
||||||
stat.daemon = True
|
stat.daemon = True
|
||||||
stat.start()
|
stat.start()
|
||||||
|
|
||||||
|
|
|
@ -16,7 +16,7 @@ from pathlib import Path
|
||||||
from typing import Optional
|
from typing import Optional
|
||||||
|
|
||||||
import click
|
import click
|
||||||
from libretime_api_client.v1 import ApiClient
|
from libretime_api_client.v1 import ApiClient as LegacyClient
|
||||||
from libretime_shared.cli import cli_logging_options
|
from libretime_shared.cli import cli_logging_options
|
||||||
from libretime_shared.config import DEFAULT_ENV_PREFIX
|
from libretime_shared.config import DEFAULT_ENV_PREFIX
|
||||||
from libretime_shared.logging import level_from_name, setup_logger
|
from libretime_shared.logging import level_from_name, setup_logger
|
||||||
|
@ -24,7 +24,7 @@ from loguru import logger
|
||||||
|
|
||||||
|
|
||||||
def api_client():
|
def api_client():
|
||||||
return ApiClient(logger=logger)
|
return LegacyClient(logger=logger)
|
||||||
|
|
||||||
|
|
||||||
@click.group(context_settings={"auto_envvar_prefix": DEFAULT_ENV_PREFIX})
|
@click.group(context_settings={"auto_envvar_prefix": DEFAULT_ENV_PREFIX})
|
||||||
|
|
|
@ -12,8 +12,8 @@ from queue import Empty
|
||||||
from subprocess import PIPE, Popen
|
from subprocess import PIPE, Popen
|
||||||
from threading import Thread, Timer
|
from threading import Thread, Timer
|
||||||
|
|
||||||
from libretime_api_client.v1 import ApiClientV1
|
from libretime_api_client.v1 import ApiClient as LegacyClient
|
||||||
from libretime_api_client.v2 import ApiClientV2
|
from libretime_api_client.v2 import ApiClient
|
||||||
from loguru import logger
|
from loguru import logger
|
||||||
|
|
||||||
from ..config import CACHE_DIR, POLL_INTERVAL, Config
|
from ..config import CACHE_DIR, POLL_INTERVAL, Config
|
||||||
|
@ -38,14 +38,16 @@ class PypoFetch(Thread):
|
||||||
telnet_lock,
|
telnet_lock,
|
||||||
pypo_liquidsoap,
|
pypo_liquidsoap,
|
||||||
config: Config,
|
config: Config,
|
||||||
|
api_client: ApiClient,
|
||||||
|
legacy_client: LegacyClient,
|
||||||
):
|
):
|
||||||
Thread.__init__(self)
|
Thread.__init__(self)
|
||||||
|
|
||||||
# Hacky...
|
# Hacky...
|
||||||
PypoFetch.ref = self
|
PypoFetch.ref = self
|
||||||
|
|
||||||
self.v1_api_client = ApiClientV1()
|
self.api_client = api_client
|
||||||
self.api_client = ApiClientV2()
|
self.legacy_client = legacy_client
|
||||||
self.fetch_queue = pypoFetch_q
|
self.fetch_queue = pypoFetch_q
|
||||||
self.push_queue = pypoPush_q
|
self.push_queue = pypoPush_q
|
||||||
self.media_prepare_queue = media_q
|
self.media_prepare_queue = media_q
|
||||||
|
@ -143,7 +145,7 @@ class PypoFetch(Thread):
|
||||||
def set_bootstrap_variables(self):
|
def set_bootstrap_variables(self):
|
||||||
logger.debug("Getting information needed on bootstrap from Airtime")
|
logger.debug("Getting information needed on bootstrap from Airtime")
|
||||||
try:
|
try:
|
||||||
info = self.v1_api_client.get_bootstrap_info()
|
info = self.legacy_client.get_bootstrap_info()
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
logger.exception("Unable to get bootstrap info.. Exiting pypo...")
|
logger.exception("Unable to get bootstrap info.. Exiting pypo...")
|
||||||
|
|
||||||
|
@ -257,7 +259,7 @@ class PypoFetch(Thread):
|
||||||
stream_id = info[0]
|
stream_id = info[0]
|
||||||
status = info[1]
|
status = info[1]
|
||||||
if status == "true":
|
if status == "true":
|
||||||
self.v1_api_client.notify_liquidsoap_status(
|
self.legacy_client.notify_liquidsoap_status(
|
||||||
"OK", stream_id, str(fake_time)
|
"OK", stream_id, str(fake_time)
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -470,7 +472,7 @@ class PypoFetch(Thread):
|
||||||
# push metadata to TuneIn. We have to do this because TuneIn turns
|
# push metadata to TuneIn. We have to do this because TuneIn turns
|
||||||
# off metadata if it does not receive a request every 5 minutes.
|
# off metadata if it does not receive a request every 5 minutes.
|
||||||
def update_metadata_on_tunein(self):
|
def update_metadata_on_tunein(self):
|
||||||
self.v1_api_client.update_metadata_on_tunein()
|
self.legacy_client.update_metadata_on_tunein()
|
||||||
Timer(120, self.update_metadata_on_tunein).start()
|
Timer(120, self.update_metadata_on_tunein).start()
|
||||||
|
|
||||||
def main(self):
|
def main(self):
|
||||||
|
|
|
@ -12,11 +12,11 @@ from requests.exceptions import ConnectionError, Timeout
|
||||||
|
|
||||||
|
|
||||||
class PypoFile(Thread):
|
class PypoFile(Thread):
|
||||||
def __init__(self, schedule_queue):
|
def __init__(self, schedule_queue, api_client: ApiClient):
|
||||||
Thread.__init__(self)
|
Thread.__init__(self)
|
||||||
self.media_queue = schedule_queue
|
self.media_queue = schedule_queue
|
||||||
self.media = None
|
self.media = None
|
||||||
self.api_client = ApiClient()
|
self.api_client = api_client
|
||||||
|
|
||||||
def copy_file(self, media_item):
|
def copy_file(self, media_item):
|
||||||
"""
|
"""
|
||||||
|
|
|
@ -6,7 +6,6 @@ from datetime import datetime
|
||||||
from queue import Queue
|
from queue import Queue
|
||||||
from threading import Thread
|
from threading import Thread
|
||||||
|
|
||||||
from libretime_api_client.v1 import ApiClient
|
|
||||||
from loguru import logger
|
from loguru import logger
|
||||||
|
|
||||||
from ..config import PUSH_INTERVAL, Config
|
from ..config import PUSH_INTERVAL, Config
|
||||||
|
@ -25,7 +24,6 @@ def is_file(media_item):
|
||||||
class PypoPush(Thread):
|
class PypoPush(Thread):
|
||||||
def __init__(self, q, telnet_lock, pypo_liquidsoap, config: Config):
|
def __init__(self, q, telnet_lock, pypo_liquidsoap, config: Config):
|
||||||
Thread.__init__(self)
|
Thread.__init__(self)
|
||||||
self.api_client = ApiClient()
|
|
||||||
self.queue = q
|
self.queue = q
|
||||||
|
|
||||||
self.telnet_lock = telnet_lock
|
self.telnet_lock = telnet_lock
|
||||||
|
|
|
@ -12,7 +12,7 @@ from threading import Thread
|
||||||
from zoneinfo import ZoneInfo
|
from zoneinfo import ZoneInfo
|
||||||
|
|
||||||
import mutagen
|
import mutagen
|
||||||
from libretime_api_client.v1 import ApiClient
|
from libretime_api_client.v1 import ApiClient as LegacyClient
|
||||||
from loguru import logger
|
from loguru import logger
|
||||||
|
|
||||||
from libretime_playout.config import PUSH_INTERVAL, RECORD_DIR, Config
|
from libretime_playout.config import PUSH_INTERVAL, RECORD_DIR, Config
|
||||||
|
@ -44,9 +44,10 @@ class ShowRecorder(Thread):
|
||||||
filelength,
|
filelength,
|
||||||
start_time,
|
start_time,
|
||||||
config: Config,
|
config: Config,
|
||||||
|
legacy_client: LegacyClient,
|
||||||
):
|
):
|
||||||
Thread.__init__(self)
|
Thread.__init__(self)
|
||||||
self.api_client = ApiClient()
|
self.legacy_client = legacy_client
|
||||||
self.config = config
|
self.config = config
|
||||||
self.filelength = filelength
|
self.filelength = filelength
|
||||||
self.start_time = start_time
|
self.start_time = start_time
|
||||||
|
@ -120,7 +121,7 @@ class ShowRecorder(Thread):
|
||||||
"show_instance": self.show_instance,
|
"show_instance": self.show_instance,
|
||||||
}
|
}
|
||||||
|
|
||||||
self.api_client.upload_recorded_show(files, self.show_instance)
|
self.legacy_client.upload_recorded_show(files, self.show_instance)
|
||||||
|
|
||||||
def set_metadata_and_save(self, filepath):
|
def set_metadata_and_save(self, filepath):
|
||||||
"""
|
"""
|
||||||
|
@ -168,9 +169,9 @@ class ShowRecorder(Thread):
|
||||||
|
|
||||||
|
|
||||||
class Recorder(Thread):
|
class Recorder(Thread):
|
||||||
def __init__(self, q, config: Config):
|
def __init__(self, q, config: Config, legacy_client: LegacyClient):
|
||||||
Thread.__init__(self)
|
Thread.__init__(self)
|
||||||
self.api_client = ApiClient()
|
self.legacy_client = legacy_client
|
||||||
self.config = config
|
self.config = config
|
||||||
self.sr = None
|
self.sr = None
|
||||||
self.shows_to_record = {}
|
self.shows_to_record = {}
|
||||||
|
@ -182,7 +183,7 @@ class Recorder(Thread):
|
||||||
success = False
|
success = False
|
||||||
while not success:
|
while not success:
|
||||||
try:
|
try:
|
||||||
self.api_client.register_component("show-recorder")
|
self.legacy_client.register_component("show-recorder")
|
||||||
success = True
|
success = True
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
logger.error(str(e))
|
logger.error(str(e))
|
||||||
|
@ -304,6 +305,7 @@ class Recorder(Thread):
|
||||||
show_length_seconds,
|
show_length_seconds,
|
||||||
start_time_formatted,
|
start_time_formatted,
|
||||||
self.config,
|
self.config,
|
||||||
|
self.legacy_client,
|
||||||
)
|
)
|
||||||
self.sr.start()
|
self.sr.start()
|
||||||
break
|
break
|
||||||
|
@ -327,7 +329,7 @@ class Recorder(Thread):
|
||||||
# Bootstrap: since we are just starting up, we need to grab the
|
# Bootstrap: since we are just starting up, we need to grab the
|
||||||
# most recent schedule. After that we can just wait for updates.
|
# most recent schedule. After that we can just wait for updates.
|
||||||
try:
|
try:
|
||||||
temp = self.api_client.get_shows_to_record()
|
temp = self.legacy_client.get_shows_to_record()
|
||||||
if temp is not None:
|
if temp is not None:
|
||||||
self.process_recorder_schedule(temp)
|
self.process_recorder_schedule(temp)
|
||||||
logger.info("Bootstrap recorder schedule received: %s", temp)
|
logger.info("Bootstrap recorder schedule received: %s", temp)
|
||||||
|
@ -345,7 +347,7 @@ class Recorder(Thread):
|
||||||
self.loops = 0
|
self.loops = 0
|
||||||
# Fetch recorder schedule
|
# Fetch recorder schedule
|
||||||
try:
|
try:
|
||||||
temp = self.api_client.get_shows_to_record()
|
temp = self.legacy_client.get_shows_to_record()
|
||||||
if temp is not None:
|
if temp is not None:
|
||||||
self.process_recorder_schedule(temp)
|
self.process_recorder_schedule(temp)
|
||||||
logger.info("updated recorder schedule received: %s", temp)
|
logger.info("updated recorder schedule received: %s", temp)
|
||||||
|
|
|
@ -7,7 +7,7 @@ from datetime import datetime
|
||||||
from threading import Thread
|
from threading import Thread
|
||||||
|
|
||||||
import defusedxml.minidom
|
import defusedxml.minidom
|
||||||
from libretime_api_client.v1 import ApiClient
|
from libretime_api_client.v1 import ApiClient as LegacyClient
|
||||||
from loguru import logger
|
from loguru import logger
|
||||||
|
|
||||||
from .config import Config
|
from .config import Config
|
||||||
|
@ -17,10 +17,10 @@ class ListenerStat(Thread):
|
||||||
|
|
||||||
HTTP_REQUEST_TIMEOUT = 30 # 30 second HTTP request timeout
|
HTTP_REQUEST_TIMEOUT = 30 # 30 second HTTP request timeout
|
||||||
|
|
||||||
def __init__(self, config: Config):
|
def __init__(self, config: Config, legacy_client: LegacyClient):
|
||||||
Thread.__init__(self)
|
Thread.__init__(self)
|
||||||
self.config = config
|
self.config = config
|
||||||
self.api_client = ApiClient()
|
self.legacy_client = legacy_client
|
||||||
|
|
||||||
def get_node_text(self, nodelist):
|
def get_node_text(self, nodelist):
|
||||||
rc = []
|
rc = []
|
||||||
|
@ -31,7 +31,7 @@ class ListenerStat(Thread):
|
||||||
|
|
||||||
def get_stream_parameters(self):
|
def get_stream_parameters(self):
|
||||||
# [{"user":"", "password":"", "url":"", "port":""},{},{}]
|
# [{"user":"", "password":"", "url":"", "port":""},{},{}]
|
||||||
return self.api_client.get_stream_parameters()
|
return self.legacy_client.get_stream_parameters()
|
||||||
|
|
||||||
def get_stream_server_xml(self, ip, url, is_shoutcast=False):
|
def get_stream_server_xml(self, ip, url, is_shoutcast=False):
|
||||||
auth_string = "%(admin_user)s:%(admin_pass)s" % ip
|
auth_string = "%(admin_user)s:%(admin_pass)s" % ip
|
||||||
|
@ -132,12 +132,12 @@ class ListenerStat(Thread):
|
||||||
return stats
|
return stats
|
||||||
|
|
||||||
def push_stream_stats(self, stats):
|
def push_stream_stats(self, stats):
|
||||||
self.api_client.push_stream_stats(stats)
|
self.legacy_client.push_stream_stats(stats)
|
||||||
|
|
||||||
def update_listener_stat_error(self, stream_id, error):
|
def update_listener_stat_error(self, stream_id, error):
|
||||||
keyname = "%s_listener_stat_error" % stream_id
|
keyname = "%s_listener_stat_error" % stream_id
|
||||||
data = {keyname: error}
|
data = {keyname: error}
|
||||||
self.api_client.update_stream_setting_table(data)
|
self.legacy_client.update_stream_setting_table(data)
|
||||||
|
|
||||||
def run(self):
|
def run(self):
|
||||||
# Wake up every 120 seconds and gather icecast statistics. Note that we
|
# Wake up every 120 seconds and gather icecast statistics. Note that we
|
||||||
|
|
Loading…
Reference in New Issue