From a28960880effac3e3df0a433d786b212d35067ff Mon Sep 17 00:00:00 2001 From: Gottfried Gaisbauer <gogo@servus.at> Date: Mon, 14 May 2018 17:51:42 +0200 Subject: [PATCH] removed old comba code --- .../communication/liquidsoap/communicator.py | 700 +----------------- .../communication/liquidsoap/initthread.py | 3 +- 2 files changed, 22 insertions(+), 681 deletions(-) diff --git a/modules/communication/liquidsoap/communicator.py b/modules/communication/liquidsoap/communicator.py index 7bf92a2e..8edf8913 100644 --- a/modules/communication/liquidsoap/communicator.py +++ b/modules/communication/liquidsoap/communicator.py @@ -286,336 +286,6 @@ class LiquidSoapCommunicator(ExceptionLogger): t.start() return "LiquidSoapInitThread started!" - # ------------------------------------------------------------------------------------------ # - def all_data(self): - """ - Gibt Metadaten aller Kanäle als JSON-String an den Client zurück - @rtype: string/None - @return: Die Antwort des Liquidsoap-Servers - - """ - channels = self.__send_lqc_command__(self.client, 'list_channels') - - if not isinstance(channels, list): - self.warning('01') - self.notifyClient() - return - - data = {} - pdata = {} - - try: - self.is_intern = True - playlist_data = simplejson.loads(self.playlist_data(True)) - self.is_intern = False - except: - self.warning('01') - self.notifyClient() - return - - # Status des Playlistkanals abfragen - status = self.__send_lqc_command__(self.client, 'status', 'mixer', '0') - - states = status.split(' ') - state_data = {} - - # Die Stati in python dicts einlesen - for state in states: - item = state.split('=') - try: - state_data[item[0]] = item[1] - except: - self.warning('01') - self.notifyClient() - return - - remaining = self.__send_lqc_command__(self.client, 'playlist_remaining') - state_data['remaining'] = remaining - # Die Metadaten der Playlist - pdata['state'] = state_data - pdata['tracks'] = playlist_data - data['playlist'] = pdata - - # Servermeldungen abschalten - self.is_intern = True - # die channel queues einlesen - - for channel in channels: - data[channel] = self.channel_queue(channel, True) - # Servermeldungen einschalten - self.is_intern = False - self.success('00', data) - self.notifyClient() - - # ------------------------------------------------------------------------------------------ # - def ping(self): - """ - dem Client antworten - """ - return self.message('OK') - - # ------------------------------------------------------------------------------------------ # - def channel_insert(self, channel, uri, pos): - """ - Track in einen Channel einfuegen - @type channel: string - @param channel: Kanal - @type uri: string - @param uri: Uri - z.B. file:///my/audio/mp3 - @type pos: int - @param pos: Die Position an der eingefügt werden soll - @rtype: string/None - @return: Die Antwort des Liquidsoap-Servers - """ - message = self.__send_lqc_command__(self.client, 'insert', uri, pos, channel) - message = message.strip() - - try: - if int(message) > -1: - self.success() - return self.message(message) - except: - self.warning('01') - self.notifyClient() - - # ------------------------------------------------------------------------------------------ # - def channel_move(self, channel, fromPos, toPos): - """ - Channel-Eintrag von Position fromPos nach Position toPos verschieben - @type channel: string - @param channel: Kanal - @type fromPos: int - @param fromPos: die Position des Eintrags, der verschoben wird - @type toPos: int - @param toPos: Zielposition - @rtype: string - @return: Die Antwort des Liquidsoap-Servers - """ - message = self.__send_lqc_command__(self.client, 'get_queue', channel, 'secondary_queue') - - rids = message.strip().split(' ') - - try: - rid = rids[int(fromPos) - 1] - except: - self.warning('01') - self.notifyClient() - return - try: - target = rids[int(toPos) - 1] - except: - self.warning('01') - self.notifyClient() - return - - if rids[int(fromPos) - 1] == rids[int(toPos) - 1]: - self.warning('02') - self.notifyClient() - return - - message = self.__send_lqc_command__(self.client, 'move', rid, str(int(toPos) - 1), channel) - message = message.strip() - - if message.strip().find('OK') > -1: - self.success() - self.notifyClient() - return - else: - self.warning('03') - self.notifyClient() - - # ------------------------------------------------------------------------------------------ # - def channel_off(self, channel): - """ - Channel deaktivieren - @type channel: string - @param channel: Kanal - @rtype: string - @return: Die Antwort des Liquidsoap-Servers - """ - # internal channel name for playlist is 'common' - if channel == 'playlist': - channel = 'common' - - channels = self.__send_lqc_command__(self.client, 'list_channels', False) - - index = channels.index(channel) - message = self.__send_lqc_command__(self.client, 'deactivate', str(index)) - if message.find('selected=false'): - self.success() - else: - self.warning('01') - - self.notifyClient() - - # ------------------------------------------------------------------------------------------ # - def channel_on(self, channel): - """ - Channel aktivieren - @type channel: string - @param channel: Kanal - @rtype: string - @return: Die Antwort des Liquidsoap-Servers - """ - - # Find channels - if channel == 'playlist': - channel = 'common' - - channels = self.__send_lqc_command__(self.client, 'list_channels', False) - - index = channels.index(channel) - # a activate channel - message = self.__send_lqc_command__(self.client, 'activate', str(index)) - - if message.find('selected=true'): - self.success() - else: - self.warning('01') - - self.notifyClient() - - # ------------------------------------------------------------------------------------------ # - def channel_queue(self, channel, raw=False): - """ - Channel Queue abrufen - @type channel: string - @param channel: Kanal - @type raw: boolean - @param raw: Wenn true, Rückgabe als Python dict Object, andernfalls als JSON-String - @rtype: string/dict - @return: Der Channel Queue - """ - data = {} - - # queue will return request id's (rids) - - message = self.__send_lqc_command__(self.client, 'get_queue', channel) - - rids = message.strip().split(' ') - data['tracks'] = [] - for rid in rids: - if rid != '': - # get each rids metadata - metadata = self.__send_lqc_command__(self.client, 'getMetadata', rid) - track = self._metadata_format(metadata) - if not 'title' in track: - if 'location' in track: - track['title'] = os.path.basename(track['location']) - elif 'filename' in track: - track['title'] = os.path.basename(track['filename']) - else: - track['title'] = 'unknown' - - data['tracks'].extend([track]) - channels = self.__send_lqc_command__(self.client, 'list_channels') - - """ - now get channels state - self.lqc.status: ready=false volume=100% single=false selected=false remaining=0.00 - """ - try: - index = channels.index(channel) - status = self.__send_lqc_command__(self.client, 'status', 'mixer', str(index + 1)) - states = status.split(' ') - state_data = {} - for state in states: - item = state.split('=') - if len(item) > 1: - state_data[item[0]] = item[1] - except: - state_data = {} - self.error('01') - self.notifyClient() - return - - data['state'] = state_data - - if raw: - # return the list internal - data['state'] = state_data - return data - else: - self.success('00', data) - self.notifyClient() - - # ------------------------------------------------------------------------------------------ # - def channel_remove(self, channel, pos): - """ - Channel-Eintrag löschen - @type channel: string - @param channel: Kanal - @type pos: int - @param pos: Position des Eintrags - """ - # Es kann nur vom Secondary Queue gelöscht werden - # Falls der Track im Primary Queue gelöscht werden soll, ist ein skip nötg - - message = self.__send_lqc_command__(self.client, 'get_queue', channel, 'secondary_queue') - rids = message.strip().split(' ') - try: - rid = rids[int(pos) - 1] - except: - self.warning('02') - self.notifyClient() - return - message = self.__send_lqc_command__(self.client, 'remove', rid, channel) - if message.find('OK') > -1: - self.success() - else: - self.warning('01') - - self.notifyClient() - - # ------------------------------------------------------------------------------------------ # - def channel_seek(self, channel, duration): - """ - Im aktuell spielenden Track auf dem Kanal <channel> <duration> Sekunden "vorspulen" - @type channel: string - @param channel: Kanal - @type duration: int - @param duration: Dauer in Sekunden - """ - # Liquidsoap Kommando - data = self.__send_lqc_command__(self.client, 'seek', duration, channel) - - # Resultate prüfen - if self._check_result(data): - self.success('00', self.lq_error['value']) - else: - self.warning('01') - - self.notifyClient() - - # ------------------------------------------------------------------------------------------ # - def channel_skip(self, channel): - """ - Kanal skippen - @type channel: string - @param channel: Kanal - """ - - # Liquidsoap Kommando - channels = self.__send_lqc_command__(self.client, 'list_channels') - - foundChannel = '' - if not isinstance(channels, list): - self.error('02') - else: - for index, item in enumerate(channels): - if item == channel: - foundChannel = self.__send_lqc_command__(self.client, 'skip', 'mixer', str(index + 1)) - break - - if foundChannel.strip().find('OK') > -1: - self.success() - elif len(channels) < 1: - self.warning('01') - else: - self.error('03') - - self.notifyClient() - # ------------------------------------------------------------------------------------------ # def channel_activate(self, channel, activate): channels = self.get_all_channels() @@ -623,16 +293,12 @@ class LiquidSoapCommunicator(ExceptionLogger): try: index = channels.index(channel) if len(channel) < 1: - self.warning('02') - except: - import traceback - traceback.print_exc() - self.error('03') - - else: - message = self.__send_lqc_command__(self.client, "mixer", "select", index, activate) - return message - + self.logger.critical("Cannot activate channel. There are no channels!") + else: + message = self.__send_lqc_command__(self.client, "mixer", "select", index, activate) + return message + except Exception as e: + self.logger.critical("Ran into exception when activating channel. Reason: " + str(e)) # ------------------------------------------------------------------------------------------ # def channel_volume(self, channel, volume): @@ -649,281 +315,33 @@ class LiquidSoapCommunicator(ExceptionLogger): index = channels.index(channel) if len(channel) < 1: - self.warning(job="channel_volume", errnum="02") + self.logger.warning("Cannot set volume of channel " + channel + "! There are no channels.") else: message = self.__send_lqc_command__(self.client, "mixer", "volume", str(index), str(int(volume))) if message.find('volume=' + str(volume) + '%'): - self.success("channel_volume", errnum="00", value=str(volume)) + self.logger.debug("Set volume of channel " + channel + " to " + str(volume)) else: - self.warning("channel_volume", errnum="01") + self.logger.warning("Setting volume of channel " + channel + " gone wrong! Liquidsoap message: " + message) return message - except (AttributeError, ValueError): #(LQConnectionError, AttributeError): + except (AttributeError, ValueError) as e: #(LQConnectionError, AttributeError): self.disable_transaction(force=True) - self.error("channel_volume", errnum="03") + self.logger.critical("Ran into exception when setting volume of channel " + channel + ". Reason: " + str(e)) # ------------------------------------------------------------------------------------------ # def auraengine_state(self): state = self.__send_lqc_command__(self.client, "auraengine", "state") return state - # ------------------------------------------------------------------------------------------ # - def current_data(self): - """ - Metadaten des gespielten Tracks im JSON-Format - Beispiel: {"title": "Deserted Cities of the Heart", "filename": "/home/michel/Nas-audio/cream/the_very_best_of/17_Deserted_Cities_of_the_Heart.mp3", "source": "ch2", "on_air": "2014/07/23 23:46:37", "rid": "2"} - """ - - # Liquidsoap Kommando - message = self.__send_lqc_command__(self.client, 'currentTrack') - - rid = message.strip() - - metadata = self.__send_lqc_command__(self.client, 'getMetadata', rid) - - data = self._metadata_format(metadata) - - if data: - self.success('00', simplejson.dumps(data)) - elif rid == '': - self.warning('01') - else: - self.warning('02', rid) - - self.notifyClient() - - # ------------------------------------------------------------------------------------------ # - def get_channel_state(self, channel): - - if channel == 'playlist': - channel = 'common' - - channels = self.__send_lqc_command__(self.client, 'list_channels', False) - - index = channels.index(channel) - state_data = {} - try: - index = channels.index(channel) - status = self.__send_lqc_command__(self.client, 'status', 'mixer', str(index + 1)) - states = status.split(' ') - for state in states: - item = state.split('=') - if len(item) > 1: - state_data[item[0]] = item[1] - except: - state_data = {} - self.error('01') - self.notifyClient() - return - self.success('00', simplejson.dumps(state_data)) - self.notifyClient() - - # ------------------------------------------------------------------------------------------ # - def help(self): - """ - Gibt die Hilfe aus - """ - try: - file = open(os.path.dirname(os.path.abspath(__file__)) + '/doc/comba.hlp', 'r') - doc = file.read() - return self.message(doc) - except: - self.warning('01') - self.notifyClient() - # ------------------------------------------------------------------------------------------ # def liquidsoap_help(self): data = self.__send_lqc_command__(self.client, 'help') if not data: - self.warning('01') - else: - self.success('00', data) - self.notifyClient() - - # ------------------------------------------------------------------------------------------ # - def list_channels(self): - """ - Channels auflisten (Simple JSON) - """ - # Liquidsoap Kommando - - channels = self.__send_lqc_command__(self.client, 'list_channels') - - if not isinstance(channels, list): - self.error('02') - elif len(channels) < 1: - self.warning('01') - else: - self.success('00', channels) - - self.notifyClient() - - # ------------------------------------------------------------------------------------------ # - def playlist_data(self, raw=False): - """ - Aktuelle Playlist Daten im JSON-Format - """ - - # Liquidsoap Kommando - data = self.__send_lqc_command__(self.client, 'playlistData') - if not raw: - self.success('00', simplejson.loads(data)) - self.notifyClient() + self.logger.warning("Could not get Liquidsoap's help") else: - return data - - # ------------------------------------------------------------------------------------------ # - def playlist_flush(self): - """ - Aktuelle Playlist leeren - """ - data = self.__send_lqc_command__(self.client, 'flush') - self.success('00') - self.notifyClient() - - # ------------------------------------------------------------------------------------------ # - def playlist_insert(self, uri, pos): - """ - Track in die Playlist einfuegen - """ - data = self.__send_lqc_command__(self.client, 'insert', uri, pos) - if not self._check_result(data): - self.warning('01') - else: - self.success('00') - self.notifyClient() - - # ------------------------------------------------------------------------------------------ # - def playlist_load(self, uri): - """ - Playlist laden - @type uri: string - @param uri: Uri der Playlist - """ - try: - xml = urllib.urlopen(uri).read().decode("utf8") - - except: - try: - xml = open(uri).read().decode("utf8") - except: - self.error("01", self.lq_error["message"]) - self.notifyClient() - return - - (num, filename) = tempfile.mkstemp(suffix=".xspf") - - with codecs.open(filename, "w", encoding="utf8") as text_file: - text_file.write(xml) - - # playlist = parsexml(xml) - self.logger.critical("playlist commented out, due to removal of parsexml") - playlist = dict() - - if not isinstance(playlist, dict): - self.error("02") - self.notifyClient() - else: - self.__send_lqc_command__(self.client, "flush") - data = self.__send_lqc_command__(self.client, "loadPlaylist", filename) - - if not self._check_result(data): - self.error("01", self.lq_error["message"]) - - else: - os.remove(filename) - self._updateEventQueue(playlist) - event = {"job": "loadplaylist", "uri": uri} - self.messenger.fire_event("loadplaylist", event, "player") - self.success("00") - - self.notifyClient() - - # ------------------------------------------------------------------------------------------ # - def playlist_move(self, fromPos, toPos): - """ - Playlist-Eintrag von Position fromPos nach Position toPos verschieben - @type fromPos: int - @param fromPos: die Position des Eintrags, der verschoben wird - @type toPos: int - @param toPos: Zielposition - """ - data = self.__send_lqc_command__(self.client, "move", str(int(fromPos) + 1), str(int(toPos) + 1)) - - if not self._check_result(data): - self.warning("01") - else: - self.success("00") - - self.notifyClient() - - # ------------------------------------------------------------------------------------------ # - def playlist_pause(self): - """ - Playlist pausieren - """ - data = self.__send_lqc_command__(self.client, "pause") - - if not self._check_result(data): - self.info("01") - else: - self.success("00") - - self.notifyClient() - - # ------------------------------------------------------------------------------------------ # - def playlist_stop(self): - """ - Playlist stoppen - der Kanal wird deaktiviert - """ - # Kanal 0 (Playlist) deaktivieren - self.__send_lqc_command__(self.client, "deactivate", "0") - - data = self.__send_lqc_command__(self.client, "pause") - - if not self._check_result(data): - self.info("01") - else: - self.success("00") - - self.notifyClient() - - # ------------------------------------------------------------------------------------------ # - def playlist_play(self, when="now"): - """ - Playlist starten - @type when: string - @param when: Wenn "now" werden alle anderen Kanäle deaktiviert und geskipped - """ - # Playlist Kanal aktivieren - self.__send_lqc_command__(self.client, "activate", "0") - - if when == "now": - # immediately skip all playing channels - # and activate the playlist channel - channels = self.__send_lqc_command__(self.client, "list_channels") - if not isinstance(channels, list): - self.error("03") - elif len(channels) < 1: - self.warning("02") - else: - # xrange - for i in range(len(channels)): - status = self.__send_lqc_command__(self.client, "status", "mixer", str(i + 1)) - if "selected=true" in status: - status = self.__send_lqc_command__(self.client, "deactivate", str(i + 1)) - status = self.__send_lqc_command__(self.client, "skip", "mixer", str(i + 1)) - self.__send_lqc_command__(self.client, "activate", "0") - - # send the play command - data = self.__send_lqc_command__(self.client, "play") - if not self._check_result(data): - self.info("01") - else: - self.success("00") - - self.notifyClient() + self.logger.debug("Got Liquidsoap's help") + return data # ------------------------------------------------------------------------------------------ # def set_http_url(self, uri): @@ -939,58 +357,14 @@ class LiquidSoapCommunicator(ExceptionLogger): return self.__send_lqc_command__(self.client, "fs", "push", uri) # self.notifyClient() - # ------------------------------------------------------------------------------------------ # - def playlist_remove(self, pos): - """ - Playlist-Eintrag löschen - @type pos: int - @param pos: Position des Eintrags - """ - data = self.__send_lqc_command__(self.client, "remove", pos) - - if not self._check_result(data): - self.info("01") - else: - self.success("00") - - self.notifyClient() - - # ------------------------------------------------------------------------------------------ # - def playlist_seek(self, duration): - """ - Im aktuell spielenden Track auf dem der Playlist "vorspulen" - @type duration: int - @param duration: Dauer in Sekunden - """ - data = self.__send_lqc_command__(self.client, "seek", duration) - - # Resultate prüfen - if self._check_result(data): - self.success("00", self.lq_error["value"]) - else: - self.warning("01") - - self.notifyClient() - - # ------------------------------------------------------------------------------------------ # - def playlist_skip(self): - """ - Playlist skippen - """ - data = self.__send_lqc_command__(self.client, "skip") - - self.success("00") - - self.notifyClient() - # ------------------------------------------------------------------------------------------ # def version(self): """ get version """ data = self.__send_lqc_command__(self.client, "version") - self.success("00", data) - self.notifyClient() + self.logger.debug("Got Liquidsoap's version") + return data # ------------------------------------------------------------------------------------------ # def uptime(self): @@ -998,40 +372,8 @@ class LiquidSoapCommunicator(ExceptionLogger): get uptime """ data = self.__send_lqc_command__(self.client, "uptime") - self.success("00", data) - self.notifyClient() - - # ------------------------------------------------------------------------------------------ # - def on_air(self): - """ - get whats playing now - """ - data = self.__send_lqc_command__(self.client, "on_air") - self.success("00", data) - self.notifyClient() - - # ------------------------------------------------------------------------------------------ # - def recorder_data(self): - """ - Status-Daten des Recorders - Rückgabe-Beispiel: /var/audio/rec/2014-05-13/2014-05-13-22-00.wav,30 - Aufnahme von 30% der angegebenen Audiodatei - """ - message = self.__send_lqc_command__(self.lqcr, "recorder_data") - l = message.split(",") - data = {} - - if not isinstance(l, list): - data = {"file": "", "recorded": ""} - self.warning("01") - else: - data["file"] = l[0] - if len(l) > 1: - data["recorded"] = l[1] - else: - data["recorded"] = "" - self.success("00", data) - - self.notifyClient() + self.logger.debug("Got Liquidsoap's help") + return data # ------------------------------------------------------------------------------------------ # def __send_lqc_command__(self, lqs_instance, namespace, command, *args): @@ -1112,9 +454,9 @@ class LiquidSoapCommunicator(ExceptionLogger): except FileNotFoundError: self.disable_transaction(socket=socket, force=True) - msg = TerminalColors.RED.value + "socket file " + socket.socket_path + " not found. Is liquidsoap running?" + TerminalColors.ENDC.value - self.logger.critical(msg) - self.auramailer.send_admin_mail("[AuraEngine] CRITICAL Exception", msg) + msg = "socket file " + socket.socket_path + " not found. Is liquidsoap running?" + self.logger.critical(TerminalColors.RED.value + msg + TerminalColors.ENDC.value) + self.auramailer.send_admin_mail("CRITICAL Exception when connecting to Liquidsoap", msg) # ------------------------------------------------------------------------------------------ # def disable_transaction(self, socket=None, force=False): diff --git a/modules/communication/liquidsoap/initthread.py b/modules/communication/liquidsoap/initthread.py index 5d6fbbd5..71b0250e 100644 --- a/modules/communication/liquidsoap/initthread.py +++ b/modules/communication/liquidsoap/initthread.py @@ -49,8 +49,7 @@ class LiquidSoapInitThread(threading.Thread): self.liquidsoapcommunicator.enable_transaction() # reset channels and reload them - self.liquidsoapcommunicator.channels = None - channels = self.liquidsoapcommunicator.get_all_channels() + channels = self.liquidsoapcommunicator.reload_channels() # set every volume to 0 for c in channels: -- GitLab