Skip to content

Instantly share code, notes, and snippets.

@RocAlayo
Last active December 10, 2021 16:21
Show Gist options
  • Save RocAlayo/3f4fc0d42ed670428edb9507b87084db to your computer and use it in GitHub Desktop.
Save RocAlayo/3f4fc0d42ed670428edb9507b87084db to your computer and use it in GitHub Desktop.
Script to fix exported metadata of images from google photos
from os import path, system
import json
from datetime import datetime
f = open("./parse-files.txt", mode='r', encoding='utf-8')
# output = subprocess.check_output(f'exiftool -filename -r -if \'($filetype eq "JPG" or $filetype eq "JPEG") and (not $createdate) and (not $datetimeoriginal)\' . | grep "========" | sed "s/======== //gi"', shell=True, text=True)
for line in f:
file = line.replace("\n", "")
json_file_name = ""
if path.isfile(f'{file}.json'):
json_file_name = f'{file}.json'
elif path.isfile(file.replace("o.jpg", ".json")):
json_file_name = file.replace("o.jpg", ".json")
if json_file_name:
try:
json_file = json.load(open(json_file_name, 'r'))
date_time = datetime.fromtimestamp(int(json_file['photoTakenTime']['timestamp']))
time = date_time.strftime("%Y-%m-%d %H:%M:%S")
print(f'==> exiftool -all= "{file}"')
system(f'exiftool -all= "{file}"')
print(f'==> exiftool "-datetimeoriginal={time}" "{file}"')
system(f'exiftool "-datetimeoriginal={time}" "{file}"')
except ValueError as error:
print (file, error)
else:
print("NO -",file)
f.close()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment