def get_common_beans(self): beans = [] cue = self.parse() if not self.is_cue_valid(): return [] for i, track in enumerate(cue.tracks): bean = FModel(text=track.performer + " - " + track.title, path=track.path) bean.artist = track.performer bean.tracknumber = i + 1 bean.title = track.title bean.album = self.cue_file.title bean.name = bean.text bean.start_sec = track.get_start_time_sec() bean.duration_sec = track.duration bean.time = convert_seconds_to_text(track.duration) bean.is_file = True try: bean.info = foobnix.util.id3_util.normalized_info(get_mutagen_audio(track.path).info, bean) except Exception, e: logging.warn(str(e) + " " + bean.path) bean.info = "" if not bean.title or not bean.artist: bean = udpate_id3(bean) beans.append(bean)
def get_full_duration (self, file): try: audio = get_mutagen_audio(file) except Exception as e: logging.warn(str(e) + " " + file) return return audio.info.length
def get_audio_tags(self, path): self.audio = get_mutagen_audio(path) for tag_name, tag_entry in zip(self.tag_names, self.tag_entries): try: if self.audio.has_key(tag_name): tag_entry.set_text(self.audio[tag_name][0]) except AttributeError: logging.warn('Can\'t get tags. This is not audio file')
def udpate_id3(bean): if bean and bean.path and os.path.isfile(bean.path): try: audio = get_mutagen_audio(bean.path) except Exception, e: logging.warn("ID3 NOT MP3" + str(e) + bean.path) return bean if audio: if isinstance(audio, MP4): if audio.has_key('\xa9ART'): bean.artist = audio["\xa9ART"][0] if audio.has_key('\xa9nam'): bean.title = audio["\xa9nam"][0] if audio.has_key('\xa9alb'): bean.album = audio["\xa9alb"][0] if audio.has_key('\xa9wrt'): bean.composer = audio["\xa9wrt"][0] if audio.has_key('trkn'): if not FC().numbering_by_order: bean.tracknumber = audio['trkn'][0] else: if audio.has_key('artist'): bean.artist = decode_cp866(audio["artist"][0]) if audio.has_key('title'): bean.title = decode_cp866(audio["title"][0]) if audio.has_key('album'): bean.album = decode_cp866(audio["album"][0]) if audio.has_key('composer'): bean.composer = decode_cp866(audio['composer'][0]) if audio.has_key('tracknumber'): if not FC().numbering_by_order: bean.tracknumber = audio["tracknumber"][0] bean.tracknumber duration_sec = bean.duration_sec if not bean.duration_sec and audio.info.length: duration_sec = int(audio.info.length) if audio.info.__dict__: bean.info = normalized_info(audio.info, bean) if bean.artist or bean.title: if bean.artist and bean.title: pass elif bean.artist: bean.title = _("Unknown title") elif bean.title: bean.artist = _("Unknown artist") bean.text = bean.artist + " - " + bean.title if bean.tracknumber: try: bean.tracknumber = int(bean.tracknumber) except: bean.tracknumber = "" bean = update_bean_from_normalized_text(bean) bean.time = convert_seconds_to_text(duration_sec)
def update_id3(bean): if bean and bean.path and os.path.isfile(bean.path): try: audio = get_mutagen_audio(bean.path) except Exception as e: logging.warn("ID3 NOT FOUND IN " + str(e) + " " + bean.path) return bean if audio: if isinstance(audio, MP4): if '\xa9ART' in audio: bean.artist = audio["\xa9ART"][0] if '\xa9nam' in audio: bean.title = audio["\xa9nam"][0] if '\xa9alb' in audio: bean.album = audio["\xa9alb"][0] if '\xa9wrt' in audio: bean.composer = audio["\xa9wrt"][0] if 'trkn' in audio: #if not FC().numbering_by_order: bean.tracknumber = audio['trkn'][0] else: if 'artist' in audio: bean.artist = correct_encoding(audio["artist"][0]) if 'title' in audio: bean.title = correct_encoding(audio["title"][0]) if 'album' in audio: bean.album = correct_encoding(audio["album"][0]) if 'composer' in audio: bean.composer = correct_encoding(audio['composer'][0]) if 'cuesheet' in audio: bean.cue = audio['cuesheet'][ 0] # correct_encoding is in cue parser if 'tracknumber' in audio: #if not FC().numbering_by_order: bean.tracknumber = audio["tracknumber"][0] if not bean.duration_sec and audio.info.length: bean.duration_sec = int(audio.info.length) if audio.info.__dict__: bean.info = normalized_info(audio.info, bean) if bean.artist or bean.title: if bean.artist and bean.title: pass elif bean.artist: bean.title = _("Unknown title") elif bean.title: bean.artist = _("Unknown artist") bean.text = bean.artist + " - " + bean.title ''' if bean.tracknumber: try: bean.tracknumber = int(bean.tracknumber) except: bean.tracknumber = "" ''' bean = update_bean_from_normalized_text(bean) bean.time = convert_seconds_to_text(bean.duration_sec) return bean
def get_audio_tags(self, paths): self.paths = paths if len(paths) == 1: for chbutton in self.check_buttons: chbutton.set_sensitive(False) else: for chbutton in self.check_buttons: chbutton.set_sensitive(True) self.audious = [] for path in paths[:]: if not path or os.path.isdir(path): self.paths.remove(path) continue audio = get_mutagen_audio(path) if not audio: try: audio.add_tags(ID3=EasyID3) except Exception as e: logging.error(e) self.decoding_cp866(audio) self.audious.append(audio) if isinstance(self.audious[0], MP4): tag_names = self.tag_mp4_names '''make author entry not sensitive because mp4 hasn't so tag''' self.tag_entries[-2].set_sensitive(False) self.check_buttons[-2].set_sensitive(False) self.labels[-2].set_sensitive(False) else: tag_names = self.tag_names for tag_name, tag_entry in zip(tag_names, self.tag_entries): tag_entry.delete_text(0, -1) try: if tag_name in self.audious[0]: tag_entry.set_text(self.audious[0][tag_name][0]) else: tag_entry.set_text('') except AttributeError: logging.warn('Can\'t get tags. This is not audio file') except TypeError as e: if isinstance(self.audious[0][tag_name][0], tuple): tag_entry.set_text(str(self.audious[0][tag_name][0]).strip('()')) else: logging.error(e) self.show_all()
def on_toggled_num(self, *a): FC().numbering_by_order = not FC().numbering_by_order number_music_tabs = self.controls.notetabs.get_n_pages() - 1 for page in xrange(number_music_tabs, -1, -1): tab_content = self.controls.notetabs.get_nth_page(page) pl_tree = tab_content.get_child() if FC().numbering_by_order: pl_tree.update_tracknumber() pl_tree.num_order.set_active(True) continue pl_tree.num_tags.set_active(True) for row in pl_tree.model: if row[pl_tree.is_file[0]]: audio = get_mutagen_audio(row[pl_tree.path[0]]) if audio and audio.has_key('tracknumber'): row[pl_tree.tracknumber[0]] = re.search('\d*', audio['tracknumber'][0]).group() if audio and audio.has_key('trkn'): row[pl_tree.tracknumber[0]] = re.search('\d*', audio["trkn"][0]).group()
def get_audio_tags(self, paths): self.paths = paths if len(paths) == 1: for chbutton in self.check_buttons: chbutton.set_sensitive(False) else: for chbutton in self.check_buttons: chbutton.set_sensitive(True) self.audious = [] for path in paths[:]: if not path or os.path.isdir(path): self.paths.remove(path) continue audio = get_mutagen_audio(path) self.decoding_cp866(audio) self.audious.append(audio) if isinstance(self.audious[0], MP4): tag_names = self.tag_mp4_names '''make author entry not sensitive because mp4 hasn't so tag''' self.tag_entries[-2].set_sensitive(False) self.check_buttons[-2].set_sensitive(False) self.labels[-2].set_sensitive(False) else: tag_names = self.tag_names for tag_name, tag_entry in zip(tag_names, self.tag_entries): tag_entry.delete_text(0, -1) try: if self.audious[0].has_key(tag_name): tag_entry.set_text(self.audious[0][tag_name][0]) else: tag_entry.set_text('') except AttributeError: logging.warn('Can\'t get tags. This is not audio file') except TypeError, e: if isinstance(self.audious[0][tag_name][0], tuple): tag_entry.set_text(str(self.audious[0][tag_name][0]).strip('()')) else: logging.error(e)
def udpate_id3(bean): if bean and bean.path and os.path.isfile(bean.path): try: audio = get_mutagen_audio(bean.path) except Exception, e: logging.warn("ID3 NOT MP3" + str(e) + bean.path) return bean if audio: if isinstance(audio, MP4): if audio.has_key('\xa9ART'): bean.artist = audio["\xa9ART"][0] if audio.has_key('\xa9nam'): bean.title = audio["\xa9nam"][0] if audio.has_key('\xa9alb'): bean.album = audio["\xa9alb"][0] else: if audio.has_key('artist'): bean.artist = decode_cp866(audio["artist"][0]) if audio.has_key('title'): bean.title = decode_cp866(audio["title"][0]) if audio.has_key('album'): bean.album = decode_cp866(audio["album"][0]) #if audio and audio.has_key('tracknumber'): bean.tracknumber = audio["tracknumber"][0] #else: #if audio and not audio.has_key('tracknumber'): duration_sec = bean.duration_sec if not bean.duration_sec: if audio and audio.info and audio.info.length: duration_sec = int(audio.info.length) if audio and audio.info: bean.info = audio.info.pprint() if bean.artist and bean.title: bean.text = bean.artist + " - " + bean.title if bean.tracknumber: try: bean.tracknumber = int(bean.tracknumber) except: bean.tracknumber = "" bean = update_bean_from_normalized_text(bean) bean.time = convert_seconds_to_text(duration_sec)
def get_audio_tags(self, paths): self.paths = paths if len(paths) == 1: for tbutton in self.toggle_buttons: tbutton.set_sensitive(False) tbutton.set_relief(gtk.RELIEF_NONE) else: for tbutton in self.toggle_buttons: tbutton.set_sensitive(True) tbutton.set_relief(gtk.RELIEF_NORMAL) self.audious = [] for path in paths: self.audious.append(get_mutagen_audio(path)) if isinstance(self.audious[0], MP4): tag_names = self.tag_mp4_names #make author entry not sensitive because mp4 hasn't so tag self.tag_entries[-2].set_sensitive(False) self.toggle_buttons[-2].set_sensitive(False) self.labels[-2].set_sensitive(False) else: tag_names = self.tag_names for tag_name, tag_entry in zip(tag_names, self.tag_entries): try: if self.audious[0].has_key(tag_name): tag_entry.set_text(self.audious[0][tag_name][0]) else: tag_entry.set_text('') except AttributeError: logging.warn('Can\'t get tags. This is not audio file') except TypeError as e: if isinstance(self.audious[0][tag_name][0], tuple): tag_entry.set_text(str(self.audious[0][tag_name][0]).strip('()')) else: logging.error(e) self.show_all()
def get_audio_tags(self, paths): self.paths = paths if len(paths) == 1: for chbutton in self.check_buttons: chbutton.set_sensitive(False) else: for chbutton in self.check_buttons: chbutton.set_sensitive(True) self.audious = [] for path in paths[:]: if not path or os.path.isdir(path): self.paths.remove(path) continue audio = get_mutagen_audio(path) if not audio: try: audio.add_tags(ID3=EasyID3) except Exception, e: logging.error(e) self.decoding_cp866(audio) self.audious.append(audio)
def get_full_duration (self, file): try: audio = get_mutagen_audio(file) except Exception, e: logging.warn(str(e) + " " + file) return
def get_full_duration (self, file): audio = get_mutagen_audio(file) return audio.info.length
def get_full_duration(self, file): audio = get_mutagen_audio(file) return audio.info.length