예제 #1
0
    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()
예제 #2
0
파일: mp4.py 프로젝트: LudoBike/quodlibet
    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()
예제 #3
0
파일: spc.py 프로젝트: nkuttler/quodlibet
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
예제 #4
0
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
예제 #5
0
    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"
예제 #6
0
    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"
예제 #7
0
    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"})
예제 #8
0
    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)
예제 #9
0
    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)
예제 #10
0
    def masked_mount_points(self):
        """List of mount points that contain masked items"""

        return listkeys(self._masked)
예제 #11
0
    def quit(self):
        """Disable plugins and tell all handlers to clean up"""

        for name in listkeys(self.__modules):
            self.__remove_module(name)
예제 #12
0
    def masked_mount_points(self):
        """List of mount points that contain masked items"""

        return listkeys(self._masked)
예제 #13
0
    def quit(self):
        """Disable plugins and tell all handlers to clean up"""

        for name in listkeys(self.__modules):
            self.__remove_module(name)
예제 #14
0
 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)
예제 #15
0
    def remove_all(self):
        """Stop all running routines."""

        for funcid in listkeys(self.__routines):
            self.remove(funcid)
예제 #16
0
 def clear(self):
     for key in listkeys(self):
         del self[key]
예제 #17
0
 def popitem(self):
     try:
         key = listkeys(self)[0]
         return key, self.pop(key)
     except IndexError:
         raise KeyError("dictionary is empty")
예제 #18
0
 def popitem(self):
     try:
         key = listkeys(self)[0]
         return key, self.pop(key)
     except IndexError:
         raise KeyError("dictionary is empty")
예제 #19
0
    def remove_all(self):
        """Stop all running routines."""

        for funcid in listkeys(self.__routines):
            self.remove(funcid)
예제 #20
0
파일: mp4.py 프로젝트: LudoBike/quodlibet
 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)
예제 #21
0
 def clear(self):
     for key in listkeys(self):
         del self[key]