You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

59 lines
1.7 KiB

from datetime import datetime
import struct
import sys
def get_mov_dates(filename):
# borrowed from stackoverflow
# difference between Unix epoch and QuickTime epoch, in seconds
EPOCH_ADJUSTER = 2082844800
# open file and search for moov item
f = open(filename, "rb")
while 1:
atom_header =
if atom_header[4:8] == b'moov':
atom_size = struct.unpack(">I", atom_header[0:4])[0] - 8, 1)
except struct.error:
raise ValueError("no 'moov' header found in {}".format(filename))
# found 'moov', look for 'mvhd' and timestamps
atom_header =
if atom_header[4:8] == b'cmov':
print("moov atom is compressed")
elif atom_header[4:8] != b'mvhd':
print("expected to find 'mvhd' header")
else:, 1)
creation_date = struct.unpack(">I",[0]
modification_date = struct.unpack(">I",[0]
created = datetime.utcfromtimestamp(creation_date - EPOCH_ADJUSTER)
#modified = datetime.utcfromtimestamp(modification_date - EPOCH_ADJUSTER)
# print(created)
#return modified
return created
def get_date(path):
"""Returns a tuple of strings (y, m, d) where m and d are zero-padded
what expects"""
date = get_mov_dates(path)
y, m, d = [str(a).zfill(2) for a in [date.year, date.month,]]
return (y, m, d)
if __name__ == "__main__":
path = sys.argv[1]
date = get_date(path)