• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Python mp4.Atom类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

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



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

示例1: test_write_back_bad_atoms

    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,代码行数:35,代码来源:test_mp4.py


示例2: test_covr_blank_format

 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,代码行数:7,代码来源:test_mp4.py


示例3: test_write_back_bad_atoms

    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,代码行数:33,代码来源:test_mp4.py


示例4: test_parse_multiple_atoms

 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,代码行数:10,代码来源:test_mp4.py


示例5: test_mdhd_version_1

 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,代码行数:12,代码来源:test_mp4.py


示例6: test_mdhd_version_1

 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,代码行数:13,代码来源:test_mp4.py


示例7: test_read

    def test_read(self):
        payload = 8 * b"\xff"
        fileobj = cBytesIO(b"\x00\x00\x00\x10atom" + payload)
        atom = Atom(fileobj)
        ok, data = atom.read(fileobj)
        self.assertTrue(ok)
        self.assertEqual(data, payload)

        payload = 7 * b"\xff"
        fileobj = cBytesIO(b"\x00\x00\x00\x10atom" + payload)
        atom = Atom(fileobj)
        ok, data = atom.read(fileobj)
        self.assertFalse(ok)
        self.assertEqual(data, payload)
开发者ID:maphew,项目名称:mutagen,代码行数:14,代码来源:test_mp4.py


示例8: test_purl

    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,代码行数:26,代码来源:test_mp4.py


示例9: test_length_0_container

 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,代码行数:7,代码来源:test_mp4.py


示例10: test_render_too_big

 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,代码行数:12,代码来源:test_mp4.py


示例11: test_multiple_tracks

 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,代码行数:15,代码来源:test_mp4.py


示例12: test_multiple_tracks

 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,代码行数:16,代码来源:test_mp4.py


示例13: test_multi_freeform

    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,代码行数:13,代码来源:test_mp4.py


示例14: test_freeform_data

    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,代码行数:23,代码来源:test_mp4.py


示例15: test_freeform_data

    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,代码行数:23,代码来源:test_mp4.py


示例16: test_bad_freeform

 def test_bad_freeform(self):
     mean = Atom.render("mean", "net.sacredchao.Mutagen")
     name = Atom.render("name", "empty test key")
     bad_freeform = Atom.render("----", "\x00" * 4 + mean + name)
     self.failUnlessRaises(MP4MetadataError, self.wrap_ilst, bad_freeform)
开发者ID:andrewboie,项目名称:discogstool,代码行数:5,代码来源:test_mp4.py


示例17: wrap_ilst

 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,代码行数:6,代码来源:test_mp4.py


示例18: test_bad_covr

 def test_bad_covr(self):
     data = Atom.render("foob", "\x00\x00\x00\x0E" + "\x00" * 4 + "whee")
     covr = Atom.render("covr", data)
     self.failUnlessRaises(MP4MetadataError, self.wrap_ilst, covr)
开发者ID:andrewboie,项目名称:discogstool,代码行数:4,代码来源:test_mp4.py


示例19: test_bad_text_data

 def test_bad_text_data(self):
     data = Atom.render("datA", "\x00\x00\x00\x01\x00\x00\x00\x00whee")
     data = Atom.render("aART", data)
     self.failUnlessRaises(MP4MetadataError, self.wrap_ilst, data)
开发者ID:andrewboie,项目名称:discogstool,代码行数:4,代码来源:test_mp4.py


示例20: test_genre_too_big

 def test_genre_too_big(self):
     data = Atom.render("data", "\x00" * 8 + "\x01\x00")
     genre = Atom.render("gnre", data)
     tags = self.wrap_ilst(genre)
     self.failIf("gnre" in tags)
     self.failIf("\xa9gen" in tags)
开发者ID:andrewboie,项目名称:discogstool,代码行数:6,代码来源:test_mp4.py



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Python ogg.OggPage类代码示例发布时间:2022-05-27
下一篇:
Python m4a.Atom类代码示例发布时间:2022-05-27
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap