def set_text(self, text="", bold_text=""): text = any2unicode(text) bold_text = any2unicode(bold_text) full_text = bold_text + "\n\n" + text + "\n" self.buffer.set_text(full_text) if text: self.clear_tags(full_text) start = self.buffer.get_iter_at_offset(0) end = self.buffer.get_iter_at_offset(len(bold_text)) self.buffer.apply_tag(self.tag_bold, start, end)
def __init__(self, path): self.path = path try: self.m3u = open(any2unicode(path)) except Exception as e: logging.error(str(e)) self.m3u = None
def get_result(self, method, data, attempt_count=0): logging.debug("get_result(%s, %s, %s)" % (method, data, attempt_count)) result = self.get(method, data) result = any2unicode(result) if not result: return logging.debug("result " + result) try: object = self.to_json(result) except simplejson.JSONDecodeError, e: logging.error(e) return
def save_audio_tags(self, button, paths): def set_tags(audio, path, tag_name): if not self.store.has_key(path): self.store[path] = ["", "", "", ""] if isinstance(audio, MP4): tag_name = tag_mp4_name try: if audio.has_key(tag_name): if not tag_value: del audio[tag_name] audio.save() return audio[tag_name] = tag_value else: if tag_value: audio[tag_name] = [tag_value] audio.save() except AttributeError: logging.warn('Can\'t save tags. Perhaps' + os.path.split(path)[1] + ' is not audio file') except MP4MetadataValueError: '''for mp4 trkn is tuple''' new_tag_value = [tuple(map(int, tag_value.split(', ')))] audio[tag_name] = new_tag_value audio.save() """ ''' store changes ''' if (tag_name == "artist" or tag_name == '\xa9ART') and tag_value: self.store[path][0] = tag_value try: if audio.has_key("title"): self.store[path][1] = audio["title"][0] elif audio.has_key('\xa9nam'): self.store[path][1] = audio['\xa9nam'][0] except UnicodeDecodeError: pass elif (tag_name == "title" or tag_name == '\xa9nam') and tag_value: self.store[path][1] = tag_value try: if audio.has_key("artist"): self.store[path][0] = audio["artist"][0] elif audio.has_key('\xa9ART'): self.store[path][0] = audio['\xa9ART'] except UnicodeDecodeError: pass if (tag_name == "composer" or tag_name == '\xa9wrt') and tag_value: self.store[path][2] = tag_value if (tag_name == "album" or tag_name == '\xa9alb') and tag_value: self.store[path][3] = tag_value """ for tag_name, tag_mp4_name, tag_entry, check_button in zip(self.tag_names, self.tag_mp4_names, self.tag_entries, self.check_buttons): tag_value = tag_entry.get_text() if check_button.get_active(): for audio, path in zip(self.audious, self.paths): set_tags(audio, path, tag_name) else: set_tags(self.audious[0], self.paths[0], any2unicode(tag_name)) check_button.set_active(False) #self.apply_changes_for_rows_in_tree() self.hide() self.controls.notetabs.get_current_tree().change_rows_by_path(self.paths)