def write(self): with translate_errors(): audio = MP4(self["~filename"]) for key in (listkeys(self.__translate) + listkeys(self.__tupletranslate)): try: del (audio[key]) except KeyError: pass for key in self.realkeys(): try: name = self.__rtranslate[key] except KeyError: continue values = self.list(key) if name == "tmpo": values = list(map(lambda v: int(round(float(v))), values)) elif name.startswith("----"): values = list(map(lambda v: v.encode("utf-8"), values)) audio[name] = values track, tracks = self("~#track"), self("~#tracks", 0) if track: audio["trkn"] = [(track, tracks)] disc, discs = self("~#disc"), self("~#discs", 0) if disc: audio["disk"] = [(disc, discs)] with translate_errors(): audio.save() self.sanitize()
def write(self): with translate_errors(): audio = MP4(self["~filename"]) for key in (listkeys(self.__translate) + listkeys(self.__tupletranslate)): try: del(audio[key]) except KeyError: pass for key in self.realkeys(): try: name = self.__rtranslate[key] except KeyError: continue values = self.list(key) if name == "tmpo": values = list(map(lambda v: int(round(float(v))), values)) elif name.startswith("----"): values = list(map(lambda v: v.encode("utf-8"), values)) audio[name] = values track, tracks = self("~#track"), self("~#tracks", 0) if track: audio["trkn"] = [(track, tracks)] disc, discs = self("~#disc"), self("~#discs", 0) if disc: audio["disk"] = [(disc, discs)] with translate_errors(): audio.save() self.sanitize()
def parse_id666(data): #http://snesmusic.org/files/spc_file_format.txt tags = {} tags["title"] = data[:32] tags["album"] = data[32:64] tags["dumper"] = data[64:80] tags["comments"] = data[80:112] # Artist differs based on binary or text mode, which is implicit. # Instead of detecting "perfectly", we'll just detect enough for # the "artist" field. This fails for artist names that begin with # numbers or symbols less than ascii value A. if getbyte(data, 130) < b'A': try: tags["~#length"] = int(data[123:126].strip(b"\x00")) except ValueError: pass tags["artist"] = data[131:163] else: tags["artist"] = data[130:162] for k in listkeys(tags): if k[:2] == "~#": continue tags[k] = tags[k].replace(b"\x00", b"").decode("ascii", "ignore") if not tags[k]: del tags[k] return tags
def test_setitem_keys(self): af = AudioFile() af[u"foo"] = u"bar" assert "foo" in af assert isinstance(listkeys(af)[0], str) af.clear() af[u"öäü"] = u"bar" assert u"öäü" in af assert isinstance(listkeys(af)[0], text_type) with self.assertRaises(TypeError): af[42] = u"foo" if PY3: with self.assertRaises(TypeError): af[b"foo"] = u"bar" else: with self.assertRaises(ValueError): af[b"\xff"] = u"bar"
def test_add_check(self): keys = listkeys(self.s) self.check_true(["add", "foo", "bar", self.f], False, False) self.s.reload() self.failUnlessEqual(self.s["foo"], "bar") self.failUnlessEqual(len(keys) + 1, len(self.s.keys())) self.check_true(["-v", "add", "foo", "bar2", self.f], False, True) self.s.reload() self.failUnlessEqual(set(self.s.list("foo")), {"bar", "bar2"})
def _update(self, songs=None): if songs is None: songs = self.__songinfo.songs else: self.__songinfo = AudioFileGroup(songs) songinfo = self.__songinfo keys = listkeys(songinfo) default_tags = get_default_tags() keys = set(keys + default_tags) def custom_sort(key): try: prio = default_tags.index(key) except ValueError: prio = len(default_tags) return (prio, tagsortkey(key)) if not config.getboolean("editing", "alltags"): keys = filter(lambda k: k not in MACHINE_TAGS, keys) if not songs: keys = [] with self._view.without_model() as model: model.clear() for tag in sorted(keys, key=custom_sort): canedit = songinfo.can_change(tag) # default tags if tag not in songinfo: entry = ListEntry(tag, Comment(u"")) entry.canedit = canedit model.append(row=[entry]) continue for value in songinfo[tag]: entry = ListEntry(tag, value) entry.origvalue = value entry.edited = False entry.canedit = canedit entry.deleted = False entry.renamed = False entry.origtag = "" model.append(row=[entry]) self._buttonbox.set_sensitive(bool(songinfo.can_change())) self._revert.set_sensitive(False) self._remove.set_sensitive(False) self._save.set_sensitive(False) self._add.set_sensitive(bool(songs)) self._parent.set_pending(None)
def masked_mount_points(self): """List of mount points that contain masked items""" return listkeys(self._masked)
def quit(self): """Disable plugins and tell all handlers to clean up""" for name in listkeys(self.__modules): self.__remove_module(name)
def can_change(self, key=None): OK = listkeys(self.__rtranslate) + listkeys(self.__rtupletranslate) if key is None: return OK else: return super(MP4File, self).can_change(key) and (key in OK)
def remove_all(self): """Stop all running routines.""" for funcid in listkeys(self.__routines): self.remove(funcid)
def clear(self): for key in listkeys(self): del self[key]
def popitem(self): try: key = listkeys(self)[0] return key, self.pop(key) except IndexError: raise KeyError("dictionary is empty")