+
+def _extract_image_timestamp(file_path):
+ with PIL.Image.open(file_path) as image:
+ exif = image._getexif()
+ if exif and 36867 in exif:
+ return datetime.datetime\
+ .strptime(exif[36867], '%Y:%m:%d %H:%M:%S')\
+ .timestamp()
+ return None
+
+def _extract_video_timestamp(file_path):
+ p = subprocess.run(['ffmpeg', '-i', file_path],
+ capture_output=True, encoding='UTF-8')
+ for line in p.stderr.splitlines():
+ m = re.search('^.*creation_time.*: ([^ ]+)$', line)
+ if m:
+ return datetime.datetime\
+ .strptime(m.group(1), '%Y-%m-%dT%H:%M:%S.%fZ')\
+ .timestamp()
+ return None