+
+def _extract_image_timestamp(file_path):
+ time = None
+ try:
+ with PIL.Image.open(file_path) as image:
+ exif = image._getexif()
+ if exif and 36867 in exif:
+ time = datetime.datetime\
+ .strptime(exif[36867], '%Y:%m:%d %H:%M:%S')\
+ .timestamp()
+ except Exception as e:
+ logging.warn("Error extracting exif for %s: %s", file_path, str(e))
+ return time
+
+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