Importing metadata from Google Picasa metadata.json

Started by Case_, April 26, 2024, 03:05:30 PM

Previous topic - Next topic

Case_

Apologies if this has been asked before, but I did try my best to search and didn't seem to come up with anything that would help.

I have a large number of photos that have been exported from the old Google Picasa web albums that eventually became Google Photos. These days, it seems that Google exports photos with individual .json files for each photo, so importing metadata is fairly straightforward and there are posts about this here.

The problem in my case is that there's a common metadata.json file for every single album that contains all the metadata for the entire album. The format is kinda as follows:

{
  "albumData": {
    "title": "Album title",
    "date": "Aug 5, 2007 7:03:54 AM",
    "access": "public",
    "description": "Album description",
    "location": "",
    "geoInfo": null
  },
  "media": [
    {
      "tags": [],
      "description": "Photo 1 description",
      "title": "IMG_1297.jpg",
      "people": [],
      "comments": [],
      "url": "https://....../IMG_1297.jpg",
      "geoInfo": {
        "latitude_": latitude,
        "longitude_": longitude,
        "altitude_": 0.0,
        "latitude_span_": latitude span,
        "longitude_span_": longitude span,
        "uninterpreted": null,
        "optional_0_": 27,
        "isMutable": true,
        "cachedSize": -1
      },
      "geoInfoExif": null,
      "imageViews": 0,
      "license": null
    },
    {
      "tags": [],
      "description": "Photo 2 description",
      "title": "IMG_1299.JPG",
      "people": [],
      "comments": [],
      "url": "https://....../IMG_1299.JPG",
      "geoInfo": {
        "latitude_": latitude,
        "longitude_": longitude,
        "altitude_": 0.0,
        "latitude_span_": latitude span,
        "longitude_span_": longitude span,
        "uninterpreted": null,
        "optional_0_": 27,
        "isMutable": true,
        "cachedSize": -1
      },
      "geoInfoExif": null,
      "imageViews": 102,
      "license": null
    }
  ]
}

The latitude and longitude (and their span counterparts) contain actual numerical values and the URL is/was also a valid full URL of the photo, I just removed/truncated them for the purpose of the example.

What I'm trying to do is somehow import the metadata into the photos, as most of them were entered only after the photos have been uploaded, meaning that while the photos themselves do include some basic metadata, the stuff like the GPS coordinates, tags and photo descriptions are missing, and going through all of the photos manually would probably take weeks.

Clearly the main issue here is to somehow pair the appropriate metadata section with the appropriate photo - the file names match as they are in the metadata file, but so far I've yet to manage to make ExifTool understand which metadata section is for which file. The best I've managed so far was to import the metadata for the first photo in the folder, but the one photo then contained all the metadata for all the photos in the folder instead of just the appropriate one.

Can anyone help or at least suggest something using some reasonably easy to use tools? Thank you!

Case_

Ok, with the help of a friend, I've finally managed to split the large metadata JSON file into individual JSONs for each photo using a simple Python (in Windows) script:

import json
import os
import sys

# Path to source JSON file
input_json_file = '.\\metadata.json'

# Path to output directory
output_directory = '.\\.'

# Open JSON file
with open(input_json_file, 'r', encoding='utf-8') as file:
    data = json.load(file)

# Go through all photos in section "media"
for item in data["media"]:
    # Name of the new file based on the photo filename
    new_filename = f"{item['title']}.json"
    output_path = os.path.join(output_directory, new_filename)
   
    # Write new JSON for each photo
    with open(output_path, 'w', encoding='utf-8') as outfile:
        json.dump(item, outfile, indent=4, ensure_ascii=False)

print("JSON files have been created.")

From there, it's simple enough to write the tags to the photos with something like (in my case):

exiftool -tagsfromfile %d%f.%e.json "-description<description" "-GPSLatitude<GeoInfoLatitude_" "-GPSLongitude<GeoInfoLongitude_" "-GPSAltitude<GeoInfoAltitude_" -overwrite_original -ext jpg -r .