当前位置: 首页>>代码示例>>Python>>正文


Python ogg.OggPage类代码示例

本文整理汇总了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)
开发者ID:badwtg1111,项目名称:kwplayer,代码行数:29,代码来源:oggflac.py

示例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)
开发者ID:badwtg1111,项目名称:mutagen,代码行数:7,代码来源:test_oggtheora.py

示例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))
开发者ID:badwtg1111,项目名称:mutagen,代码行数:7,代码来源: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(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)
开发者ID:jiuerd,项目名称:kwplayer,代码行数:32,代码来源:oggspeex.py

示例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)
开发者ID:badwtg1111,项目名称:mutagen,代码行数:8,代码来源:test_ogg.py

示例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)
开发者ID:badwtg1111,项目名称:mutagen,代码行数:8,代码来源:test_oggvorbis.py

示例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)
开发者ID:badwtg1111,项目名称:mutagen,代码行数:8,代码来源:test_oggvorbis.py

示例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)
开发者ID:badwtg1111,项目名称:kwplayer,代码行数:9,代码来源:oggopus.py

示例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()))
开发者ID:badwtg1111,项目名称:mutagen,代码行数:11,代码来源:test_oggopus.py

示例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)))
开发者ID:badwtg1111,项目名称:mutagen,代码行数:14,代码来源:test_ogg.py

示例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)))
开发者ID:badwtg1111,项目名称:mutagen,代码行数:15,代码来源:test_ogg.py

示例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)
开发者ID:badwtg1111,项目名称:mutagen,代码行数:7,代码来源:test_ogg.py

示例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)
开发者ID:badwtg1111,项目名称:mutagen,代码行数:13,代码来源:test_ogg.py

示例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)
开发者ID:badwtg1111,项目名称:mutagen,代码行数:8,代码来源:test_ogg.py

示例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
开发者ID:badwtg1111,项目名称:mutagen,代码行数:17,代码来源:test_ogg.py


注:本文中的mutagenx.ogg.OggPage类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。