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


Python ogg.OggPage类代码示例

本文整理汇总了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)
开发者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


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