当前位置: 首页>>代码示例>>Python>>正文


Python Atom.render方法代码示例

本文整理汇总了Python中mutagen.mp4.Atom.render方法的典型用法代码示例。如果您正苦于以下问题:Python Atom.render方法的具体用法?Python Atom.render怎么用?Python Atom.render使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在mutagen.mp4.Atom的用法示例。


在下文中一共展示了Atom.render方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: test_write_back_bad_atoms

# 需要导入模块: from mutagen.mp4 import Atom [as 别名]
# 或者: from mutagen.mp4.Atom import render [as 别名]
    def test_write_back_bad_atoms(self):
        # write a broken atom and try to load it
        data = Atom.render(b"datA", b"\x00\x00\x00\x01\x00\x00\x00\x00wheeee")
        data = Atom.render(b"aART", data)
        tags = self.wrap_ilst(data)
        self.assertFalse(tags)

        # save it into an existing mp4
        original = os.path.join(DATA_DIR, "has-tags.m4a")
        filename = get_temp_copy(original)
        try:
            delete(filename)

            # it should still end up in the file
            tags.save(filename)
            with open(filename, "rb") as h:
                self.assertTrue(b"wheeee" in h.read())

            # if we define our own aART throw away the broken one
            tags["aART"] = ["new"]
            tags.save(filename)
            with open(filename, "rb") as h:
                self.assertFalse(b"wheeee" in h.read())

            # add the broken one back and delete all tags including
            # the broken one
            del tags["aART"]
            tags.save(filename)
            with open(filename, "rb") as h:
                self.assertTrue(b"wheeee" in h.read())
            delete(filename)
            with open(filename, "rb") as h:
                self.assertFalse(b"wheeee" in h.read())
        finally:
            os.unlink(filename)
开发者ID:gdelfresno,项目名称:mutagen,代码行数:37,代码来源:test_mp4.py

示例2: test_covr_blank_format

# 需要导入模块: from mutagen.mp4 import Atom [as 别名]
# 或者: from mutagen.mp4.Atom import render [as 别名]
 def test_covr_blank_format(self):
     data = Atom.render(
         b"data", b"\x00\x00\x00\x00" + b"\x00" * 4 + b"whee")
     covr = Atom.render(b"covr", data)
     tags = self.wrap_ilst(covr)
     self.failUnlessEqual(
         MP4Cover.FORMAT_JPEG, tags["covr"][0].imageformat)
开发者ID:maphew,项目名称:mutagen,代码行数:9,代码来源:test_mp4.py

示例3: test_write_back_bad_atoms

# 需要导入模块: from mutagen.mp4 import Atom [as 别名]
# 或者: from mutagen.mp4.Atom import render [as 别名]
    def test_write_back_bad_atoms(self):
        # write a broken atom and try to load it
        data = Atom.render(b"datA", b"\x00\x00\x00\x01\x00\x00\x00\x00wheeee")
        data = Atom.render(b"aART", data)
        tags = self.wrap_ilst(data)
        self.assertFalse(tags)

        # save it into an existing mp4
        original = os.path.join("tests", "data", "has-tags.m4a")
        fd, filename = mkstemp(suffix=".mp4")
        os.close(fd)
        shutil.copy(original, filename)
        delete(filename)

        # it should still end up in the file
        tags.save(filename)
        with open(filename, "rb") as h:
            self.assertTrue(b"wheeee" in h.read())

        # if we define our own aART throw away the broken one
        tags["aART"] = ["new"]
        tags.save(filename)
        with open(filename, "rb") as h:
            self.assertFalse(b"wheeee" in h.read())

        # add the broken one back and delete all tags including the broken one
        del tags["aART"]
        tags.save(filename)
        with open(filename, "rb") as h:
            self.assertTrue(b"wheeee" in h.read())
        delete(filename)
        with open(filename, "rb") as h:
            self.assertFalse(b"wheeee" in h.read())
开发者ID:dmoon4117,项目名称:mutagen,代码行数:35,代码来源:test_mp4.py

示例4: test_parse_multiple_atoms

# 需要导入模块: from mutagen.mp4 import Atom [as 别名]
# 或者: from mutagen.mp4.Atom import render [as 别名]
 def test_parse_multiple_atoms(self):
     # while we don't write multiple values as multiple atoms
     # still read them
     # https://github.com/quodlibet/mutagen/issues/165
     data = Atom.render(b"data", b"\x00\x00\x00\x01" + b"\x00" * 4 + b"foo")
     grp1 = Atom.render(b"\xa9grp", data)
     data = Atom.render(b"data", b"\x00\x00\x00\x01" + b"\x00" * 4 + b"bar")
     grp2 = Atom.render(b"\xa9grp", data)
     tags = self.wrap_ilst(grp1 + grp2)
     self.assertEqual(tags["\xa9grp"], [u"foo", u"bar"])
开发者ID:maphew,项目名称:mutagen,代码行数:12,代码来源:test_mp4.py

示例5: test_mdhd_version_1

# 需要导入模块: from mutagen.mp4 import Atom [as 别名]
# 或者: from mutagen.mp4.Atom import render [as 别名]
 def test_mdhd_version_1(self, soun="soun"):
     mdhd = Atom.render("mdhd", ("\x01\x00\x00\x00" + "\x00" * 16 +
                                 "\x00\x00\x00\x02" + # 2 Hz
                                 "\x00\x00\x00\x00\x00\x00\x00\x10"))
     hdlr = Atom.render("hdlr", "\x00" * 8 + soun)
     mdia = Atom.render("mdia", mdhd + hdlr)
     trak = Atom.render("trak", mdia)
     moov = Atom.render("moov", trak)
     fileobj = StringIO(moov)
     atoms = Atoms(fileobj)
     info = MP4Info(atoms, fileobj)
     self.failUnlessEqual(info.length, 8)
开发者ID:andrewboie,项目名称:discogstool,代码行数:14,代码来源:test_mp4.py

示例6: test_mdhd_version_1

# 需要导入模块: from mutagen.mp4 import Atom [as 别名]
# 或者: from mutagen.mp4.Atom import render [as 别名]
 def test_mdhd_version_1(self, soun=b"soun"):
     mdhd = Atom.render(
         b"mdhd",
         (b"\x01\x00\x00\x00" + b"\x00" * 16 + b"\x00\x00\x00\x02" + b"\x00\x00\x00\x00\x00\x00\x00\x10"),  # 2 Hz
     )
     hdlr = Atom.render(b"hdlr", b"\x00" * 8 + soun)
     mdia = Atom.render(b"mdia", mdhd + hdlr)
     trak = Atom.render(b"trak", mdia)
     moov = Atom.render(b"moov", trak)
     fileobj = cBytesIO(moov)
     atoms = Atoms(fileobj)
     info = MP4Info(atoms, fileobj)
     self.failUnlessEqual(info.length, 8)
开发者ID:dmoon4117,项目名称:mutagen,代码行数:15,代码来源:test_mp4.py

示例7: test_purl

# 需要导入模块: from mutagen.mp4 import Atom [as 别名]
# 或者: from mutagen.mp4.Atom import render [as 别名]
    def test_purl(self):
        # purl can have 0 or 1 flags (implicit or utf8)
        data = Atom.render(b"data", b"\x00\x00\x00\x01" + b"\x00" * 4 + b"foo")
        purl = Atom.render(b"purl", data)
        tags = self.wrap_ilst(purl)
        self.failUnlessEqual(tags["purl"], ["foo"])

        data = Atom.render(b"data", b"\x00\x00\x00\x00" + b"\x00" * 4 + b"foo")
        purl = Atom.render(b"purl", data)
        tags = self.wrap_ilst(purl)
        self.failUnlessEqual(tags["purl"], ["foo"])

        # invalid flag
        data = Atom.render(b"data", b"\x00\x00\x00\x03" + b"\x00" * 4 + b"foo")
        purl = Atom.render(b"purl", data)
        tags = self.wrap_ilst(purl)
        self.assertFalse("purl" in tags)

        self.assertTrue("purl" in tags._failed_atoms)

        # invalid utf8
        data = Atom.render(
            b"data", b"\x00\x00\x00\x01" + b"\x00" * 4 + b"\xff")
        purl = Atom.render(b"purl", data)
        tags = self.wrap_ilst(purl)
        self.assertFalse("purl" in tags)
开发者ID:maphew,项目名称:mutagen,代码行数:28,代码来源:test_mp4.py

示例8: test_length_0_container

# 需要导入模块: from mutagen.mp4 import Atom [as 别名]
# 或者: from mutagen.mp4.Atom import render [as 别名]
 def test_length_0_container(self):
     data = StringIO(struct.pack(">I4s", 0, "moov") +
                     Atom.render("data", "whee"))
     atom = Atom(data)
     self.failUnlessEqual(len(atom.children), 1)
     self.failUnlessEqual(atom.length, 20)
     self.failUnlessEqual(atom.children[-1].length, 12)
开发者ID:andrewboie,项目名称:discogstool,代码行数:9,代码来源:test_mp4.py

示例9: test_render_too_big

# 需要导入模块: from mutagen.mp4 import Atom [as 别名]
# 或者: from mutagen.mp4.Atom import render [as 别名]
 def test_render_too_big(self):
     class TooBig(str):
         def __len__(self):
             return 1L << 32
     data = TooBig("test")
     try: len(data)
     except OverflowError:
         # Py_ssize_t is still only 32 bits on this system.
         self.failUnlessRaises(OverflowError, Atom.render, "data", data)
     else:
         data = Atom.render("data", data)
         self.failUnlessEqual(len(data), 4 + 4 + 8 + 4)
开发者ID:andrewboie,项目名称:discogstool,代码行数:14,代码来源:test_mp4.py

示例10: test_multiple_tracks

# 需要导入模块: from mutagen.mp4 import Atom [as 别名]
# 或者: from mutagen.mp4.Atom import render [as 别名]
 def test_multiple_tracks(self):
     hdlr = Atom.render("hdlr", "\x00" * 8 + "whee")
     mdia = Atom.render("mdia", hdlr)
     trak1 = Atom.render("trak", mdia)
     mdhd = Atom.render("mdhd", ("\x01\x00\x00\x00" + "\x00" * 16 +
                                 "\x00\x00\x00\x02" + # 2 Hz
                                 "\x00\x00\x00\x00\x00\x00\x00\x10"))
     hdlr = Atom.render("hdlr", "\x00" * 8 + "soun")
     mdia = Atom.render("mdia", mdhd + hdlr)
     trak2 = Atom.render("trak", mdia)
     moov = Atom.render("moov", trak1 + trak2)
     fileobj = StringIO(moov)
     atoms = Atoms(fileobj)
     info = MP4Info(atoms, fileobj)
     self.failUnlessEqual(info.length, 8)
开发者ID:andrewboie,项目名称:discogstool,代码行数:17,代码来源:test_mp4.py

示例11: test_multiple_tracks

# 需要导入模块: from mutagen.mp4 import Atom [as 别名]
# 或者: from mutagen.mp4.Atom import render [as 别名]
 def test_multiple_tracks(self):
     hdlr = Atom.render(b"hdlr", b"\x00" * 8 + b"whee")
     mdia = Atom.render(b"mdia", hdlr)
     trak1 = Atom.render(b"trak", mdia)
     mdhd = Atom.render(
         b"mdhd",
         (b"\x01\x00\x00\x00" + b"\x00" * 16 + b"\x00\x00\x00\x02" + b"\x00\x00\x00\x00\x00\x00\x00\x10"),  # 2 Hz
     )
     hdlr = Atom.render(b"hdlr", b"\x00" * 8 + b"soun")
     mdia = Atom.render(b"mdia", mdhd + hdlr)
     trak2 = Atom.render(b"trak", mdia)
     moov = Atom.render(b"moov", trak1 + trak2)
     fileobj = cBytesIO(moov)
     atoms = Atoms(fileobj)
     info = MP4Info(atoms, fileobj)
     self.failUnlessEqual(info.length, 8)
开发者ID:dmoon4117,项目名称:mutagen,代码行数:18,代码来源:test_mp4.py

示例12: test_multi_freeform

# 需要导入模块: from mutagen.mp4 import Atom [as 别名]
# 或者: from mutagen.mp4.Atom import render [as 别名]
    def test_multi_freeform(self):
        # merge multiple freeform tags with the same key
        mean = Atom.render(b"mean", b"\x00" * 4 + b"net.sacredchao.Mutagen")
        name = Atom.render(b"name", b"\x00" * 4 + b"foo")

        data = Atom.render(b"data", b"\x00\x00\x00\x01" + b"\x00" * 4 + b"bar")
        result = Atom.render(b"----", mean + name + data)
        data = Atom.render(b"data", b"\x00\x00\x00\x01" + b"\x00" * 4 + b"quux")
        result += Atom.render(b"----", mean + name + data)
        tags = self.wrap_ilst(result)
        values = tags["----:net.sacredchao.Mutagen:foo"]
        self.assertEqual(values[0], b"bar")
        self.assertEqual(values[1], b"quux")
开发者ID:dmoon4117,项目名称:mutagen,代码行数:15,代码来源:test_mp4.py

示例13: test_freeform_data

# 需要导入模块: from mutagen.mp4 import Atom [as 别名]
# 或者: from mutagen.mp4.Atom import render [as 别名]
    def test_freeform_data(self):
        # https://github.com/quodlibet/mutagen/issues/103
        key = "----:com.apple.iTunes:Encoding Params"
        value = (b"vers\x00\x00\x00\x01acbf\x00\x00\x00\x01brat\x00\x01\xf4"
                 b"\x00cdcv\x00\x01\x05\x04")

        data = (b"\x00\x00\x00\x1cmean\x00\x00\x00\x00com.apple.iTunes\x00\x00"
                b"\x00\x1bname\x00\x00\x00\x00Encoding Params\x00\x00\x000data"
                b"\x00\x00\x00\x00\x00\x00\x00\x00vers\x00\x00\x00\x01acbf\x00"
                b"\x00\x00\x01brat\x00\x01\xf4\x00cdcv\x00\x01\x05\x04")

        tags = self.wrap_ilst(Atom.render(b"----", data))
        v = tags[key][0]
        self.failUnlessEqual(v, value)
        self.failUnlessEqual(v.dataformat, AtomDataType.IMPLICIT)

        data = MP4Tags()._MP4Tags__render_freeform(key, v)
        v = self.wrap_ilst(data)[key][0]
        self.failUnlessEqual(v.dataformat, AtomDataType.IMPLICIT)

        data = MP4Tags()._MP4Tags__render_freeform(key, value)
        v = self.wrap_ilst(data)[key][0]
        self.failUnlessEqual(v.dataformat, AtomDataType.UTF8)
开发者ID:maphew,项目名称:mutagen,代码行数:25,代码来源:test_mp4.py

示例14: test_freeform_data

# 需要导入模块: from mutagen.mp4 import Atom [as 别名]
# 或者: from mutagen.mp4.Atom import render [as 别名]
    def test_freeform_data(self):
        # http://code.google.com/p/mutagen/issues/detail?id=103
        key = "----:com.apple.iTunes:Encoding Params"
        value = ("vers\x00\x00\x00\x01acbf\x00\x00\x00\x01brat\x00\x01\xf4"
                 "\x00cdcv\x00\x01\x05\x04")

        data = ("\x00\x00\x00\x1cmean\x00\x00\x00\x00com.apple.iTunes\x00\x00"
                "\x00\x1bname\x00\x00\x00\x00Encoding Params\x00\x00\x000data"
                "\x00\x00\x00\x00\x00\x00\x00\x00vers\x00\x00\x00\x01acbf\x00"
                "\x00\x00\x01brat\x00\x01\xf4\x00cdcv\x00\x01\x05\x04")

        tags = self.wrap_ilst(Atom.render("----", data))
        v = tags[key][0]
        self.failUnlessEqual(v, value)
        self.failUnlessEqual(v.dataformat, MP4FreeForm.FORMAT_DATA)

        data = MP4Tags()._MP4Tags__render_freeform(key, v)
        v = self.wrap_ilst(data)[key][0]
        self.failUnlessEqual(v.dataformat, MP4FreeForm.FORMAT_DATA)

        data = MP4Tags()._MP4Tags__render_freeform(key, value)
        v = self.wrap_ilst(data)[key][0]
        self.failUnlessEqual(v.dataformat, MP4FreeForm.FORMAT_TEXT)
开发者ID:andrewboie,项目名称:discogstool,代码行数:25,代码来源:test_mp4.py

示例15: wrap_ilst

# 需要导入模块: from mutagen.mp4 import Atom [as 别名]
# 或者: from mutagen.mp4.Atom import render [as 别名]
 def wrap_ilst(self, data):
     ilst = Atom.render("ilst", data)
     meta = Atom.render("meta", "\x00" * 4 + ilst)
     data = Atom.render("moov", Atom.render("udta", meta))
     fileobj = StringIO(data)
     return MP4Tags(Atoms(fileobj), fileobj)
开发者ID:andrewboie,项目名称:discogstool,代码行数:8,代码来源:test_mp4.py


注:本文中的mutagen.mp4.Atom.render方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。