+def extract_timestamp(file_path, use_exif=False):
+ if use_exif:
+ try:
+ with PIL.Image.open(file_path) as image:
+ exif = image._getexif()
+ if exif and 36867 in exif:
+ return int( datetime.datetime
+ .strptime(exif[36867], '%Y:%m:%d %H:%M:%S')
+ .timestamp() )
+ except PIL.UnidentifiedImageError:
+ pass