當前位置: 首頁>>代碼示例>>Python>>正文


Python OggPage.replace方法代碼示例

本文整理匯總了Python中mutagenx.ogg.OggPage.replace方法的典型用法代碼示例。如果您正苦於以下問題:Python OggPage.replace方法的具體用法?Python OggPage.replace怎麽用?Python OggPage.replace使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在mutagenx.ogg.OggPage的用法示例。


在下文中一共展示了OggPage.replace方法的7個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: _inject

# 需要導入模塊: from mutagenx.ogg import OggPage [as 別名]
# 或者: from mutagenx.ogg.OggPage import replace [as 別名]
    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,代碼行數:31,代碼來源:oggflac.py

示例2: _inject

# 需要導入模塊: from mutagenx.ogg import OggPage [as 別名]
# 或者: from mutagenx.ogg.OggPage import replace [as 別名]
    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,代碼行數:34,代碼來源:oggspeex.py

示例3: _inject

# 需要導入模塊: from mutagenx.ogg import OggPage [as 別名]
# 或者: from mutagenx.ogg.OggPage import replace [as 別名]
    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,代碼行數:11,代碼來源:oggopus.py

示例4: _inject

# 需要導入模塊: from mutagenx.ogg import OggPage [as 別名]
# 或者: from mutagenx.ogg.OggPage import replace [as 別名]
    def _inject(self, fileobj):
        """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)

        packets[0] = b"\x81theora" + self.write(framing=False)

        new_pages = OggPage.from_packets(packets, old_pages[0].sequence)
        OggPage.replace(fileobj, old_pages, new_pages)
開發者ID:badwtg1111,項目名稱:kwplayer,代碼行數:22,代碼來源:oggtheora.py

示例5: _inject

# 需要導入模塊: from mutagenx.ogg import OggPage [as 別名]
# 或者: from mutagenx.ogg.OggPage import replace [as 別名]
    def _inject(self, fileobj):
        """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)

        # Set the new comment packet.
        packets[0] = b"\x03vorbis" + self.write()

        new_pages = OggPage.from_packets(packets, old_pages[0].sequence)
        OggPage.replace(fileobj, old_pages, new_pages)
開發者ID:kouxulei,項目名稱:xyplayer-package,代碼行數:25,代碼來源:oggvorbis.py

示例6: test_streaminfo_bad_version

# 需要導入模塊: from mutagenx.ogg import OggPage [as 別名]
# 或者: from mutagenx.ogg.OggPage import replace [as 別名]
 def test_streaminfo_bad_version(self):
     page = OggPage(open(self.filename, "rb")).write()
     page = page.replace(b"\x01\x00", b"\x02\x00", 1)
     self.failUnlessRaises(IOError, OggFLACStreamInfo, io.BytesIO(page))
開發者ID:badwtg1111,項目名稱:mutagen,代碼行數:6,代碼來源:test_oggflac.py

示例7: test_streaminfo_bad_marker

# 需要導入模塊: from mutagenx.ogg import OggPage [as 別名]
# 或者: from mutagenx.ogg.OggPage import replace [as 別名]
 def test_streaminfo_bad_marker(self):
     page = OggPage(open(self.filename, "rb")).write()
     page = page.replace(b"fLaC", b"!fLa", 1)
     self.failUnlessRaises(IOError, OggFLACStreamInfo, io.BytesIO(page))
開發者ID:badwtg1111,項目名稱:mutagen,代碼行數:6,代碼來源:test_oggflac.py


注:本文中的mutagenx.ogg.OggPage.replace方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。