本文整理汇总了Python中mutagen.ogg.OggPage.write方法的典型用法代码示例。如果您正苦于以下问题:Python OggPage.write方法的具体用法?Python OggPage.write怎么用?Python OggPage.write使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类mutagen.ogg.OggPage
的用法示例。
在下文中一共展示了OggPage.write方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_crc_py25
# 需要导入模块: from mutagen.ogg import OggPage [as 别名]
# 或者: from mutagen.ogg.OggPage import write [as 别名]
def test_crc_py25(self):
# Make sure page.write can handle both signed/unsigned int
# return values of crc32.
# http://code.google.com/p/mutagen/issues/detail?id=63
# http://docs.python.org/library/zlib.html#zlib.crc32
import zlib
old_crc = zlib.crc32
def zlib_uint(*args):
return (old_crc(*args) & 0xffffffff)
def zlib_int(*args):
return cdata.int_be(cdata.to_uint_be(old_crc(*args) & 0xffffffff))
try:
page = OggPage()
page.packets = [b"abc"]
zlib.crc32 = zlib_uint
uint_data = page.write()
zlib.crc32 = zlib_int
int_data = page.write()
finally:
zlib.crc32 = old_crc
self.failUnlessEqual(uint_data, int_data)
示例2: test_too_many_packets
# 需要导入模块: from mutagen.ogg import OggPage [as 别名]
# 或者: from mutagen.ogg.OggPage import write [as 别名]
def test_too_many_packets(self):
packets = [b"1"] * 3000
pages = OggPage.from_packets(packets)
for p in pages:
OggPage.write(p)
self.failUnless(len(pages) > 3000//255)
示例3: test_unsupported_version
# 需要导入模块: from mutagen.ogg import OggPage [as 别名]
# 或者: from mutagen.ogg.OggPage import write [as 别名]
def test_unsupported_version(self):
page = OggPage(open(self.filename, "rb"))
data = bytearray(page.packets[0])
data[8] = 0x03
page.packets[0] = bytes(data)
OggOpusInfo(BytesIO(page.write()))
data[8] = 0x10
page.packets[0] = bytes(data)
self.failUnlessRaises(IOError, OggOpusInfo, BytesIO(page.write()))
示例4: test_unsupported_version
# 需要导入模块: from mutagen.ogg import OggPage [as 别名]
# 或者: from mutagen.ogg.OggPage import write [as 别名]
def test_unsupported_version(self):
page = OggPage(open(self.filename, "rb"))
data = list(page.packets[0])
data[8] = "\x03"
page.packets[0] = "".join(data)
OggOpusInfo(StringIO(page.write()))
data[8] = "\x10"
page.packets[0] = "".join(data)
self.failUnlessRaises(IOError, OggOpusInfo, StringIO(page.write()))
示例5: test_read_max_size
# 需要导入模块: from mutagen.ogg import OggPage [as 别名]
# 或者: from mutagen.ogg.OggPage import write [as 别名]
def test_read_max_size(self):
page = OggPage()
page.packets = [b"1" * 255 * 255]
page.complete = False
page2 = OggPage()
page2.packets = [b"", b"foo"]
page2.sequence = 1
page2.continued = True
data = page.write() + page2.write()
fileobj = BytesIO(data)
self.failUnlessEqual(OggPage(fileobj), page)
self.failUnlessEqual(OggPage(fileobj), page2)
self.failUnlessRaises(EOFError, OggPage, fileobj)
示例6: test_theora_bad_version
# 需要导入模块: from mutagen.ogg import OggPage [as 别名]
# 或者: from mutagen.ogg.OggPage import write [as 别名]
def test_theora_bad_version(self):
page = OggPage(open(self.filename, "rb"))
packet = page.packets[0]
packet = packet[:7] + b"\x03\x00" + packet[9:]
page.packets = [packet]
fileobj = cBytesIO(page.write())
self.failUnlessRaises(IOError, OggTheoraInfo, fileobj)
示例7: test_underestimated_bitrate
# 需要导入模块: from mutagen.ogg import OggPage [as 别名]
# 或者: from mutagen.ogg.OggPage import write [as 别名]
def test_underestimated_bitrate(self):
page = OggPage(open(self.filename, "rb"))
packet = page.packets[0]
packet = (packet[:16] + b"\x00\x00\x01\x00" + b"\x01\x00\x00\x00" +
b"\x00\x00\x01\x00" + packet[28:])
page.packets[0] = packet
info = OggVorbisInfo(cBytesIO(page.write()))
self.failUnlessEqual(info.bitrate, 65536)
示例8: test_overestimated_bitrate
# 需要导入模块: from mutagen.ogg import OggPage [as 别名]
# 或者: from mutagen.ogg.OggPage import write [as 别名]
def test_overestimated_bitrate(self):
page = OggPage(file(self.filename, "rb"))
packet = page.packets[0]
packet = (packet[:16] + "\x00\x00\x01\x00" + "\x00\x00\x00\x01" +
"\x00\x00\x00\x00" + packet[28:])
page.packets[0] = packet
info = OggVorbisInfo(StringIO(page.write()))
self.failUnlessEqual(info.bitrate, 65536)
示例9: test_negative_bitrate
# 需要导入模块: from mutagen.ogg import OggPage [as 别名]
# 或者: from mutagen.ogg.OggPage import write [as 别名]
def test_negative_bitrate(self):
page = OggPage(open(self.filename, "rb"))
packet = page.packets[0]
packet = (packet[:16] + b"\xff\xff\xff\xff" + b"\xff\xff\xff\xff" +
b"\xff\xff\xff\xff" + packet[28:])
page.packets[0] = packet
info = OggVorbisInfo(cBytesIO(page.write()))
self.failUnlessEqual(info.bitrate, 0)
示例10: test_avg_bitrate
# 需要导入模块: from mutagen.ogg import OggPage [as 别名]
# 或者: from mutagen.ogg.OggPage import write [as 别名]
def test_avg_bitrate(self):
page = OggPage(open(self.filename, "rb"))
packet = page.packets[0]
packet = (packet[:16] + "\x00\x00\x01\x00" + "\x00\x00\x00\x00" +
"\x00\x00\x00\x00" + packet[28:])
page.packets[0] = packet
info = OggVorbisInfo(StringIO(page.write()))
self.failUnlessEqual(info.bitrate, 32768)
示例11: main
# 需要导入模块: from mutagen.ogg import OggPage [as 别名]
# 或者: from mutagen.ogg.OggPage import write [as 别名]
def main(argv):
from mutagen.ogg import OggPage
parser = OptionParser(
usage="%prog [options] filename.ogg ...",
description="Split Ogg logical streams using Mutagen.",
version="Mutagen %s" % ".".join(map(str, mutagen.version))
)
parser.add_option(
"--extension", dest="extension", default="ogg", metavar='ext',
help="use this extension (default 'ogg')")
parser.add_option(
"--pattern", dest="pattern", default="%(base)s-%(stream)d.%(ext)s",
metavar='pattern', help="name files using this pattern")
parser.add_option(
"--m3u", dest="m3u", action="store_true", default=False,
help="generate an m3u (playlist) file")
(options, args) = parser.parse_args(argv[1:])
if not args:
raise SystemExit(parser.print_help() or 1)
format = {'ext': options.extension}
for filename in args:
with _sig.block():
fileobjs = {}
format["base"] = os.path.splitext(os.path.basename(filename))[0]
fileobj = open(filename, "rb")
if options.m3u:
m3u = open(format["base"] + ".m3u", "w")
fileobjs["m3u"] = m3u
else:
m3u = None
while True:
try:
page = OggPage(fileobj)
except EOFError:
break
else:
format["stream"] = page.serial
if page.serial not in fileobjs:
new_filename = options.pattern % format
new_fileobj = open(new_filename, "wb")
fileobjs[page.serial] = new_fileobj
if m3u:
m3u.write(new_filename + "\r\n")
fileobjs[page.serial].write(page.write())
for f in fileobjs.values():
f.close()
示例12: test_invalid_not_first
# 需要导入模块: from mutagen.ogg import OggPage [as 别名]
# 或者: from mutagen.ogg.OggPage import write [as 别名]
def test_invalid_not_first(self):
page = OggPage(open(self.filename, "rb"))
page.first = False
self.failUnlessRaises(IOError, OggSpeexInfo, BytesIO(page.write()))
示例13: test_invalid_not_first
# 需要导入模块: from mutagen.ogg import OggPage [as 别名]
# 或者: from mutagen.ogg.OggPage import write [as 别名]
def test_invalid_not_first(self):
with open(self.filename, "rb") as h:
page = OggPage(h)
page.first = False
self.failUnlessRaises(error, OggSpeexInfo, cBytesIO(page.write()))
示例14: TOggPage
# 需要导入模块: from mutagen.ogg import OggPage [as 别名]
# 或者: from mutagen.ogg.OggPage import write [as 别名]
class TOggPage(TestCase):
def setUp(self):
self.fileobj = open(os.path.join(DATA_DIR, "empty.ogg"), "rb")
self.page = OggPage(self.fileobj)
pages = [OggPage(), OggPage(), OggPage()]
pages[0].packets = [b"foo"]
pages[1].packets = [b"bar"]
pages[2].packets = [b"baz"]
for i in xrange(len(pages)):
pages[i].sequence = i
for page in pages:
page.serial = 1
self.pages = pages
def test_flags(self):
self.failUnless(self.page.first)
self.failIf(self.page.continued)
self.failIf(self.page.last)
self.failUnless(self.page.complete)
for first in [True, False]:
self.page.first = first
for last in [True, False]:
self.page.last = last
for continued in [True, False]:
self.page.continued = continued
self.failUnlessEqual(self.page.first, first)
self.failUnlessEqual(self.page.last, last)
self.failUnlessEqual(self.page.continued, continued)
def test_flags_next_page(self):
page = OggPage(self.fileobj)
self.failIf(page.first)
self.failIf(page.continued)
self.failIf(page.last)
def test_length(self):
# Always true for Ogg Vorbis files
self.failUnlessEqual(self.page.size, 58)
self.failUnlessEqual(len(self.page.write()), 58)
def test_first_metadata_page_is_separate(self):
self.failIf(OggPage(self.fileobj).continued)
def test_single_page_roundtrip(self):
self.failUnlessEqual(
self.page, OggPage(BytesIO(self.page.write())))
def test_at_least_one_audio_page(self):
page = OggPage(self.fileobj)
while not page.last:
page = OggPage(self.fileobj)
self.failUnless(page.last)
def test_crappy_fragmentation(self):
packets = [b"1" * 511, b"2" * 511, b"3" * 511]
pages = OggPage.from_packets(packets, default_size=510, wiggle_room=0)
self.failUnless(len(pages) > 3)
self.failUnlessEqual(OggPage.to_packets(pages), packets)
def test_wiggle_room(self):
packets = [b"1" * 511, b"2" * 511, b"3" * 511]
pages = OggPage.from_packets(
packets, default_size=510, wiggle_room=100)
self.failUnlessEqual(len(pages), 3)
self.failUnlessEqual(OggPage.to_packets(pages), packets)
def test_one_packet_per_wiggle(self):
packets = [b"1" * 511, b"2" * 511, b"3" * 511]
pages = OggPage.from_packets(
packets, default_size=1000, wiggle_room=1000000)
self.failUnlessEqual(len(pages), 2)
self.failUnlessEqual(OggPage.to_packets(pages), packets)
def test_replace(self):
# create interleaved pages
fileobj = BytesIO()
pages = [OggPage(), OggPage(), OggPage()]
pages[0].serial = 42
pages[0].sequence = 0
pages[0].packets = [b"foo"]
pages[1].serial = 24
pages[1].sequence = 0
pages[1].packets = [b"bar"]
pages[2].serial = 42
pages[2].sequence = 1
pages[2].packets = [b"baz"]
for page in pages:
fileobj.write(page.write())
fileobj.seek(0, 0)
pages_from_file = [OggPage(fileobj), OggPage(fileobj),
OggPage(fileobj)]
old_pages = [pages_from_file[0], pages_from_file[2]]
packets = OggPage.to_packets(old_pages, strict=True)
self.assertEqual(packets, [b"foo", b"baz"])
new_packets = [b"1111", b"2222"]
#.........这里部分代码省略.........
示例15: test_invalid_not_first
# 需要导入模块: from mutagen.ogg import OggPage [as 别名]
# 或者: from mutagen.ogg.OggPage import write [as 别名]
def test_invalid_not_first(self):
page = OggPage(file(self.filename, "rb"))
page.first = False
self.failUnlessRaises(IOError, OggVorbisInfo, StringIO(page.write()))