def on_message(self, bus, message): type = message.type if type == gst.MESSAGE_BUFFERING: return #logging.debug("Message type %s" % type) #logging.debug("Message %s" % message) if type == gst.MESSAGE_ERROR: err, debug = message.parse_error() logging.warn("Error: " + str(err) + str(debug) + str(err.domain) + str(err.code)) if self.error_counter > 1 and err.code != 1: self.notify_error(str(err)) self.error_counter = 0 self.state_stop() else: logging.warning("Error ocured, retry") self.error_counter += 1 self.play(self.bean) elif type in [gst.MESSAGE_STATE_CHANGED, gst.MESSAGE_STREAM_STATUS]: if (self.bean and self.bean.type == FTYPE_RADIO and message.structure.has_field("new-state") and message.structure['old-state'] == gst.STATE_READY and message.structure['new-state'] == gst.STATE_NULL): logging.info("Reconnect") self.play(self.bean) return if type == gst.MESSAGE_TAG and message.parse_tag(): self.error_counter = 0 artist = ""; title = "" if message.structure.has_field("title"): title = message.structure['title'] title = decode_cp866(title) text = title if message.structure.has_field("artist"): artist = message.structure['artist'] artist = decode_cp866(artist) text = artist + " - " + text if (self.bean.type == FTYPE_RADIO and message.structure.has_field("bitrate")): text = text + " (bitrate: " + str(message.structure['bitrate']) + ")" self.notify_title(text) elif type == gst.MESSAGE_EOS: self.error_counter = 0 logging.info("MESSAGE_EOS") self.notify_eos()
def on_message(self, bus, message): type = message.type if type == gst.MESSAGE_BUFFERING: return #logging.debug("Message type %s" % type) #logging.debug("Message %s" % message) if type in [gst.MESSAGE_STATE_CHANGED, gst.MESSAGE_STREAM_STATUS]: pass if type == gst.MESSAGE_TAG and message.parse_tag(): if message.structure.has_field("title"): title = message.structure['title'] title = decode_cp866(title) self.notify_title(title) elif type == gst.MESSAGE_EOS: logging.info("MESSAGE_EOS") self.notify_eos() elif type == gst.MESSAGE_ERROR: err, debug = message.parse_error() logging.warn("Error: " + str(err) + str(debug) + str(err.domain) + str(err.code)) if err.code != 1: self.notify_error(str(err))
def on_message(self, bus, message): type = message.type if type == gst.MESSAGE_BUFFERING: return #logging.debug("Message type %s" % type) #logging.debug("Message %s" % message) if type in [ gst.MESSAGE_STATE_CHANGED, gst.MESSAGE_STREAM_STATUS]: pass if type == gst.MESSAGE_TAG and message.parse_tag(): if message.structure.has_field("title"): title = message.structure['title'] title = decode_cp866(title) self.notify_title(title) elif type == gst.MESSAGE_EOS: logging.info("MESSAGE_EOS") self.notify_eos() elif type == gst.MESSAGE_ERROR: err, debug = message.parse_error() logging.warn("Error: " + str(err) + str(debug) + str(err.domain) + str(err.code)) if err.code != 1: self.notify_error(str(err))
def decoding_cp866(self, audio): if not audio: return if not isinstance(audio, MP4): for value, key in zip(audio.values(), audio.keys()): audio[key] = decode_cp866(value[0])