Skip to content

Instantly share code, notes, and snippets.

Created February 14, 2020 21:18
  • Star 2 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
Star You must be signed in to star a gist
What would you like to do?
Automatically Corrects Insta360 Studio Snapshot Dates according to the filename.
import os
import re
import datetime
import piexif
filepath = os.path.abspath(".")
# Find files with `screenshot` in the name.
files = [f for f in os.listdir(filepath) if "screenshot" in f and f.endswith(".jpg")]
for filename in files:
# Extract datetime
date_rex = r"(20\d\d)(\d\d)(\d\d)_(\d\d)(\d\d)(\d\d)"
date_ranges =, filename)
# Date
year =
month =
day =
# Time
hour =
minute =
second =
# date text
dt_text = f"{year}:{month}:{day} {hour}:{month}:{second}"
# Image file path
image_filepath = os.path.join(filepath, filename)
exif_dict = piexif.load(image_filepath)
print(exif_dict) # Before
exif_dict["0th"][piexif.ImageIFD.DateTime] = dt_text
exif_dict["Exif"][piexif.ExifIFD.DateTimeOriginal] = dt_text
print(exif_dict) # After
# Save new metadata
exif_bytes = piexif.dump(exif_dict)
piexif.insert(exif_bytes, image_filepath)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment