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] = correct_encoding(value[0])
def on_message(self, bus, message): type = message.type struct = message.get_structure() if type == Gst.MessageType.BUFFERING: percent = message.parse_buffering() if percent < 100: if not self.buffering: logging.debug("Pausing...") self.buffering = True self.player.set_state(Gst.State.PAUSED) logging.debug("Buffering... %d" % percent) else: if self.buffering: logging.debug("Playing...") self.buffering = False self.player.set_state(Gst.State.PLAYING) return if type == Gst.MessageType.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.MessageType.STATE_CHANGED, Gst.MessageType.STREAM_STATUS]: if (self.bean and self.bean.type == FTYPE_RADIO and struct.has_field("new-state") and struct.get_enum('old-state', Gst.State) == Gst.State.READY and struct.get_enum('new-state', Gst.State) == Gst.State.NULL): logging.info("Reconnect") self.play(self.bean) return if type == Gst.MessageType.TAG and message.parse_tag(): self.error_counter = 0 if struct.has_field("taglist"): taglist = struct.get_value("taglist") title = taglist.get_string("title")[1] if not title: title = "" title = correct_encoding(title) text = title if taglist.get_string('artist')[0]: artist = taglist.get_string('artist')[1] artist = correct_encoding(artist) text = artist + " - " + text if not text: text = self.bean.path if self._is_remote() and taglist.get_string("audio-codec")[0]: text = text + " || " + taglist.get_string("audio-codec")[1] if self._is_remote() and taglist.get_uint('bitrate')[0]: text = text + " || " + str(taglist.get_uint('bitrate')[1] / 1000) + _("kbps") self.emit('bitrate-changed', taglist.get_uint('bitrate')[1]) self.notify_title(text) elif type == Gst.MessageType.EOS: self.error_counter = 0 logging.info("MESSAGE_EOS") self.notify_eos()
def parse(self): if self.embedded_cue: data = self.embedded_cue else: file = open(self.cue_path, "r") data = file.read() code = self.code_detecter(correct_encoding(data)) data = data.replace('\r\n', '\n').split('\n') title = "" performer = "" index = "00:00:00" full_file = None self.cue_file.image = get_image_by_path(self.cue_path) self.files_count = 0 for line in data: if not self.is_valid and not line.startswith(FILE): continue else: self.is_valid = True try: line = unicode(line, code) except: logging.error("There is some problems while converting in unicode") line = str(line).strip() if not line: continue if line.startswith(TITLE): title = self.get_line_value(line) if self.files_count == 0: self.cue_file.title = title if line.startswith(PERFORMER): performer = self.get_line_value(line) if self.files_count == 0: self.cue_file.performer = performer if line.startswith(FILE): self.files_count += 1 file = self.get_line_value(line) file = os.path.basename(file) if "/" in file: file = file[file.rfind("/")+1:] if "\\" in file: file = file[file.rfind("\\")+1:] dir = os.path.dirname(self.cue_path) full_file = os.path.join(dir, file) logging.debug("CUE source" + full_file) exists = os.path.exists(full_file) """if there no source cue file""" if not exists: """try to find other source""" ext = file_utils.get_file_extension(full_file) nor = full_file[:-len(ext)] logging.info("Normalized path" + nor) find_source = False for support_ext in FC().audio_formats: try_name = nor + support_ext if os.path.exists(try_name): full_file = try_name logging.debug("Found source for cue file name" + try_name) find_source = True break if not find_source: self.is_valid = False self.files_count -= 1 logging.warn("Can't find source for " + line + " Check source file name") continue if self.files_count == 0: self.cue_file.file = full_file if line.startswith(INDEX): index = self.get_line_value(line) if line.startswith("INDEX 01"): cue_track = CueTrack(title, performer, index, full_file) self.cue_file.append_track(cue_track) logging.debug("CUE file parsed " + str(self.cue_file.file)) return self.normalize()
def on_message(self, bus, message): type = message.type struct = message.get_structure() if type == Gst.MessageType.BUFFERING: percent = message.parse_buffering() if percent < 100: if not self.buffering: logging.debug("Pausing...") self.buffering = True self.player.set_state(Gst.State.PAUSED) logging.debug("Buffering... %d" % percent) else: if self.buffering: logging.debug("Playing...") self.buffering = False self.player.set_state(Gst.State.PLAYING) return if type == Gst.MessageType.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.MessageType.STATE_CHANGED, Gst.MessageType.STREAM_STATUS ]: if (self.bean and self.bean.type == FTYPE_RADIO and struct.has_field("new-state") and struct.get_enum( 'old-state', Gst.State) == Gst.State.READY and struct.get_enum('new-state', Gst.State) == Gst.State.NULL): logging.info("Reconnect") self.play(self.bean) return if type == Gst.MessageType.TAG and message.parse_tag(): self.error_counter = 0 if struct.has_field("taglist"): taglist = struct.get_value("taglist") title = taglist.get_string("title")[1] if not title: title = "" title = correct_encoding(title) text = title if taglist.get_string('artist')[0]: artist = taglist.get_string('artist')[1] artist = correct_encoding(artist) text = artist + " - " + text if not text: text = self.bean.path if self._is_remote() and taglist.get_string("audio-codec")[0]: text = text + " || " + taglist.get_string("audio-codec")[1] if self._is_remote() and taglist.get_uint('bitrate')[0]: text = text + " || " + str( taglist.get_uint('bitrate')[1] / 1000) + _("kbps") self.emit('bitrate-changed', taglist.get_uint('bitrate')[1]) self.notify_title(text) elif type == Gst.MessageType.EOS: self.error_counter = 0 logging.info("MESSAGE_EOS") self.notify_eos()