chore(playout): rename variables

This commit is contained in:
jo 2022-07-01 12:28:08 +02:00 committed by Kyle Robbertze
parent 2ad65bba8c
commit 97b723d0a5
2 changed files with 73 additions and 73 deletions

View File

@ -56,10 +56,10 @@ class TelnetLiquidsoap:
def __is_empty(self, queue_id): def __is_empty(self, queue_id):
return True return True
tn = self.__connect() connection = self.__connect()
msg = "%s.queue\nexit\n" % queue_id msg = "%s.queue\nexit\n" % queue_id
tn.write(msg.encode("utf-8")) connection.write(msg.encode("utf-8"))
output = tn.read_all().decode("utf-8").splitlines() output = connection.read_all().decode("utf-8").splitlines()
if len(output) == 3: if len(output) == 3:
return len(output[0]) == 0 return len(output[0]) == 0
else: else:
@ -69,15 +69,15 @@ class TelnetLiquidsoap:
def queue_clear_all(self): def queue_clear_all(self):
try: try:
self.telnet_lock.acquire() self.telnet_lock.acquire()
tn = self.__connect() connection = self.__connect()
for i in self.queues: for i in self.queues:
msg = "queues.%s_skip\n" % i msg = "queues.%s_skip\n" % i
logger.debug(msg) logger.debug(msg)
tn.write(msg.encode("utf-8")) connection.write(msg.encode("utf-8"))
tn.write(b"exit\n") connection.write(b"exit\n")
logger.debug(tn.read_all().decode("utf-8")) logger.debug(connection.read_all().decode("utf-8"))
except Exception: except Exception:
raise raise
finally: finally:
@ -87,14 +87,14 @@ class TelnetLiquidsoap:
def queue_remove(self, queue_id): def queue_remove(self, queue_id):
try: try:
self.telnet_lock.acquire() self.telnet_lock.acquire()
tn = self.__connect() connection = self.__connect()
msg = "queues.%s_skip\n" % queue_id msg = "queues.%s_skip\n" % queue_id
logger.debug(msg) logger.debug(msg)
tn.write(msg.encode("utf-8")) connection.write(msg.encode("utf-8"))
tn.write(b"exit\n") connection.write(b"exit\n")
logger.debug(tn.read_all().decode("utf-8")) logger.debug(connection.read_all().decode("utf-8"))
except Exception: except Exception:
raise raise
finally: finally:
@ -108,19 +108,19 @@ class TelnetLiquidsoap:
if not self.__is_empty(queue_id): if not self.__is_empty(queue_id):
raise QueueNotEmptyException() raise QueueNotEmptyException()
tn = self.__connect() connection = self.__connect()
annotation = create_liquidsoap_annotation(media_item) annotation = create_liquidsoap_annotation(media_item)
msg = f"{queue_id}.push {annotation}\n" msg = f"{queue_id}.push {annotation}\n"
logger.debug(msg) logger.debug(msg)
tn.write(msg.encode("utf-8")) connection.write(msg.encode("utf-8"))
show_name = media_item["show_name"] show_name = media_item["show_name"]
msg = "vars.show_name %s\n" % show_name msg = "vars.show_name %s\n" % show_name
tn.write(msg.encode("utf-8")) connection.write(msg.encode("utf-8"))
logger.debug(msg) logger.debug(msg)
tn.write(b"exit\n") connection.write(b"exit\n")
logger.debug(tn.read_all().decode("utf-8")) logger.debug(connection.read_all().decode("utf-8"))
except Exception: except Exception:
raise raise
finally: finally:
@ -130,22 +130,22 @@ class TelnetLiquidsoap:
def stop_web_stream_buffer(self): def stop_web_stream_buffer(self):
try: try:
self.telnet_lock.acquire() self.telnet_lock.acquire()
tn = telnetlib.Telnet(self.ls_host, self.ls_port) connection = telnetlib.Telnet(self.ls_host, self.ls_port)
# dynamic_source.stop http://87.230.101.24:80/top100station.mp3 # dynamic_source.stop http://87.230.101.24:80/top100station.mp3
msg = "http.stop\n" msg = "http.stop\n"
logger.debug(msg) logger.debug(msg)
tn.write(msg.encode("utf-8")) connection.write(msg.encode("utf-8"))
msg = "dynamic_source.id -1\n" msg = "dynamic_source.id -1\n"
logger.debug(msg) logger.debug(msg)
tn.write(msg.encode("utf-8")) connection.write(msg.encode("utf-8"))
tn.write(b"exit\n") connection.write(b"exit\n")
logger.debug(tn.read_all().decode("utf-8")) logger.debug(connection.read_all().decode("utf-8"))
except Exception as e: except Exception as exception:
logger.error(str(e)) logger.error(str(exception))
logger.error(traceback.format_exc()) logger.error(traceback.format_exc())
finally: finally:
self.telnet_lock.release() self.telnet_lock.release()
@ -154,18 +154,18 @@ class TelnetLiquidsoap:
def stop_web_stream_output(self): def stop_web_stream_output(self):
try: try:
self.telnet_lock.acquire() self.telnet_lock.acquire()
tn = telnetlib.Telnet(self.ls_host, self.ls_port) connection = telnetlib.Telnet(self.ls_host, self.ls_port)
# dynamic_source.stop http://87.230.101.24:80/top100station.mp3 # dynamic_source.stop http://87.230.101.24:80/top100station.mp3
msg = "dynamic_source.output_stop\n" msg = "dynamic_source.output_stop\n"
logger.debug(msg) logger.debug(msg)
tn.write(msg.encode("utf-8")) connection.write(msg.encode("utf-8"))
tn.write(b"exit\n") connection.write(b"exit\n")
logger.debug(tn.read_all().decode("utf-8")) logger.debug(connection.read_all().decode("utf-8"))
except Exception as e: except Exception as exception:
logger.error(str(e)) logger.error(str(exception))
logger.error(traceback.format_exc()) logger.error(traceback.format_exc())
finally: finally:
self.telnet_lock.release() self.telnet_lock.release()
@ -174,22 +174,22 @@ class TelnetLiquidsoap:
def start_web_stream(self, media_item): def start_web_stream(self, media_item):
try: try:
self.telnet_lock.acquire() self.telnet_lock.acquire()
tn = telnetlib.Telnet(self.ls_host, self.ls_port) connection = telnetlib.Telnet(self.ls_host, self.ls_port)
# TODO: DO we need this? # TODO: DO we need this?
msg = "streams.scheduled_play_start\n" msg = "streams.scheduled_play_start\n"
tn.write(msg.encode("utf-8")) connection.write(msg.encode("utf-8"))
msg = "dynamic_source.output_start\n" msg = "dynamic_source.output_start\n"
logger.debug(msg) logger.debug(msg)
tn.write(msg.encode("utf-8")) connection.write(msg.encode("utf-8"))
tn.write(b"exit\n") connection.write(b"exit\n")
logger.debug(tn.read_all().decode("utf-8")) logger.debug(connection.read_all().decode("utf-8"))
self.current_prebuffering_stream_id = None self.current_prebuffering_stream_id = None
except Exception as e: except Exception as exception:
logger.error(str(e)) logger.error(str(exception))
logger.error(traceback.format_exc()) logger.error(traceback.format_exc())
finally: finally:
self.telnet_lock.release() self.telnet_lock.release()
@ -198,22 +198,22 @@ class TelnetLiquidsoap:
def start_web_stream_buffer(self, media_item): def start_web_stream_buffer(self, media_item):
try: try:
self.telnet_lock.acquire() self.telnet_lock.acquire()
tn = telnetlib.Telnet(self.ls_host, self.ls_port) connection = telnetlib.Telnet(self.ls_host, self.ls_port)
msg = "dynamic_source.id %s\n" % media_item["row_id"] msg = "dynamic_source.id %s\n" % media_item["row_id"]
logger.debug(msg) logger.debug(msg)
tn.write(msg.encode("utf-8")) connection.write(msg.encode("utf-8"))
msg = "http.restart %s\n" % media_item["uri"] msg = "http.restart %s\n" % media_item["uri"]
logger.debug(msg) logger.debug(msg)
tn.write(msg.encode("utf-8")) connection.write(msg.encode("utf-8"))
tn.write(b"exit\n") connection.write(b"exit\n")
logger.debug(tn.read_all().decode("utf-8")) logger.debug(connection.read_all().decode("utf-8"))
self.current_prebuffering_stream_id = media_item["row_id"] self.current_prebuffering_stream_id = media_item["row_id"]
except Exception as e: except Exception as exception:
logger.error(str(e)) logger.error(str(exception))
logger.error(traceback.format_exc()) logger.error(traceback.format_exc())
finally: finally:
self.telnet_lock.release() self.telnet_lock.release()
@ -222,19 +222,19 @@ class TelnetLiquidsoap:
def get_current_stream_id(self): def get_current_stream_id(self):
try: try:
self.telnet_lock.acquire() self.telnet_lock.acquire()
tn = telnetlib.Telnet(self.ls_host, self.ls_port) connection = telnetlib.Telnet(self.ls_host, self.ls_port)
msg = "dynamic_source.get_id\n" msg = "dynamic_source.get_id\n"
logger.debug(msg) logger.debug(msg)
tn.write(msg.encode("utf-8")) connection.write(msg.encode("utf-8"))
tn.write(b"exit\n") connection.write(b"exit\n")
stream_id = tn.read_all().decode("utf-8").splitlines()[0] stream_id = connection.read_all().decode("utf-8").splitlines()[0]
logger.debug("stream_id: %s" % stream_id) logger.debug("stream_id: %s" % stream_id)
return stream_id return stream_id
except Exception as e: except Exception as exception:
logger.error(str(e)) logger.error(str(exception))
logger.error(traceback.format_exc()) logger.error(traceback.format_exc())
finally: finally:
self.telnet_lock.release() self.telnet_lock.release()
@ -250,12 +250,12 @@ class TelnetLiquidsoap:
try: try:
self.telnet_lock.acquire() self.telnet_lock.acquire()
tn = telnetlib.Telnet(self.ls_host, self.ls_port) connection = telnetlib.Telnet(self.ls_host, self.ls_port)
logger.info(command) logger.info(command)
tn.write(command.encode("utf-8")) connection.write(command.encode("utf-8"))
tn.write(b"exit\n") connection.write(b"exit\n")
tn.read_all().decode("utf-8") connection.read_all().decode("utf-8")
except Exception as e: except Exception:
logger.error(traceback.format_exc()) logger.error(traceback.format_exc())
finally: finally:
self.telnet_lock.release() self.telnet_lock.release()
@ -265,17 +265,17 @@ class TelnetLiquidsoap:
try: try:
self.telnet_lock.acquire() self.telnet_lock.acquire()
tn = telnetlib.Telnet(self.ls_host, self.ls_port) connection = telnetlib.Telnet(self.ls_host, self.ls_port)
for i in commands: for line in commands:
logger.info(i) logger.info(line)
if type(i) is str: if type(line) is str:
i = i.encode("utf-8") line = line.encode("utf-8")
tn.write(i) connection.write(line)
tn.write(b"exit\n") connection.write(b"exit\n")
tn.read_all().decode("utf-8") connection.read_all().decode("utf-8")
except Exception as e: except Exception as exception:
logger.error(str(e)) logger.error(str(exception))
logger.error(traceback.format_exc()) logger.error(traceback.format_exc())
finally: finally:
self.telnet_lock.release() self.telnet_lock.release()
@ -303,8 +303,8 @@ class DummyTelnetLiquidsoap:
self.telnet_lock = telnet_lock self.telnet_lock = telnet_lock
self.liquidsoap_mock_queues = {} self.liquidsoap_mock_queues = {}
for i in range(4): for index in range(4):
self.liquidsoap_mock_queues["s" + str(i)] = [] self.liquidsoap_mock_queues["s" + str(index)] = []
@ls_timeout @ls_timeout
def queue_push(self, queue_id, media_item): def queue_push(self, queue_id, media_item):

View File

@ -15,13 +15,13 @@ def __timeout(func, timeout_duration, default, args, kwargs):
first_attempt = True first_attempt = True
while True: while True:
it = InterruptableThread() thread = InterruptableThread()
it.start() thread.start()
if not first_attempt: if not first_attempt:
timeout_duration = timeout_duration * 2 timeout_duration = timeout_duration * 2
it.join(timeout_duration) thread.join(timeout_duration)
if it.is_alive(): if thread.is_alive():
# Restart Liquidsoap and try the command one more time. If it # Restart Liquidsoap and try the command one more time. If it
# fails again then there is something critically wrong... # fails again then there is something critically wrong...
if first_attempt: if first_attempt:
@ -30,13 +30,13 @@ def __timeout(func, timeout_duration, default, args, kwargs):
else: else:
raise Exception("Thread did not terminate") raise Exception("Thread did not terminate")
else: else:
return it.result return thread.result
first_attempt = False first_attempt = False
def ls_timeout(f, timeout=15, default=None): def ls_timeout(func, timeout=15, default=None):
def new_f(*args, **kwargs): def new_f(*args, **kwargs):
return __timeout(f, timeout, default, args, kwargs) return __timeout(func, timeout, default, args, kwargs)
return new_f return new_f