def readMetadataFile(datapath): numberOfMetadata = 0 listOfMetadata = [] f = open(datapath, "rb") done = False while done == False: allData = f.read(16) if (allData.find( b'\x00\x00\x06\x0e+4\x02\x0b\x01\x01\x0e\x01\x03\x01\x01') > 0): allData = b'\x06\x0e+4\x02\x0b\x01\x01\x0e\x01\x03\x01\x01\x00\x00\x00' length = f.read(4) else: length = f.read(1) allData += length length = bytes_to_int(length) if length >= 128: length -= 128 length *= 128 secondRead = f.read(1) allData += secondRead secondRead = bytes_to_int(secondRead) if secondRead >= 128: secondRead -= 128 length += secondRead allData += f.read(length) if allData == b"": done = True else: listOfMetadata.append(allData) numberOfMetadata += 1 f.close() global metadataRead metadataRead = True return listOfMetadata, numberOfMetadata
def __next__(self): key = self.__read(self.key_length) # TODO : HOTFIX for some videos, make better # in some videos the header not follow the correct pattern # Sample key: # b'\xdc\x00\x00\x06\x0e+4\x02\x0b\x01\x01\x0e\x01\x03\x01\x01' if key.find(KlvHeaderKey) > 0: key = UASLocalMetadataSet byte_length = bytes_to_int(self.__read(4)) else: byte_length = bytes_to_int(self.__read(1)) if byte_length < 128: # BER Short Form length = byte_length else: # BER Long Form length = bytes_to_int(self.__read(byte_length - 128)) # try: # value = self.__read(length) # except OverflowError: # value = self.__read(0) value = self.__read(length) return key, value
def __next__(self): key = self.__read(self.key_length) byte_length = bytes_to_int(self.__read(1)) if byte_length < 128: # BER Short Form length = byte_length else: # BER Long Form length = bytes_to_int(self.__read(byte_length - 128)) value = self.__read(length) return key, value
def __next__(self): key = self.__read(self.key_length) # TODO : HOTFIX for some videos, make better # in some videos the header not follow the correct pattern # Sample key: b'\xdc\x00\x00\x06\x0e+4\x02\x0b\x01\x01\x0e\x01\x03\x01\x01' if (key.find(b'\x00\x00\x06\x0e+4\x02\x0b\x01\x01\x0e\x01\x03\x01\x01') > 0): key = b'\x06\x0e+4\x02\x0b\x01\x01\x0e\x01\x03\x01\x01\x00\x00\x00' byte_length = bytes_to_int(self.__read(4)) else: byte_length = bytes_to_int(self.__read(1)) if byte_length < 128: # BER Short Form length = byte_length else: # BER Long Form length = bytes_to_int(self.__read(byte_length - 128)) value = self.__read(length) return key, value
def __init__(self, value): try: self.value = bytes_to_int(value) except TypeError: self.value = value