Last active
December 10, 2021 16:21
-
-
Save RocAlayo/3f4fc0d42ed670428edb9507b87084db to your computer and use it in GitHub Desktop.
Script to fix exported metadata of images from google photos
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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