def __render_integer(self, key, value, min_bytes): assert min_bytes in (1, 2, 4, 8) data_list = [] try: for v in value: # We default to the int size of the usual values written # by itunes for compatibility. if cdata.int8_min <= v <= cdata.int8_max and min_bytes <= 1: data = cdata.to_int8(v) elif cdata.int16_min <= v <= cdata.int16_max and \ min_bytes <= 2: data = cdata.to_int16_be(v) elif cdata.int32_min <= v <= cdata.int32_max and \ min_bytes <= 4: data = cdata.to_int32_be(v) elif cdata.int64_min <= v <= cdata.int64_max and \ min_bytes <= 8: data = cdata.to_int64_be(v) else: raise MP4MetadataValueError("value out of range: %r" % value) data_list.append(data) except (TypeError, ValueError, cdata.error) as e: raise MP4MetadataValueError(e) return self.__render_data(key, 0, AtomDataType.INTEGER, data_list)
def __render_integer(self, key, value, min_bytes): assert min_bytes in (1, 2, 4, 8) data_list = [] try: for v in value: # We default to the int size of the usual values written # by itunes for compatibility. if cdata.int8_min <= v <= cdata.int8_max and min_bytes <= 1: data = cdata.to_int8(v) elif cdata.int16_min <= v <= cdata.int16_max and \ min_bytes <= 2: data = cdata.to_int16_be(v) elif cdata.int32_min <= v <= cdata.int32_max and \ min_bytes <= 4: data = cdata.to_int32_be(v) elif cdata.int64_min <= v <= cdata.int64_max and \ min_bytes <= 8: data = cdata.to_int64_be(v) else: raise MP4MetadataValueError( "value out of range: %r" % value) data_list.append(data) except (TypeError, ValueError, cdata.error) as e: raise MP4MetadataValueError(e) return self.__render_data(key, 0, AtomDataType.INTEGER, data_list)