本文整理汇总了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;未经允许,请勿转载。 |
请发表评论