import struct from apev2 import Apev2 # apev2 spec: https://wiki.hydrogenaud.io/index.php?title=APEv2_specification # parse dates from XLastPlayed and XLastScheduled from SPL. by brainsmoke: # d=swap32(0x14a63351) # Y,M,D,h,m,s = 1980+(d>>25), (d>>21)&0xf, (d>>16)&0x1f, (d>>11)&0x1f, (d>>5)&0x3f, (d<<1)&0x3f # print(Y,M,D,h,m,s) # for swapping endianness of a binary package def swap32(i): return struct.unpack("I", i))[0] ape = Apev2.from_file('OMYG.apetag') for item in ape.tag.frames: key = item.item_key value = item.item_value # print(key, value) if key == 'XLastPlayed': hex = value.hex() for i in range(0, len(hex), 8): hex_chunk = "0x{}".format(hex[i: i+8]) d=swap32(int(hex_chunk, 16)) Y,M,D,h,m,s = 1980+(d>>25), (d>>21)&0xf, (d>>16)&0x1f, (d>>11)&0x1f, (d>>5)&0x3f, (d<<1)&0x3f print(Y,M,D,h,m,s)