diff --git a/python_apps/pypo/telnetliquidsoap.py b/python_apps/pypo/telnetliquidsoap.py index 0cfb8709c..069a727aa 100644 --- a/python_apps/pypo/telnetliquidsoap.py +++ b/python_apps/pypo/telnetliquidsoap.py @@ -27,8 +27,16 @@ class TelnetLiquidsoap: def __connect(self): return telnetlib.Telnet(self.ls_host, self.ls_port) - def __is_empty(self, tn, queue_id): + def __is_empty(self, queue_id): return True + tn = self.__connect() + msg = '%s.queue\nexit\n' % queue_id + tn.write(msg) + output = tn.read_all().splitlines() + if len(output) == 3: + return len(output[0]) == 0 + else: + raise Exception("Unexpected list length returned: %s" % output) def queue_clear_all(self): try: @@ -67,11 +75,11 @@ class TelnetLiquidsoap: def queue_push(self, queue_id, media_item): try: self.telnet_lock.acquire() - tn = self.__connect() - if not self.__is_empty(tn, queue_id): + if not self.__is_empty(queue_id): raise QueueNotEmptyException() + tn = self.__connect() annotation = create_liquidsoap_annotation(media_item) msg = '%s.push %s\n' % (queue_id, annotation.encode('utf-8')) self.logger.debug(msg)