本文整理汇总了Python中mutagen.flac.MetadataBlock类的典型用法代码示例。如果您正苦于以下问题:Python MetadataBlock类的具体用法?Python MetadataBlock怎么用?Python MetadataBlock使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了MetadataBlock类的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: get_header
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: __read_metadata_block
def __read_metadata_block(self, file):
byte = ord(file.read(1))
size = to_int_be(file.read(3))
try:
data = file.read(size)
if len(data) != size:
raise Exception("file said %d bytes, read %d bytes" % (size, len(data)))
block = self.METADATA_BLOCKS[byte & 0x7F](data)
except (IndexError, TypeError):
block = MetadataBlock(data)
block.code = byte & 0x7F
self.metadata_blocks.append(block)
else:
self.metadata_blocks.append(block)
if block.code == VCFLACDict.code:
if self.tags is None:
self.tags = block
else:
raise FLACVorbisError("> 1 Vorbis comment block found")
elif block.code == CueSheet.code:
if self.cuesheet is None:
self.cuesheet = block
else:
raise Exception("> 1 CueSheet block found")
elif block.code == SeekTable.code:
if self.seektable is None:
self.seektable = block
else:
raise Exception("> 1 SeekTable block found")
return (byte >> 7) ^ 1
示例3: test_group_padding
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)
示例4: test_write_read_max_size
def test_write_read_max_size(self):
class SomeBlock(MetadataBlock):
code = 255
max_data_size = 2 ** 24 - 1
block = SomeBlock(b"\x00" * max_data_size)
data = MetadataBlock._writeblock(block)
self.assertEqual(data[:4], b"\xff\xff\xff\xff")
header_size = 4
self.assertEqual(len(data), max_data_size + header_size)
block = SomeBlock(b"\x00" * (max_data_size + 1))
self.assertRaises(error, MetadataBlock._writeblock, block)
示例5: test_writeblocks
def test_writeblocks(self):
blocks = [Padding("\x00" * 20), Padding("\x00" * 30)]
self.failUnlessEqual(len(MetadataBlock.writeblocks(blocks)), 58)
示例6: test_change
def test_change(self):
b = MetadataBlock("foobar")
b.data = "quux"
self.failUnlessEqual(b.write(), "quux")
示例7: test_save_unknown_block
def test_save_unknown_block(self):
block = MetadataBlock("test block data")
block.code = 99
self.flac.metadata_blocks.append(block)
self.flac.save()
示例8: test_too_large_padding
def test_too_large_padding(self):
block = Padding()
self.assertEqual(
len(MetadataBlock._writeblocks([block], 0, 0, lambda x: 2 ** 24)),
2**24 - 1 + 4)