def callback(self, objs): if len(objs) != 1 or not isinstance(objs[0], Cluster): return cluster = objs[0] artists = set() for i, file in enumerate(cluster.files): artists.add(file.metadata["artist"]) tracks = [] for i, file in enumerate(cluster.files): try: i = int(file.metadata["tracknumber"]) except: i += 1 if len(artists) > 1: tracks.append((i, "%s. %s - %s (%s)" % ( i, file.metadata["title"], file.metadata["artist"], format_time(file.metadata.length)))) else: tracks.append((i, "%s. %s (%s)" % ( i, file.metadata["title"], format_time(file.metadata.length)))) clipboard = QtGui.QApplication.clipboard() clipboard.setText("\n".join(map(lambda x: x[1], sorted(tracks))))
def recording_to_metadata(node, m, track=None): m.length = 0 m.add_unique('musicbrainz_recordingid', node['id']) for key, value in node.items(): if not value: continue if key in _RECORDING_TO_METADATA: m[_RECORDING_TO_METADATA[key]] = value elif key == 'length': m.length = value elif key == 'artist-credit': artist_credit_to_metadata(value, m) # set tags from artists if track: for artist in value: track.append_track_artist(artist['artist']['id']) elif key == 'relations': _relations_to_metadata(value, m) elif key == 'tags' and track: add_folksonomy_tags(value, track) elif key == 'user-tags' and track: add_user_folksonomy_tags(value, track) elif key == 'isrcs': add_isrcs_to_metadata(value, m) elif key == 'video' and value: m['~video'] = '1' m['~recordingtitle'] = m['title'] m['~length'] = format_time(m.length)
def recording_to_metadata(node, m, track=None): m.length = 0 m.add_unique('musicbrainz_recordingid', node['id']) for key, value in node.items(): if not value: continue if key in _RECORDING_TO_METADATA: m[_RECORDING_TO_METADATA[key]] = value elif key == 'user-rating': m['~rating'] = value['value'] elif key == 'length': m.length = value elif key == 'artist-credit': artist_credit_to_metadata(value, m) # set tags from artists if track: for credit in value: artist = credit['artist'] artist_obj = track.append_track_artist(artist['id']) add_genres_from_node(artist, artist_obj) elif key == 'relations': _relations_to_metadata(value, m) elif key in ('genres', 'tags') and track: add_genres(value, track) elif key in ('user-genres', 'user-tags') and track: add_user_genres(value, track) elif key == 'isrcs': add_isrcs_to_metadata(value, m) elif key == 'video' and value: m['~video'] = '1' if m['title']: m['~recordingtitle'] = m['title'] if m.length: m['~length'] = format_time(m.length)
def recording_to_metadata(node, m, track=None): m.length = 0 m.add_unique('musicbrainz_recordingid', node['id']) for key, value in node.items(): if not value: continue if key in _RECORDING_TO_METADATA: m[_RECORDING_TO_METADATA[key]] = value elif key == 'length': m.length = value elif key == 'artist-credit': artist_credit_to_metadata(value, m) # set tags from artists if track: for artist in value: track.append_track_artist(artist['artist']['id']) elif key == 'relations': _relations_to_metadata(value, m) elif key == 'tags' and track: add_folksonomy_tags(value, track) elif key == 'user-tags' and track: add_user_folksonomy_tags(value, track) elif key == 'isrcs': add_isrcs_to_metadata(value, m) elif key == 'video' and value: m['~video'] = '1' if m['title']: m['~recordingtitle'] = m['title'] if m.length: m['~length'] = format_time(m.length)
def recording_to_metadata(node, track, config): m = track.metadata m.length = 0 m['musicbrainz_trackid'] = node.attribs['id'] for name, nodes in node.children.iteritems(): if not nodes: continue if name == 'title': m['title'] = nodes[0].text elif name == 'length' and nodes[0].text: m.length = int(nodes[0].text) elif name == 'disambiguation': m['~recordingcomment'] = nodes[0].text elif name == 'artist_credit': artist_credit_to_metadata(nodes[0], m, config) elif name == 'relation_list': _relations_to_metadata(nodes, m, config) elif name == 'tag_list': add_folksonomy_tags(nodes[0], track) elif name == 'user_tag_list': add_user_folksonomy_tags(nodes[0], track) elif name == 'isrc_list': add_isrcs_to_metadata(nodes[0], m) elif name == 'user_rating': m['~rating'] = nodes[0].text m['~length'] = format_time(m.length)
def column(self, column): if column == "title": if self.tracks: linked_tracks = 0 for track in self.tracks: if track.is_linked(): linked_tracks += 1 text = u"%s\u200E (%d/%d" % (self.metadata["album"], linked_tracks, len(self.tracks)) unmatched = self.get_num_unmatched_files() if unmatched: text += "; %d?" % (unmatched,) unsaved = self.get_num_unsaved_files() if unsaved: text += "; %d*" % (unsaved,) text += ungettext("; %i image", "; %i images", len(self.metadata.images)) % len(self.metadata.images) return text + ")" else: return self.metadata["album"] elif column == "~length": length = self.metadata.length if length: return format_time(length) else: return "" elif column == "artist": return self.metadata["albumartist"] else: return ""
def _saving_finished(self, result=None, error=None): old_filename = new_filename = self.filename if error is not None: self.error = str(error) self.set_state(File.ERROR, update=True) else: self.filename = new_filename = result self.base_filename = os.path.basename(new_filename) length = self.orig_metadata.length temp_info = {} for info in ('~bitrate', '~sample_rate', '~channels', '~bits_per_sample', '~format'): temp_info[info] = self.orig_metadata[info] # Data is copied from New to Original because New may be a subclass to handle id3v23 if config.setting["clear_existing_tags"]: self.orig_metadata.copy(self.metadata) else: self.orig_metadata.update(self.metadata) self.orig_metadata.length = length self.orig_metadata['~length'] = format_time(length) for k, v in temp_info.items(): self.orig_metadata[k] = v self.error = None self.clear_pending() self._add_path_to_metadata(self.orig_metadata) del self.tagger.files[old_filename] self.tagger.files[new_filename] = self
def format_file_info(file_): info = [] info.append((_('Filename:'), file_.filename)) if '~format' in file_.orig_metadata: info.append((_('Format:'), file_.orig_metadata['~format'])) try: size = os.path.getsize(encode_filename(file_.filename)) sizestr = "%s (%s)" % (bytes1human.decimal(size), bytes2human.binary(size)) info.append((_('Size:'), sizestr)) except BaseException: pass if file_.orig_metadata.length: info.append((_('Length:'), format_time(file_.orig_metadata.length))) if '~bitrate' in file_.orig_metadata: info.append((_('Bitrate:'), '%s kbps' % file_.orig_metadata['~bitrate'])) if '~sample_rate' in file_.orig_metadata: info.append((_('Sample rate:'), '%s Hz' % file_.orig_metadata['~sample_rate'])) if '~bits_per_sample' in file_.orig_metadata: info.append((_('Bits per sample:'), str(file_.orig_metadata['~bits_per_sample']))) if '~channels' in file_.orig_metadata: ch = file_.orig_metadata['~channels'] if ch == '1': ch = _('Mono') elif ch == '2': ch = _('Stereo') info.append((_('Channels:'), ch)) return '<br/>'.join(map(lambda i: '<b>%s</b> %s' % (htmlescape(i[0]), htmlescape(i[1])), info))
def recording_to_metadata(node, track): m = track.metadata m.length = 0 m.add_unique('musicbrainz_recordingid', node.id) for name, nodes in node.children.iteritems(): if not nodes: continue if name == 'title': m['title'] = nodes[0].text m['~recordingtitle'] = nodes[0].text elif name == 'length' and nodes[0].text: m.length = int(nodes[0].text) elif name == 'disambiguation': m['~recordingcomment'] = nodes[0].text elif name == 'artist_credit': artist_credit_to_metadata(nodes[0], m) elif name == 'relation_list': _relations_to_metadata(nodes, m) elif name == 'tag_list': add_folksonomy_tags(nodes[0], track) elif name == 'user_tag_list': add_user_folksonomy_tags(nodes[0], track) elif name == 'isrc_list': add_isrcs_to_metadata(nodes[0], m) elif name == 'user_rating': m['~rating'] = nodes[0].text elif name == 'video' and nodes[0].text == 'true': m['~video'] = '1' m['~length'] = format_time(m.length)
def _saving_finished(self, result=None, error=None): old_filename = new_filename = self.filename if error is not None: self.error = str(error) self.set_state(File.ERROR, update=True) else: self.filename = new_filename = result self.base_filename = os.path.basename(new_filename) length = self.orig_metadata.length temp_info = {} for info in ('~bitrate', '~sample_rate', '~channels', '~bits_per_sample', '~format'): temp_info[info] = self.orig_metadata[info] # Data is copied from New to Original because New may be a subclass to handle id3v23 if config.setting["clear_existing_tags"]: self.orig_metadata.copy(self.new_metadata) else: self.orig_metadata.update(self.new_metadata) self.orig_metadata.length = length self.orig_metadata['~length'] = format_time(length) for k, v in temp_info.items(): self.orig_metadata[k] = v self.error = None self.clear_pending() self._add_path_to_metadata(self.orig_metadata) del self.tagger.files[old_filename] self.tagger.files[new_filename] = self
def _copy_loaded_metadata(self, metadata, postprocessors=None): metadata['~length'] = format_time(metadata.length) if postprocessors: for processor in postprocessors: processor(metadata) self.orig_metadata = metadata self.metadata.copy(metadata)
def _display_info_tab(self): file = self.obj info = [] info.append((_('Filename:'), file.filename)) if '~format' in file.orig_metadata: info.append((_('Format:'), file.orig_metadata['~format'])) try: size = os.path.getsize(encode_filename(file.filename)) sizestr = "%s (%s)" % (bytes2human.decimal(size), bytes2human.binary(size)) info.append((_('Size:'), sizestr)) except: pass if file.orig_metadata.length: info.append((_('Length:'), format_time(file.orig_metadata.length))) if '~bitrate' in file.orig_metadata: info.append((_('Bitrate:'), '%s kbps' % file.orig_metadata['~bitrate'])) if '~sample_rate' in file.orig_metadata: info.append((_('Sample rate:'), '%s Hz' % file.orig_metadata['~sample_rate'])) if '~bits_per_sample' in file.orig_metadata: info.append((_('Bits per sample:'), str(file.orig_metadata['~bits_per_sample']))) if '~channels' in file.orig_metadata: ch = file.orig_metadata['~channels'] if ch == 1: ch = _('Mono') elif ch == 2: ch = _('Stereo') else: ch = str(ch) info.append((_('Channels:'), ch)) text = '<br/>'.join(map(lambda i: '<b>%s</b><br/>%s' % (cgi.escape(i[0]), cgi.escape(i[1])), info)) self.ui.info.setText(text)
def _saving_finished(self, next, result=None, error=None): old_filename = new_filename = self.filename if error is not None: self.error = str(error) self.set_state(File.ERROR, update=True) else: self.filename = new_filename = result self.base_filename = os.path.basename(new_filename) length = self.orig_metadata.length temp_info = {} for info in ('~bitrate', '~sample_rate', '~channels', '~bits_per_sample', '~format'): temp_info[info] = self.orig_metadata[info] if self.config.setting["clear_existing_tags"]: self.orig_metadata.copy(self.metadata) else: self.orig_metadata.update(self.metadata) self.orig_metadata.length = length self.orig_metadata['~length'] = format_time(length) for k, v in temp_info.items(): self.orig_metadata[k] = v self.error = None self.clear_pending() self._add_path_to_metadata(self.orig_metadata) return self, old_filename, new_filename
def column(self, column): if column == 'title': if self.tracks: linked_tracks = 0 for track in self.tracks: if track.is_linked(): linked_tracks+=1 text = u'%s\u200E (%d/%d' % (self.metadata['album'], linked_tracks, len(self.tracks)) unmatched = self.get_num_unmatched_files() if unmatched: text += '; %d?' % (unmatched,) unsaved = self.get_num_unsaved_files() if unsaved: text += '; %d*' % (unsaved,) return text + ')' else: return self.metadata['album'] elif column == '~length': length = self.metadata.length if length: return format_time(length) else: return '' elif column == 'artist': return self.metadata['albumartist'] else: return ''
def recording_to_metadata(node, m, track=None): m.length = 0 m.add_unique('musicbrainz_recordingid', node['id']) for key, value in _node_skip_empty_iter(node): if key in _RECORDING_TO_METADATA: m[_RECORDING_TO_METADATA[key]] = value elif key == 'user-rating': m['~rating'] = value['value'] elif key == 'length': m.length = value elif key == 'artist-credit': artist_credit_to_metadata(value, m) # set tags from artists if track: for credit in value: artist = credit['artist'] artist_obj = track.append_track_artist(artist['id']) add_genres_from_node(artist, artist_obj) elif key == 'relations': _relations_to_metadata(value, m) elif track and key in {'genres', 'tags'}: add_genres(value, track) elif track and key in {'user-genres', 'user-tags'}: add_user_genres(value, track) elif key == 'isrcs': add_isrcs_to_metadata(value, m) elif key == 'video' and value: m['~video'] = '1' if m['title']: m['~recordingtitle'] = m['title'] if m.length: m['~length'] = format_time(m.length) if 'instrumental' in m.getall('~performance_attributes'): m.unset('lyricist') m['language'] = 'zxx'
def format_file_info(file_): info = [] info.append((_('Filename:'), file_.filename)) if '~format' in file_.orig_metadata: info.append((_('Format:'), file_.orig_metadata['~format'])) try: size = os.path.getsize(encode_filename(file_.filename)) sizestr = "%s (%s)" % (bytes2human.decimal(size), bytes2human.binary(size)) info.append((_('Size:'), sizestr)) except BaseException: pass if file_.orig_metadata.length: info.append((_('Length:'), format_time(file_.orig_metadata.length))) if '~bitrate' in file_.orig_metadata: info.append( (_('Bitrate:'), '%s kbps' % file_.orig_metadata['~bitrate'])) if '~sample_rate' in file_.orig_metadata: info.append( (_('Sample rate:'), '%s Hz' % file_.orig_metadata['~sample_rate'])) if '~bits_per_sample' in file_.orig_metadata: info.append((_('Bits per sample:'), str(file_.orig_metadata['~bits_per_sample']))) if '~channels' in file_.orig_metadata: ch = file_.orig_metadata['~channels'] if ch == '1': ch = _('Mono') elif ch == '2': ch = _('Stereo') info.append((_('Channels:'), ch)) return '<br/>'.join( map(lambda i: '<b>%s</b> %s' % (htmlescape(i[0]), htmlescape(i[1])), info))
def column(self, column): if column == 'title': if self.status is not None: title = self.status else: title = self.metadata['album'] if self.tracks: linked_tracks = 0 for track in self.tracks: if track.is_linked(): linked_tracks += 1 text = u'%s\u200E (%d/%d' % (title, linked_tracks, len(self.tracks)) unmatched = self.get_num_unmatched_files() if unmatched: text += '; %d?' % (unmatched,) unsaved = self.get_num_unsaved_files() if unsaved: text += '; %d*' % (unsaved,) text += ungettext("; %i image", "; %i images", len(self.metadata.images)) % len(self.metadata.images) return text + ')' else: return title elif column == '~length': length = self.metadata.length if length: return format_time(length) else: return '' elif column == 'artist': return self.metadata['albumartist'] else: return ''
def _display_info_tab(self): file = self.obj info = [] info.append((_('Filename:'), file.filename)) if '~format' in file.orig_metadata: info.append((_('Format:'), file.orig_metadata['~format'])) try: size = os.path.getsize(encode_filename(file.filename)) if size < 1024: size = '%d B' % size elif size < 1024 * 1024: size = '%0.1f kB' % (size / 1024.0) else: size = '%0.1f MB' % (size / 1024.0 / 1024.0) info.append((_('Size:'), size)) except: pass if file.orig_metadata.length: info.append((_('Length:'), format_time(file.orig_metadata.length))) if '~bitrate' in file.orig_metadata: info.append((_('Bitrate:'), '%s kbps' % file.orig_metadata['~bitrate'])) if '~sample_rate' in file.orig_metadata: info.append((_('Sample rate:'), '%s Hz' % file.orig_metadata['~sample_rate'])) if '~bits_per_sample' in file.orig_metadata: info.append((_('Bits per sample:'), str(file.orig_metadata['~bits_per_sample']))) if '~channels' in file.orig_metadata: ch = file.orig_metadata['~channels'] if ch == 1: ch = _('Mono') elif ch == 2: ch = _('Stereo') else: ch = str(ch) info.append((_('Channels:'), ch)) text = '<br/>'.join(map(lambda i: '<b>%s</b><br/>%s' % i, info)) self.ui.info.setText(text)
def column(self, column): if column == 'title': if self.tracks: linked_tracks = 0 for track in self.tracks: if track.is_linked(): linked_tracks += 1 text = u'%s\u200E (%d/%d' % (self.metadata['album'], linked_tracks, len(self.tracks)) unmatched = self.get_num_unmatched_files() if unmatched: text += '; %d?' % (unmatched, ) unsaved = self.get_num_unsaved_files() if unsaved: text += '; %d*' % (unsaved, ) return text + ')' else: return self.metadata['album'] elif column == '~length': length = self.metadata.length if length: return format_time(length) else: return '' elif column == 'artist': return self.metadata['albumartist'] else: return ''
def callback(self, objs): if len(objs) != 1 or not isinstance(objs[0], Cluster): return cluster = objs[0] artists = set() for i, file in enumerate(cluster.files): artists.add(file.metadata["artist"]) url = "http://musicbrainz.org/cdi/enter.html" if len(artists) > 1: url += "?hasmultipletrackartists=1&artistid=1" else: url += "?hasmultipletrackartists=0&artistid=2" url += "&artistedit=1&artistname=%s" % QtCore.QUrl.toPercentEncoding(cluster.metadata["artist"]) url += "&releasename=%s" % QtCore.QUrl.toPercentEncoding(cluster.metadata["album"]) tracks = 0 for i, file in enumerate(cluster.files): try: i = int(file.metadata["tracknumber"]) - 1 except: pass tracks = max(tracks, i + 1) url += "&track%d=%s" % (i, QtCore.QUrl.toPercentEncoding(file.metadata["title"])) url += "&tracklength%d=%s" % (i, QtCore.QUrl.toPercentEncoding(format_time(file.metadata.length))) if len(artists) > 1: url += "&tr%d_artistedit=1" % i url += "&tr%d_artistname=%s" % (i, QtCore.QUrl.toPercentEncoding(file.metadata["artist"])) url += "&tracks=%d" % tracks webbrowser2.open(url)
def recording_to_metadata(node, track, config): m = track.metadata m.length = 0 m["musicbrainz_trackid"] = node.attribs["id"] for name, nodes in node.children.iteritems(): if not nodes: continue if name == "title": m["title"] = nodes[0].text elif name == "length" and nodes[0].text: m.length = int(nodes[0].text) elif name == "disambiguation": m["~recordingcomment"] = nodes[0].text elif name == "artist_credit": artist_credit_to_metadata(nodes[0], m, config) elif name == "relation_list": _relations_to_metadata(nodes, m, config) elif name == "tag_list": add_folksonomy_tags(nodes[0], track) elif name == "user_tag_list": add_user_folksonomy_tags(nodes[0], track) elif name == "isrc_list": add_isrcs_to_metadata(nodes[0], m) elif name == "user_rating": m["~rating"] = nodes[0].text m["~length"] = format_time(m.length)
def test(self): self.assertEqual("?:??", util.format_time(0)) self.assertEqual("0:00", util.format_time(0, display_zero=True)) self.assertEqual("3:00", util.format_time(179750)) self.assertEqual("3:00", util.format_time(179500)) self.assertEqual("2:59", util.format_time(179499)) self.assertEqual("59:59", util.format_time(3599499)) self.assertEqual("1:00:00", util.format_time(3599500)) self.assertEqual("1:02:59", util.format_time(3779499))
def column(self, column): if column == 'title': return '%s (%d)' % (self.metadata['album'], self.metadata['totaltracks']) elif (column == '~length' and self.special) or column == 'album': return '' elif column == '~length': return format_time(self.metadata.length) return self.metadata[column]
def column(self, column): m = self.metadata if column == '~length': return format_time(m.length) elif column == "title" and not m["title"]: return self.base_filename else: return m[column]
def column(self, column): m = self.orig_metadata if column == '~length': return format_time(m.length), self.similarity elif column == "title" and not m["title"]: return self.base_filename, self.similarity else: return m[column], self.similarity
def _get_file_as_recording_data(file): metadata = file.metadata data = { 'edit-recording.name': metadata['title'], 'edit-recording.artist_credit.names.0.artist.name': metadata['artist'], 'edit-recording.length': format_time(file.metadata.length), } return data
def column(self, column): if self.orig_metadata: md = self.orig_metadata else: md = self.metadata if column == "~length": return format_time(md.length), self.similarity else: return md[column], self.similarity
def test(self): self.assertEqual("?:??", util.format_time(0)) self.assertEqual("3:00", util.format_time(179750)) self.assertEqual("3:00", util.format_time(179500)) self.assertEqual("2:59", util.format_time(179499)) self.assertEqual("59:59", util.format_time(3599499)) self.assertEqual("1:00:00", util.format_time(3599500)) self.assertEqual("1:02:59", util.format_time(3779499))
def column(self, column): m = self.metadata similarity = self.similarity() if column == "title": prefix = "%s-" % m["discnumber"] if m["totaldiscs"] != "1" else "" return u"%s%s %s" % (prefix, m["tracknumber"].zfill(2), m["title"]), similarity elif column == "~length": return format_time(m.length), similarity else: return m[column], similarity
def column(self, column): if column == "title": return "%s (%d)" % (self.metadata["album"], len(self.files)) elif (column == "~length" and self.special) or column == "album": return "" elif column == "~length": return format_time(self.metadata.length) elif column == "artist": return self.metadata["albumartist"] return self.metadata[column]
def column(self, column): m = self.metadata similarity = self.similarity() if column == 'title': prefix = "%s-" % m['discnumber'] if m['totaldiscs'] != "1" else "" return u"%s%s %s" % (prefix, m['tracknumber'].zfill(2), m['title']), similarity elif column == '~length': return format_time(m.length), similarity else: return m[column], similarity
def column(self, column): if column == 'title': return '%s (%d)' % (self.metadata['album'], len(self.files)) elif (column == '~length' and self.special) or column == 'album': return '' elif column == '~length': return format_time(self.metadata.length) elif column == 'artist': return self.metadata['albumartist'] return self.metadata[column]
def _copy_loaded_metadata(self, metadata): filename, _ = os.path.splitext(self.base_filename) metadata['~length'] = format_time(metadata.length) if 'title' not in metadata: metadata['title'] = filename if 'tracknumber' not in metadata: tracknumber = tracknum_from_filename(self.base_filename) if tracknumber != -1: metadata['tracknumber'] = str(tracknumber) self.orig_metadata = metadata self.metadata.copy(metadata)
def column(self, column): if column == 'title': if self.status is not None: title = self.status else: title = self.metadata['album'] if self.tracks: linked_tracks = 0 for track in self.tracks: if track.is_linked(): linked_tracks += 1 text = '%s\u200E (%d/%d' % (title, linked_tracks, len(self.tracks)) unmatched = self.get_num_unmatched_files() if unmatched: text += '; %d?' % (unmatched, ) unsaved = self.get_num_unsaved_files() if unsaved: text += '; %d*' % (unsaved, ) # CoverArt.set_metadata uses the orig_metadata.images if metadata.images is empty # in order to show existing cover art if there's no cover art for a release. So # we do the same here in order to show the number of images consistently. if self.metadata.images: metadata = self.metadata else: metadata = self.orig_metadata number_of_images = len(metadata.images) if getattr(metadata, 'has_common_images', True): text += ngettext("; %i image", "; %i images", number_of_images) % number_of_images else: text += ngettext("; %i image not in all tracks", "; %i different images among tracks", number_of_images) % number_of_images return text + ')' else: return title elif column == '~length': length = self.metadata.length if length: return format_time(length) else: return '' elif column == 'artist': return self.metadata['albumartist'] elif column == 'tracknumber': return self.metadata['~totalalbumtracks'] elif column == 'discnumber': return self.metadata['totaldiscs'] else: return self.metadata[column]
def _saving_finished(self, result=None, error=None): # Handle file removed before save # Result is None if save was skipped if ((self.state == File.REMOVED or self.tagger.stopping) and result is None): return old_filename = new_filename = self.filename if error is not None: self.state = File.ERROR self.error_append(str(error)) else: self.filename = new_filename = result self.base_filename = os.path.basename(new_filename) length = self.orig_metadata.length temp_info = {} for info in FILE_INFO_TAGS: temp_info[info] = self.orig_metadata[info] images_changed = self.orig_metadata.images != self.metadata.images # Copy new metadata to original metadata, applying format specific # conversions (e.g. for ID3v2.3) config = get_config() new_metadata = self._format_specific_copy(self.metadata, config.setting) if config.setting["clear_existing_tags"]: self.orig_metadata = new_metadata else: self.orig_metadata.update(new_metadata) # After saving deleted tags should no longer be marked deleted self.metadata.clear_deleted() self.orig_metadata.clear_deleted() self.orig_metadata.length = length self.orig_metadata['~length'] = format_time(length) self.orig_metadata.update(temp_info) self.clear_errors() self.clear_pending(signal=False) self._add_path_to_metadata(self.orig_metadata) if images_changed: self.metadata_images_changed.emit() # run post save hook run_file_post_save_processors(self) # Force update to ensure file status icon changes immediately after save self.update() if self.state != File.REMOVED: del self.tagger.files[old_filename] self.tagger.files[new_filename] = self if self.tagger.stopping: log.debug("Save of %r completed before stopping Picard", self.filename)
def column(self, column): if self.num_linked_files == 1: m = self.linked_files[0].metadata else: m = self.metadata if column == 'title': prefix = "%s-" % m['discnumber'] if m['totaldiscs'] != "1" else "" return u"%s%s %s" % (prefix, m['tracknumber'].zfill(2), m['title']) elif column == '~length': return format_time(m.length) else: return m[column]
def _saving_finished(self, result=None, error=None): # Handle file removed before save # Result is None if save was skipped if ((self.state == File.REMOVED or self.tagger.stopping) and result is None): return old_filename = new_filename = self.filename if error is not None: self.state = File.ERROR self.error_append(str(error)) else: self.filename = new_filename = result self.base_filename = os.path.basename(new_filename) length = self.orig_metadata.length temp_info = {} for info in FILE_INFO_TAGS: temp_info[info] = self.orig_metadata[info] images_changed = self.orig_metadata.images != self.new_metadata.images # Data is copied from New to Original because New may be # a subclass to handle id3v23 if config.setting["clear_existing_tags"]: self.orig_metadata.copy(self.new_metadata) else: self.orig_metadata.update(self.new_metadata) # After saving deleted tags should no longer be marked deleted self.new_metadata.clear_deleted() self.orig_metadata.clear_deleted() self.orig_metadata.length = length self.orig_metadata['~length'] = format_time(length) for k, v in temp_info.items(): self.orig_metadata[k] = v self.clear_errors() self.clear_pending(signal=False) self._add_path_to_metadata(self.orig_metadata) if images_changed: self.metadata_images_changed.emit() # run post save hook run_file_post_save_processors(self) # Force update to ensure file status icon changes immediately after save self.update() if self.state != File.REMOVED: del self.tagger.files[old_filename] self.tagger.files[new_filename] = self if self.tagger.stopping: log.debug("Save of %r completed before stopping Picard", self.filename)
def column(self, column): if column == 'title': return '%s (%d)' % (self.metadata['album'], len(self.files)) elif self.special and (column in ['~length', 'album']): return '' elif column == '~length': return format_time(self.metadata.length) elif column == 'artist': return self.metadata['albumartist'] elif column == 'tracknumber': return self.metadata['totaltracks'] elif column == 'discnumber': return self.metadata['totaldiscs'] return self.metadata[column]
def track_to_metadata(node, track): m = track.metadata recording_to_metadata(node['recording'], m, track) m.add_unique('musicbrainz_trackid', node['id']) # overwrite with data we have on the track for key, value in _node_skip_empty_iter(node): if key in _TRACK_TO_METADATA: m[_TRACK_TO_METADATA[key]] = value elif key == 'length' and value: m.length = value elif key == 'artist-credit': artist_credit_to_metadata(value, m) if m.length: m['~length'] = format_time(m.length)
def copy_value(self): item = self.currentItem() if item: column = item.column() tag = self.tag_diff.tag_names[item.row()] value = None if column == self.COLUMN_ORIG: value = self.tag_diff.orig[tag] elif column == self.COLUMN_NEW: value = self.tag_diff.new[tag] if tag == '~length': value = [format_time(value or 0), ] if value is not None: self.tagger.clipboard().setText(MULTI_VALUED_JOINER.join(value)) self.clipboard = value
def _saving_finished(self, result=None, error=None): # Handle file removed before save # Result is None if save was skipped if ((self.state == File.REMOVED or self.tagger.stopping) and result is None): return old_filename = new_filename = self.filename if error is not None: self.error = str(error) self.state = File.ERROR else: self.filename = new_filename = result self.base_filename = os.path.basename(new_filename) length = self.orig_metadata.length temp_info = {} for info in ('~bitrate', '~sample_rate', '~channels', '~bits_per_sample', '~format'): temp_info[info] = self.orig_metadata[info] # Data is copied from New to Original because New may be # a subclass to handle id3v23 if config.setting["clear_existing_tags"]: self.orig_metadata.copy(self.new_metadata) else: self.orig_metadata.update(self.new_metadata) # After saving deleted tags should no longer be marked deleted self.new_metadata.clear_deleted() self.orig_metadata.clear_deleted() self.orig_metadata.length = length self.orig_metadata['~length'] = format_time(length) for k, v in temp_info.items(): self.orig_metadata[k] = v self.error = None self.clear_pending() self._add_path_to_metadata(self.orig_metadata) self.metadata_images_changed.emit() # run post save hook run_file_post_save_processors(self) # Force update to ensure file status icon changes immediately after save self.update() if self.state != File.REMOVED: del self.tagger.files[old_filename] self.tagger.files[new_filename] = self if self.tagger.stopping: log.debug("Save of %r completed before stopping Picard", self.filename)
def column(self, column): if column == 'title': return '%s (%d)' % (self.metadata['album'], len(self.files)) elif self.special and column in {'~length', 'album', 'covercount'}: return '' elif column == '~length': return format_time(self.metadata.length) elif column == 'artist': return self.metadata['albumartist'] elif column == 'tracknumber': return self.metadata['totaltracks'] elif column == 'discnumber': return self.metadata['totaldiscs'] elif column == 'covercount': return self.cover_art_description() return self.metadata[column]
def _copy_loaded_metadata(self, metadata): filename, _ = os.path.splitext(self.base_filename) metadata['~length'] = format_time(metadata.length) if 'title' not in metadata: metadata['title'] = filename if 'tracknumber' not in metadata: match = re.match("(?:track)?\s*(?:no|nr)?\s*(\d+)", filename, re.I) if match: try: tracknumber = int(match.group(1)) except ValueError: pass else: metadata['tracknumber'] = str(tracknumber) self.orig_metadata = metadata self.metadata.copy(metadata)
def track_to_metadata(node, track): m = track.metadata recording_to_metadata(node.recording[0], track) # overwrite with data we have on the track for name, nodes in node.children.iteritems(): if not nodes: continue if name == 'title': m['title'] = nodes[0].text elif name == 'position': m['tracknumber'] = nodes[0].text elif name == 'length' and nodes[0].text: m.length = int(nodes[0].text) elif name == 'artist_credit': artist_credit_to_metadata(nodes[0], m) m['~length'] = format_time(m.length)
def display_value(self, tag): count = self.counts[tag] missing = self.parent.objects - count if tag in self.different: return (ungettext("(different across %d item)", "(different across %d items)", count) % count, True) else: if tag == "~length": msg = format_time(self.get(tag, 0)) else: msg = MULTI_VALUED_JOINER.join(self[tag]) if count > 0 and missing > 0: return (msg + " " + (ungettext("(missing from %d item)", "(missing from %d items)", missing) % missing), True) else: return (msg, False)
def track_to_metadata(node, track, config): m = track.metadata recording_to_metadata(node.recording[0], track, config) # overwrite with data we have on the track for name, nodes in node.children.iteritems(): if not nodes: continue if name == "title": m["title"] = nodes[0].text elif name == "position": m["tracknumber"] = nodes[0].text elif name == "length" and nodes[0].text: m.length = int(nodes[0].text) elif name == "artist_credit": artist_credit_to_metadata(nodes[0], m, config) m["~length"] = format_time(m.length)
def track_to_metadata(node, track, config): m = track.metadata recording_to_metadata(node.recording[0], track, config) # overwrite with data we have on the track for name, nodes in node.children.iteritems(): if not nodes: continue if name == 'title': m['title'] = nodes[0].text elif name == 'position': m['tracknumber'] = nodes[0].text elif name == 'length' and nodes[0].text: m.length = int(nodes[0].text) elif name == 'artist_credit': artist_credit_to_metadata(nodes[0], m, config) m['~length'] = format_time(m.length)
def track_to_metadata(node, track): m = track.metadata recording_to_metadata(node['recording'], m, track) m.add_unique('musicbrainz_trackid', node['id']) # overwrite with data we have on the track for key, value in node.items(): if not value: continue if key in _TRACK_TO_METADATA: m[_TRACK_TO_METADATA[key]] = value elif key == 'length' and value: m.length = value elif key == 'artist-credit': artist_credit_to_metadata(value, m) if m.length: m['~length'] = format_time(m.length)
def _copy_loaded_metadata(self, metadata): filename, extension = os.path.splitext(self.base_filename) self.metadata.copy(metadata) self.metadata['~extension'] = extension[1:].lower() self.metadata['~length'] = format_time(self.metadata.length) if 'title' not in self.metadata: self.metadata['title'] = filename if 'tracknumber' not in self.metadata: match = re.match("(?:track)?\s*(?:no|nr)?\s*(\d+)", filename, re.I) if match: try: tracknumber = int(match.group(1)) except ValueError: pass else: self.metadata['tracknumber'] = str(tracknumber) self.orig_metadata.copy(self.metadata)
def _copy_loaded_metadata(self, metadata): filename, _ = os.path.splitext(self.base_filename) metadata['~length'] = format_time(metadata.length) if 'title' not in metadata: metadata['title'] = filename if 'tracknumber' not in metadata: tracknumber = tracknum_from_filename(self.base_filename) if tracknumber != -1: tracknumber = str(tracknumber) metadata['tracknumber'] = tracknumber if metadata['title'] == filename: stripped_filename = filename.lstrip('0') tnlen = len(tracknumber) if stripped_filename[:tnlen] == tracknumber: metadata['title'] = stripped_filename[tnlen:].lstrip() self.orig_metadata = metadata self.metadata.copy(metadata)
def _saving_finished(self, result=None, error=None): # Handle file removed before save # Result is None if save was skipped if ((self.state == File.REMOVED or self.tagger.stopping) and result is None): return old_filename = new_filename = self.filename if error is not None: self.error = str(error) self.set_state(File.ERROR, update=True) else: self.filename = new_filename = result self.base_filename = os.path.basename(new_filename) length = self.orig_metadata.length temp_info = {} for info in ('~bitrate', '~sample_rate', '~channels', '~bits_per_sample', '~format'): temp_info[info] = self.orig_metadata[info] # Data is copied from New to Original because New may be # a subclass to handle id3v23 if config.setting["clear_existing_tags"]: self.orig_metadata.copy(self.new_metadata) else: self.orig_metadata.update(self.new_metadata) # After saving deleted tags should no longer be marked deleted self.new_metadata.clear_deleted() self.orig_metadata.clear_deleted() self.orig_metadata.length = length self.orig_metadata['~length'] = format_time(length) for k, v in temp_info.items(): self.orig_metadata[k] = v self.error = None # Force update to ensure file status icon changes immediately after save self.clear_pending(force_update=True) self._add_path_to_metadata(self.orig_metadata) self.metadata_images_changed.emit() if self.state != File.REMOVED: del self.tagger.files[old_filename] self.tagger.files[new_filename] = self if self.tagger.stopping: log.debug("Save of %r completed before stopping Picard", self.filename)