本文整理汇总了Python中mutagen.ogg.OggPage类的典型用法代码示例。如果您正苦于以下问题:Python OggPage类的具体用法?Python OggPage怎么用?Python OggPage使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了OggPage类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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)
开发者ID:4everGhost,项目名称:PlexKodiConnect,代码行数:30,代码来源:oggvorbis.py
示例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))
开发者ID:Sophist-UK,项目名称:mutagen,代码行数:7,代码来源:test_ogg.py
示例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)
开发者ID:svetlio2,项目名称:hackbg,代码行数:26,代码来源:test_ogg.py
示例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)
开发者ID:Gimpson,项目名称:pytivo,代码行数:32,代码来源:oggspeex.py
示例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)
开发者ID:KirillMysnik,项目名称:Source.Python,代码行数:27,代码来源:oggtheora.py
示例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)
开发者ID:fourth-4,项目名称:mutagen,代码行数:29,代码来源:oggflac.py
示例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)
开发者ID:Shutshutnunte,项目名称:mutagen,代码行数:7,代码来源:test_oggtheora.py
示例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
开发者ID:quodlibet,项目名称:mutagen,代码行数:8,代码来源:test_ogg.py
示例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)
开发者ID:fourth-4,项目名称:mutagen,代码行数:8,代码来源:test_ogg.py
示例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)
开发者ID:akerbis,项目名称:mutagen,代码行数:8,代码来源:test_oggvorbis.py
示例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)
开发者ID:akerbis,项目名称:mutagen,代码行数:8,代码来源:test_oggvorbis.py
示例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)
开发者ID:Knio,项目名称:tag2itunes,代码行数:8,代码来源:test_oggvorbis.py
示例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)
开发者ID:Jbonnett,项目名称:Mutagen-flo,代码行数:8,代码来源:test_oggvorbis.py
示例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)
开发者ID:Begall,项目名称:headphones,代码行数:9,代码来源:oggopus.py
示例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)
开发者ID:quodlibet,项目名称:mutagen,代码行数:10,代码来源:test_ogg.py
示例16: test_unsupported_version
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()))
开发者ID:andrewboie,项目名称:discogstool,代码行数:11,代码来源:test_oggopus.py
示例17: 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 = map(random_file.read, lengths)
self.failUnlessEqual(packets, OggPage.to_packets(OggPage.from_packets(packets)))
开发者ID:hanvo,项目名称:MusicCloud,代码行数:11,代码来源:test_ogg.py
示例18: 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(BytesIO(page.write()))
data[8] = 0x10
page.packets[0] = bytes(data)
self.failUnlessRaises(IOError, OggOpusInfo, BytesIO(page.write()))
开发者ID:svetlio2,项目名称:hackbg,代码行数:11,代码来源:test_oggopus.py
示例19: main
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()
开发者ID:YipYup,项目名称:headphones,代码行数:49,代码来源:moggsplit.py
示例20: 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 = BytesIO(bytearray().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)))
开发者ID:Sophist-UK,项目名称:mutagen,代码行数:15,代码来源:test_ogg.py
注:本文中的mutagen.ogg.OggPage类示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论