本文整理汇总了Python中mutagenx.ogg.OggPage类的典型用法代码示例。如果您正苦于以下问题:Python OggPage类的具体用法?Python OggPage怎么用?Python OggPage使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了OggPage类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: _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)
示例2: 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 = io.BytesIO(page.write())
self.failUnlessRaises(IOError, OggTheoraInfo, fileobj)
示例3: 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))
示例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(b"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: 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)
示例6: 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(io.BytesIO(page.write()))
self.failUnlessEqual(info.bitrate, 65536)
示例7: 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(io.BytesIO(page.write()))
self.failUnlessEqual(info.bitrate, 0)
示例8: _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] = b"OpusTags" + self.write(framing=False)
new_pages = OggPage.from_packets(packets, old_pages[0].sequence)
OggPage.replace(fileobj, old_pages, new_pages)
示例9: test_unsupported_version
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(io.BytesIO(page.write()))
data[8] = 0x10
page.packets[0] = bytes(data)
self.failUnlessRaises(IOError, OggOpusInfo, io.BytesIO(page.write()))
示例10: test_random_data_roundtrip
def test_random_data_roundtrip(self):
try:
random_file = open("/dev/urandom", "rb")
except (IOError, OSError):
print("WARNING: Random data round trip test disabled.")
return
for i in range(10):
num_packets = random.randrange(2, 100)
lengths = [random.randrange(10, 10000)
for i in range(num_packets)]
packets = [random_file.read(l) for l in lengths]
self.failUnlessEqual(
packets, OggPage.to_packets(OggPage.from_packets(packets)))
示例11: test_renumber_muxed
def test_renumber_muxed(self):
pages = [OggPage() for i in range(10)]
for seq, page in enumerate(pages[0:1] + pages[2:]):
page.serial = 0
page.sequence = seq
pages[1].serial = 2
pages[1].sequence = 100
data = io.BytesIO(b"".join([page.write() for page in pages]))
OggPage.renumber(data, 0, 20)
data.seek(0)
pages = [OggPage(data) for i in range(10)]
self.failUnlessEqual(pages[1].serial, 2)
self.failUnlessEqual(pages[1].sequence, 100)
pages.pop(1)
self.failUnlessEqual([page.sequence for page in pages], list(range(20, 29)))
示例12: test_from_packets_position
def test_from_packets_position(self):
packets = [b"1" * 100000]
pages = OggPage.from_packets(packets)
self.failUnless(len(pages) > 1)
for page in pages[:-1]:
self.failUnlessEqual(-1, page.position)
self.failUnlessEqual(0, pages[-1].position)
示例13: test_read_max_size
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 = io.BytesIO(data)
self.failUnlessEqual(OggPage(fileobj), page)
self.failUnlessEqual(OggPage(fileobj), page2)
self.failUnlessRaises(EOFError, OggPage, fileobj)
示例14: test_find_last_no_serial
def test_find_last_no_serial(self):
pages = [OggPage() for i in range(10)]
for i, page in enumerate(pages):
page.sequence = i
data = io.BytesIO(b"".join([page.write() for page in pages]))
self.failUnless(OggPage.find_last(data, pages[0].serial + 1) is None)
示例15: test_renumber_reread
def test_renumber_reread(self):
try:
fd, filename = tempfile.mkstemp(suffix=".ogg")
os.close(fd)
shutil.copy(os.path.join("tests", "data", "multipagecomment.ogg"),
filename)
fileobj = open(filename, "rb+")
OggPage.renumber(fileobj, 1002429366, 20)
fileobj.close()
fileobj = open(filename, "rb+")
OggPage.renumber(fileobj, 1002429366, 0)
fileobj.close()
finally:
try:
os.remove(filename)
except OSError:
pass