本文整理汇总了Python中mutagen._util.BitReader.get_position方法的典型用法代码示例。如果您正苦于以下问题:Python BitReader.get_position方法的具体用法?Python BitReader.get_position怎么用?Python BitReader.get_position使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类mutagen._util.BitReader
的用法示例。
在下文中一共展示了BitReader.get_position方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_get_position
# 需要导入模块: from mutagen._util import BitReader [as 别名]
# 或者: from mutagen._util.BitReader import get_position [as 别名]
def test_get_position(self):
r = BitReader(cBytesIO(b"\xAB\xCD"))
self.assertEqual(r.get_position(), 0)
r.bits(3)
self.assertEqual(r.get_position(), 3)
r.skip(9)
self.assertEqual(r.get_position(), 3 + 9)
r.align()
self.assertEqual(r.get_position(), 16)
示例2: __init__
# 需要导入模块: from mutagen._util import BitReader [as 别名]
# 或者: from mutagen._util.BitReader import get_position [as 别名]
def __init__(self, fileobj, length):
"""Raises DescriptorError"""
r = BitReader(fileobj)
try:
self.objectTypeIndication = r.bits(8)
self.streamType = r.bits(6)
self.upStream = r.bits(1)
self.reserved = r.bits(1)
self.bufferSizeDB = r.bits(24)
self.maxBitrate = r.bits(32)
self.avgBitrate = r.bits(32)
if (self.objectTypeIndication, self.streamType) != (0x40, 0x5):
return
# all from here is optional
if length * 8 == r.get_position():
return
tag = r.bits(8)
except BitReaderError as e:
raise DescriptorError(e)
if tag == DecoderSpecificInfo.TAG:
assert r.is_aligned()
self.decSpecificInfo = DecoderSpecificInfo.parse(fileobj)
示例3: find_stream
# 需要导入模块: from mutagen._util import BitReader [as 别名]
# 或者: from mutagen._util.BitReader import get_position [as 别名]
def find_stream(cls, fileobj, max_bytes):
"""Returns a possibly valid _ADTSStream or None.
Args:
max_bytes (int): maximum bytes to read
"""
r = BitReader(fileobj)
stream = cls(r)
if stream.sync(max_bytes):
stream.offset = (r.get_position() - 12) // 8
return stream
示例4: test_align
# 需要导入模块: from mutagen._util import BitReader [as 别名]
# 或者: from mutagen._util.BitReader import get_position [as 别名]
def test_align(self):
r = BitReader(cBytesIO(b"\xAB\xCD\xEF"))
r.skip(3)
self.assertEqual(r.align(), 5)
self.assertEqual(r.get_position(), 8)
示例5: __init__
# 需要导入模块: from mutagen._util import BitReader [as 别名]
# 或者: from mutagen._util.BitReader import get_position [as 别名]
def __init__(self, fileobj):
"""Raises HeaderNotFoundError"""
self.frame_offset = fileobj.tell()
r = BitReader(fileobj)
try:
if r.bits(11) != 0x7ff:
raise HeaderNotFoundError("invalid sync")
version = r.bits(2)
layer = r.bits(2)
protection = r.bits(1)
bitrate = r.bits(4)
sample_rate = r.bits(2)
padding = r.bits(1)
r.skip(1) # private
self.mode = r.bits(2)
r.skip(6)
except BitReaderError:
raise HeaderNotFoundError("truncated header")
assert r.get_position() == 32 and r.is_aligned()
# try to be strict here to redice the chance of a false positive
if version == 1 or layer == 0 or sample_rate == 0x3 or \
bitrate == 0xf or bitrate == 0:
raise HeaderNotFoundError("invalid header")
self.channels = 1 if self.mode == MONO else 2
self.version = [2.5, None, 2, 1][version]
self.layer = 4 - layer
self.protected = not protection
self.padding = bool(padding)
self.bitrate = self.__BITRATE[(self.version, self.layer)][bitrate]
self.bitrate *= 1000
self.sample_rate = self.__RATES[self.version][sample_rate]
if self.layer == 1:
frame_size = 384
slot = 4
elif self.version >= 2 and self.layer == 3:
frame_size = 576
slot = 1
else:
frame_size = 1152
slot = 1
frame_length = (
((frame_size // 8 * self.bitrate) // self.sample_rate) +
padding) * slot
self.sketchy = True
# Try to find/parse the Xing header, which trumps the above length
# and bitrate calculation.
if self.layer == 3:
self._parse_vbr_header(fileobj, self.frame_offset, frame_size,
frame_length)
fileobj.seek(self.frame_offset + frame_length, 0)