本文整理汇总了Python中mutagen.ogg.OggPage类的典型用法代码示例。如果您正苦于以下问题:Python OggPage类的具体用法?Python OggPage怎么用?Python OggPage使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了OggPage类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: _inject
def _inject(self, fileobj, padding_func):
"""Write tag data into the Vorbis comment packet/page."""
# Find the old pages in the file; we'll need to remove them,
# plus grab any stray setup packet data out of them.
fileobj.seek(0)
page = OggPage(fileobj)
while not page.packets[0].startswith(b"\x03vorbis"):
page = OggPage(fileobj)
old_pages = [page]
while not (old_pages[-1].complete or len(old_pages[-1].packets) > 1):
page = OggPage(fileobj)
if page.serial == old_pages[0].serial:
old_pages.append(page)
packets = OggPage.to_packets(old_pages, strict=False)
content_size = get_size(fileobj) - len(packets[0]) # approx
vcomment_data = b"\x03vorbis" + self.write()
padding_left = len(packets[0]) - len(vcomment_data)
info = PaddingInfo(padding_left, content_size)
new_padding = info._get_padding(padding_func)
# Set the new comment packet.
packets[0] = vcomment_data + b"\x00" * new_padding
new_pages = OggPage._from_packets_try_preserve(packets, old_pages)
OggPage.replace(fileobj, old_pages, new_pages)
示例2: test_to_packets
def test_to_packets(self):
self.failUnlessEqual(
[b"foo", b"bar", b"baz"], OggPage.to_packets(self.pages))
self.pages[0].complete = False
self.pages[1].continued = True
self.failUnlessEqual(
[b"foobar", b"baz"], OggPage.to_packets(self.pages))
示例3: test_crc_py25
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)
示例4: _inject
def _inject(self, fileobj):
"""Write tag data into the Speex comment packet/page."""
fileobj.seek(0)
# Find the first header page, with the stream info.
# Use it to get the serial number.
page = OggPage(fileobj)
while not page.packets[0].startswith("Speex "):
page = OggPage(fileobj)
# Look for the next page with that serial number, it'll start
# the comment packet.
serial = page.serial
page = OggPage(fileobj)
while page.serial != serial:
page = OggPage(fileobj)
# Then find all the pages with the comment packet.
old_pages = [page]
while not (old_pages[-1].complete or len(old_pages[-1].packets) > 1):
page = OggPage(fileobj)
if page.serial == old_pages[0].serial:
old_pages.append(page)
packets = OggPage.to_packets(old_pages, strict=False)
# Set the new comment packet.
packets[0] = self.write(framing=False)
new_pages = OggPage.from_packets(packets, old_pages[0].sequence)
OggPage.replace(fileobj, old_pages, new_pages)
示例5: _inject
def _inject(self, fileobj, padding_func):
"""Write tag data into the Theora comment packet/page."""
fileobj.seek(0)
page = OggPage(fileobj)
while not page.packets[0].startswith(b"\x81theora"):
page = OggPage(fileobj)
old_pages = [page]
while not (old_pages[-1].complete or len(old_pages[-1].packets) > 1):
page = OggPage(fileobj)
if page.serial == old_pages[0].serial:
old_pages.append(page)
packets = OggPage.to_packets(old_pages, strict=False)
content_size = get_size(fileobj) - len(packets[0]) # approx
vcomment_data = b"\x81theora" + self.write(framing=False)
padding_left = len(packets[0]) - len(vcomment_data)
info = PaddingInfo(padding_left, content_size)
new_padding = info._get_padding(padding_func)
packets[0] = vcomment_data + b"\x00" * new_padding
new_pages = OggPage._from_packets_try_preserve(packets, old_pages)
OggPage.replace(fileobj, old_pages, new_pages)
示例6: _inject
def _inject(self, fileobj):
"""Write tag data into the FLAC Vorbis comment packet/page."""
# Ogg FLAC has no convenient data marker like Vorbis, but the
# second packet - and second page - must be the comment data.
fileobj.seek(0)
page = OggPage(fileobj)
while not page.packets[0].startswith(b"\x7FFLAC"):
page = OggPage(fileobj)
first_page = page
while not (page.sequence == 1 and page.serial == first_page.serial):
page = OggPage(fileobj)
old_pages = [page]
while not (old_pages[-1].complete or len(old_pages[-1].packets) > 1):
page = OggPage(fileobj)
if page.serial == first_page.serial:
old_pages.append(page)
packets = OggPage.to_packets(old_pages, strict=False)
# Set the new comment block.
data = self.write()
data = bytes((packets[0][0],)) + struct.pack(">I", len(data))[-3:] + data
packets[0] = data
new_pages = OggPage.from_packets(packets, old_pages[0].sequence)
OggPage.replace(fileobj, old_pages, new_pages)
示例7: test_theora_bad_version
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)
示例8: test_find_last_single_muxed
def test_find_last_single_muxed(self):
page1 = OggPage()
page1.last = True
page2 = OggPage()
page2.serial = page1.serial + 1
pages = [page1, page2]
data = BytesIO(b"".join([page.write() for page in pages]))
assert OggPage.find_last(data, page2.serial).serial == page2.serial
示例9: test_too_many_packets
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)
示例10: test_underestimated_bitrate
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)
示例11: test_negative_bitrate
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)
示例12: test_overestimated_bitrate
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)
示例13: test_avg_bitrate
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)
示例14: _inject
def _inject(self, fileobj):
fileobj.seek(0)
info = OggOpusInfo(fileobj)
old_pages = self.__get_comment_pages(fileobj, info)
packets = OggPage.to_packets(old_pages)
packets[0] = "OpusTags" + self.write(framing=False)
new_pages = OggPage.from_packets(packets, old_pages[0].sequence)
OggPage.replace(fileobj, old_pages, new_pages)
示例15: test_renumber_reread
def test_renumber_reread(self):
try:
filename = get_temp_copy(
os.path.join(DATA_DIR, "multipagecomment.ogg"))
with open(filename, "rb+") as fileobj:
OggPage.renumber(fileobj, 1002429366, 20)
with open(filename, "rb+") as fileobj:
OggPage.renumber(fileobj, 1002429366, 0)
finally:
os.unlink(filename)