本文整理汇总了Python中mutagen.flac.MetadataBlock.group_padding方法的典型用法代码示例。如果您正苦于以下问题:Python MetadataBlock.group_padding方法的具体用法?Python MetadataBlock.group_padding怎么用?Python MetadataBlock.group_padding使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类mutagen.flac.MetadataBlock
的用法示例。
在下文中一共展示了MetadataBlock.group_padding方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: get_header
# 需要导入模块: from mutagen.flac import MetadataBlock [as 别名]
# 或者: from mutagen.flac.MetadataBlock import group_padding [as 别名]
def get_header(self, filename=None):
f = self.fileobj
f.seek(0)
# Ensure we've got padding at the end, and only at the end.
# If adding makes it too large, we'll scale it down later.
self.metadata_blocks.append(Padding("\x00" * 1020))
MetadataBlock.group_padding(self.metadata_blocks)
header = self.__check_header(f)
# "fLaC" and maybe ID3
available = self.__find_audio_offset(f) - header
data = MetadataBlock.writeblocks(self.metadata_blocks)
if len(data) > available:
# If we have too much data, see if we can reduce padding.
padding = self.metadata_blocks[-1]
newlength = padding.length - (len(data) - available)
if newlength > 0:
padding.length = newlength
data = MetadataBlock.writeblocks(self.metadata_blocks)
assert len(data) == available
elif len(data) < available:
# If we have too little data, increase padding.
self.metadata_blocks[-1].length += available - len(data)
data = MetadataBlock.writeblocks(self.metadata_blocks)
assert len(data) == available
self.__offset = len("fLaC" + data)
return "fLaC" + data
示例2: test_group_padding
# 需要导入模块: from mutagen.flac import MetadataBlock [as 别名]
# 或者: from mutagen.flac.MetadataBlock import group_padding [as 别名]
def test_group_padding(self):
blocks = [Padding("\x00" * 20), Padding("\x00" * 30),
MetadataBlock("foobar")]
blocks[-1].code = 0
length1 = len(MetadataBlock.writeblocks(blocks))
MetadataBlock.group_padding(blocks)
length2 = len(MetadataBlock.writeblocks(blocks))
self.failUnlessEqual(length1, length2)
self.failUnlessEqual(len(blocks), 2)