def save(self): """Writes the tags in self.__tags to self.filename if no filename is specified.""" filepath = self.filepath if self.mut_obj.tags is None: self.mut_obj.add_tags() if filepath != self.mut_obj.filename: self.mut_obj.filename = filepath audio = self.mut_obj newtag = {} for field, value in usertags(self.__tags).items(): try: newtag[self.__rtranslate[field]] = value except KeyError: newtag[field] = value pics = map(pic_to_bin, self.images) if pics: newtag['WM/Picture'] = pics toremove = [z for z in audio if z not in newtag] for z in toremove: del(audio[z]) audio.update(newtag) audio.save()
def save(self): """Writes the tags in self.__tags to self.filename if no filename is specified.""" filepath = self.filepath if self.mut_obj.tags is None: self.mut_obj.add_tags() if filepath != self.mut_obj.filename: self.mut_obj.filename = filepath audio = self.mut_obj newtag = {} for tag, value in usertags(self.__tags).items(): newtag[tag] = value if self.__images: if base == FLAC: audio.clear_pictures() map(lambda p: audio.add_picture(image_to_bin(p)), self.__images) else: newtag[COVER_KEY] = filter(None, map(image_to_base64, self.__images)) else: if base == FLAC: audio.clear_pictures() toremove = [z for z in audio if z not in newtag] for z in toremove: del(audio[z]) audio.update(newtag) audio.save()
def save(self): if self.mut_obj.tags is None: self.mut_obj.add_tags() if self.filepath != self.mut_obj.filename: self.mut_obj.filename = self.filepath audio = self.mut_obj newtag = {} tuples = (('track', ['trkn', 'totaltracks']), ('disc', ['disk', 'totaldiscs'])) tags = self.__tags for tag, values in tuples: if tag in tags: denom = tags[tag] if values[1] in tags: total = tags[values[1]] newtag[values[0]] = [(int(t), int(total)) for t, total in zip(denom, total)] else: newtag[values[0]] = [(int(z), 0) for z in denom] elif values[1] in tags: total = tags[values[1]] newtag[values[0]] = [(0, int(z)) for z in total] tags = usertags(self.__tags) tags = [(z, tags[z]) for z in tags if z not in ['track', 'totaltracks', 'disc', 'totaldiscs']] for tag, value in tags: try: newtag[REVTAGS[tag]] = value except KeyError: newtag[self.__freeform[tag].encode('utf8')] = encode( self.__tags[tag]) if self.images: newtag['covr'] = filter(None, map(pic_to_bin, self.images)) toremove = [ z for z in audio.keys() if z not in newtag and z not in self.__errors ] for key in toremove: del (audio[key]) audio.update(newtag) audio.save()
def save(self): if self.mut_obj.tags is None: self.mut_obj.add_tags() if self.filepath != self.mut_obj.filename: self.mut_obj.filename = self.filepath audio = self.mut_obj newtag = {} tuples = (('track', ['trkn', 'totaltracks']), ('disc', ['disk', 'totaldiscs'])) tags = self.__tags for tag, values in tuples: if tag in tags: denom = tags[tag] if values[1] in tags: total = tags[values[1]] newtag[values[0]] = [(int(t), int(total)) for t, total in zip(denom, total)] else: newtag[values[0]] = [(int(z), 0) for z in denom] elif values[1] in tags: total = tags[values[1]] newtag[values[0]] = [(0, int(z)) for z in total] tags = usertags(self.__tags) tags = [(z, tags[z]) for z in tags if z not in ['track', 'totaltracks', 'disc', 'totaldiscs']] for tag, value in tags: try: newtag[REVTAGS[tag]] = value except KeyError: newtag[self.__freeform[tag].encode('utf8')] = encode(self.__tags[tag]) if self.images: newtag['covr'] = filter(None, map(pic_to_bin, self.images)) toremove = [z for z in audio.keys() if z not in newtag and z not in self.__errors] for key in toremove: del(audio[key]) audio.update(newtag) audio.save()
def save(self): if self.mut_obj.tags is None: self.mut_obj.add_tags() if self.filepath != self.mut_obj.filename: self.mut_obj.filename = self.filepath audio = self.mut_obj newtag = {} if self.images: [newtag.update(pic_to_bin(z)) for z in self.images] for field, value in usertags(self.__tags).items(): try: if isinstance(field, unicode): field = field.encode('utf8') newtag[field] = value except AttributeError: pass toremove = [z for z in audio if z not in newtag and audio[z].kind == 0] for z in toremove: del(audio[z]) audio.tags.update(newtag) audio.save()
def save(self): if self.mut_obj.tags is None: self.mut_obj.add_tags() if self.filepath != self.mut_obj.filename: self.mut_obj.filename = self.filepath audio = self.mut_obj newtag = {} if self.images: [newtag.update(pic_to_bin(z)) for z in self.images] for field, value in usertags(self.__tags).items(): try: if isinstance(field, unicode): field = field.encode('utf8') newtag[field] = value except AttributeError: pass toremove = [ z for z in audio if z not in newtag and audio[z].kind == 0 ] for z in toremove: del (audio[z]) audio.tags.update(newtag) audio.save()
def save(self, v1=None, v2=None): if v1 is None: v1 = v1_option """Writes the tags to file.""" filename = self.filepath if self.mut_obj.tags is None: self.mut_obj.add_tags() if filename != self.mut_obj.filename: self.mut_obj.tags.filename = filename self.mut_obj.filename = filename audio = self.mut_obj util.MockTag.save(self) userkeys = usertags(self.__tags).keys() frames = [] [ frames.append(frame) if not hasattr(frame, 'frames') else frames.extend(frame.frames) for key, frame in self.__tags.items() if key in userkeys ] hashes = dict([(frame.HashKey, frame) for frame in frames]) toremove = [ z for z in self._originaltags if z in audio and not (z in hashes or z.startswith('APIC')) ] audio.update(hashes) old_apics = [z for z in audio if z.startswith(u'APIC')] if self.__images: newimages = [] for image in filter(None, map(pic_to_bin, self.__images)): i = 0 while image.HashKey in newimages: i += 1 #Pad with spaces so that each key is unique. image.desc += u' ' * i audio[image.HashKey] = image newimages.append(image.HashKey) [toremove.append(z) for z in old_apics if z not in newimages] else: toremove.extend(old_apics) for z in set(toremove): try: del (audio[z]) except KeyError: continue audio.tags.filename = self.filepath v1 = v1_option if v1 is None else v1 v2 = v2_option if v2 is None else v2 if AIFF is not None and id3_filetype is AIFFFileType: if v2 == 3: audio.tags.save(v2_version=3) #AIFF doesn't support id3v1 else: audio.tags.save() #AIFF doesn't support id3v1 elif DSF is not None and id3_filetype is DSFFileType: if v2 == 3: audio.tags.save(v2_version=3) #DSF doesn't support id3v1 else: audio.tags.save() #DSF doesn't support id3v1 else: if v2 == 4: audio.tags.update_to_v24() audio.tags.save(v1=v1, v2=4) else: c = ID3() c.filename = self.filepath c.update(audio) c.update_to_v23() c.save(v1=v1, v2=3) self.__tags['__tag_read'] = u'ID3v2.4' if v2 == 4 else u'ID3v2.3' self.update_tag_list() self._originaltags = audio.keys()
def save(self, v1=None, v2=None): if v1 is None: v1 = v1_option """Writes the tags to file.""" filename = self.filepath if self.mut_obj.tags is None: self.mut_obj.add_tags() if filename != self.mut_obj.filename: self.mut_obj.tags.filename = filename self.mut_obj.filename = filename audio = self.mut_obj util.MockTag.save(self) userkeys = usertags(self.__tags).keys() frames = [] [frames.append(frame) if not hasattr(frame, 'frames') else frames.extend(frame.frames) for key, frame in self.__tags.items() if key in userkeys] hashes = dict([(frame.HashKey, frame) for frame in frames]) toremove = [z for z in self._originaltags if z in audio and not (z in hashes or z.startswith('APIC'))] audio.update(hashes) old_apics = [z for z in audio if z.startswith(u'APIC')] if self.__images: newimages = [] for image in filter(None, map(pic_to_bin, self.__images)): i = 0 while image.HashKey in newimages: i += 1 #Pad with spaces so that each key is unique. image.desc += u' '*i audio[image.HashKey] = image newimages.append(image.HashKey) [toremove.append(z) for z in old_apics if z not in newimages] else: toremove.extend(old_apics) for z in set(toremove): try: del(audio[z]) except KeyError: continue audio.tags.filename = self.filepath v1 = v1_option if v1 is None else v1 v2 = v2_option if v2 is None else v2 if AIFF is not None and id3_filetype is AIFFFileType: if v2 == 3: audio.tags.save(v2_version=3) #AIFF doesn't support id3v1 else: audio.tags.save() #AIFF doesn't support id3v1 else: if v2 == 4: audio.tags.update_to_v24() audio.tags.save(v1=v1, v2=4) else: c = ID3() c.filename = self.filepath c.update(audio) c.update_to_v23() c.save(v1=v1, v2=3) self.__tags['__tag_read'] = u'ID3v2.4' if v2 == 4 else u'ID3v2.3' self.update_tag_list() self._originaltags = audio.keys()