Last active
August 14, 2023 20:14
-
-
Save kevincox/0f2147309aa25347dff2d03b0f9d05ca to your computer and use it in GitHub Desktop.
Update media timestamps in Facebook Messenger Download
This file contains hidden or 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
#!/usr/bin/env python3 | |
import datetime | |
import glob | |
import json | |
import subprocess | |
for f in glob.glob("messages/*/*/message_*.json"): | |
print(f) | |
d = json.load(open(f)) | |
for m in d["messages"]: | |
for p in m.get("gifs", []) + m.get("photos", []) + m.get("videos", []): | |
path = p.get("uri") | |
if path.startswith("http"): | |
continue | |
ts = p.get("creation_timestamp") | |
if not ts: | |
continue | |
dt = datetime.datetime.fromtimestamp(ts) | |
print(p) | |
subprocess.run([ | |
"exiftool", | |
"-overwrite_original", | |
f"-DateTimeOriginal={dt.isoformat()}", | |
path, | |
]) |
This file contains hidden or 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
#!/usr/bin/env python3 | |
import datetime | |
import glob | |
import json | |
import subprocess | |
timestamps = {} | |
def register_timestamp(path, ts): | |
dt = datetime.datetime.fromtimestamp(ts) | |
prev = timestamps.get(path) | |
if prev and prev <= dt: | |
return | |
timestamps[path] = dt | |
for a in glob.glob("posts/album/*.json"): | |
j = json.load(open(a)) | |
for p in j["photos"]: | |
path = p["uri"] | |
ts = p["creation_timestamp"] | |
register_timestamp(path, ts) | |
for f in glob.glob("posts/your_posts_*.json"): | |
for p in json.load(open(f)): | |
for a in p.get("attachments", ()): | |
for d in a["data"]: | |
m = d.get("media") | |
if not m: | |
continue | |
path = m["uri"] | |
ts = m["creation_timestamp"] | |
register_timestamp(path, ts) | |
your_photos = json.load(open("posts/your_uncategorized_photos.json"))["other_photos_v2"] | |
your_videos = json.load(open("posts/your_videos.json"))["videos_v2"] | |
for v in your_photos + your_videos: | |
path = v["uri"] | |
ts = v["creation_timestamp"] | |
register_timestamp(path, ts) | |
for path, dt in timestamps.items(): | |
print(dt, path) | |
subprocess.run([ | |
"exiftool", | |
"-overwrite_original", | |
f"-DateTimeOriginal={dt.isoformat()}", | |
path, | |
]) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment