BUG:Google Takeout photos with duplicate or long names lose their date and location
I noticed that PictoPy fails to read the JSON metadata for some photos imported from Google Takeout.
This happens mainly when a photo has a duplicate name or a long filename.
For example, when Google Takeout renames a duplicate photo, the names can look like this:
Photo: IMG_0002(1).jpg JSON: IMG_0002.jpg(1).json
Another format is:
Photo: IMG_0003(1).jpg JSON: IMG_0003.jpg.supplemental-metadata(1).json
The same problem happens with long filenames because Google Takeout can shorten the JSON filename.
PictoPy currently looks for a JSON filename starting with the full image name, so it misses these files.
As a result, the photo's original date and GPS location are not read correctly.
Where the problem is
In backend/app/utils/takeout_sidecar.py:
directory, basename = os.path.split(image_path) prefix = basename + "." for name in _sidecar_names(directory or "."): if not name.startswith(prefix): continue
The comment above this code mentions handling .supplemental-metadata(1).json, but the check still fails when the image itself has (1) in its filename.
Steps to reproduce
Save this as takeout_names.py:
import json, os, sys, tempfile sys.path.insert(0, sys.argv[1])
from app.utils.takeout_sidecar import takeout_sidecar_read
d = tempfile.mkdtemp()
def make(image, sidecar, ts): open(os.path.join(d, image), "wb").close() with open(os.path.join(d, sidecar), "w") as f: json.dump({ "title": image, "photoTakenTime": {"timestamp": str(ts)}, "geoData": { "latitude": 48.85, "longitude": 2.35 } }, f)
long_name = "PXL_20230615_101010123.PORTRAIT.ORIGINAL_long_name.jpg"
cases = [ ("normal", "IMG_0001.jpg", "IMG_0001.jpg.supplemental-metadata.json", 1600000000),
("duplicate, old style", "IMG_0002(1).jpg",
"IMG_0002.jpg(1).json", 1600000100),
("duplicate, new style", "IMG_0003(1).jpg",
"IMG_0003.jpg.supplemental-metadata(1).json", 1600000200),
("long name, truncated", long_name,
long_name[:46] + ".json", 1600000300),
]
for label, image, sidecar, ts in cases: make(image, sidecar, ts)
for label, image, sidecar, ts in cases: print(f"{label:22} -> {takeout_sidecar_read(os.path.join(d, image))}")
Run it using:
python takeout_names.py /path/to/PictoPy/backend
Output
normal -> ('2020:09:13 17:56:40', 48.85, 2.35) duplicate, old style -> (None, None, None) duplicate, new style -> (None, None, None) long name, truncated -> (None, None, None)
The normal filename works, but the other three fail to return the date and location.
Expected behavior
PictoPy should be able to find these JSON files even when Google Takeout changes or shortens their names.
I also found that GooglePhotosTakeoutHelper handles similar naming cases.
I'd like to work on this issue and add tests for it if the maintainers agree.
👋 Thanks for opening this issue! The maintainers will review it shortly. Till then, do not open any PR. This is a strict rule we like to follow around here :)
⚠️ Potential Duplicate Issue (Semantic Match)
This issue appears semantically similar to the following issues in AOSSIE-Org/PictoPy:
-
BUG: Add Duplicate and Near Duplicate Photo Detection and Management (#1510, open) https://github.com/AOSSIE-Org/PictoPy/issues/1510 Similarity: 59.1%
-
Feat:Import PictoPy metadata from PNG files during library indexing (#1638, closed) https://github.com/AOSSIE-Org/PictoPy/issues/1638 Similarity: 56.6%
-
Feat:No content-based duplicate image detection (same image added multiple times in DB) (#1069, closed) https://github.com/AOSSIE-Org/PictoPy/issues/1069 Similarity: 56.5%
Please review before proceeding.
This is a different issue. #1510 and #1069 are about photos being saved twice, and #1638 is about PNG metadata.
The issue I reported is about PictoPy not finding the JSON file that stores a photo's date and location. Google Takeout sometimes changes the JSON filename by moving (1) or making the name shorter. PictoPy then fails to find it, so the photo loses its date and location.
Link your account with Gitcord
Thanks for opening this issue, @soujasK!
To receive Discord notifications and contributor tracking for this organization:
- Join Discord: https://discord.gg/hjUhu33uAn
- In Discord, run
/link soujasK - Paste the verification code into your GitHub bio (or a public gist)
- Click Verify in Discord (or run
/verify-link soujasK)
Once linked, Gitcord can notify you about assignments, mentions, and more.
— Posted by Gitcord
Hi! I am interested in working on this issue. I can investigate the Google Takeout sidecar filename matching problem and add tests for duplicate and long filenames. I noticed the bot asks contributors to wait for maintainer review, so I will wait for approval before opening a PR. Thank you!
Hi @jeevanabhi-r, thanks for your interest!
I opened this issue after investigating the Google Takeout sidecar filename matching problem, and I’m planning to work on the fix myself.
I’m currently waiting for maintainer feedback before proceeding with a PR, as per the contribution guidelines.
Happy to coordinate if needed. Thanks!