Inspired by this post on Apple Photos internal SQLite database I decided to have a play around with using Apple Photos for my own photos.

I’d never used it on the Mac before (only on iPhone).
I manage all my photos in a custom Java app that I started writing in 2001 (and have only partially rewritten twice since).
I’m quite happy with my setup, but I also like the idea of analysing my photos and adding facial recognition to my data.

Adding my photos

Initially I had to import my photos into Apple Photos. To do this I wrote some code in my app to dump all the large size image files to a nested directory structure.
Then I imported the lot into Apple Photos (making sure that the “Copy items to the Photos library” option was unchecked).
After that I needed to wait a few days for Apple Photos to analyse my photos.
I also manually trained it to recognise some of the people in my photos.

Exporting the JSON file

After Apple Photos had finished analysing my photos I then used RhetTbull/osxphotos to export a JSON file.

$ osxphotos dump --json | jq . > osxphotos.json

Processing the JSON file

Finally, I wrote some code in my app to process the exported file.
I used the path value in the json file to match the Apple Photos data against the entries in my database.
Then I looked for the following fields to add to my data.

{
    "persons": [
      "Darren Greaves"
    ],
    "labels": [
      "Clothing",
      "People",
      "Adult"
    ],
    "score": {
      "overall": 0.42578125,
    }
}

There’s probably other interesting data in there but that’s all I am looking at for now.

I then added new columns to my database and got them indexed by the search engine that I use, and I added some code to display the new data in the frontend.
I also added some nice touches whereby I could put things like “Stephen and Darren” in the auto-generated photo titles, or “Darren and Friends” if I’m with people who haven’t been recognised yet.

Keeping it updated

The last part to this is keeping the data updated.
I have a monthly reminder to add any new photos and run a new export.
It’s always worth processing a full export as the software might now recognise new people etc.

Things that could be improved

Sadly there doesn’t seem to be a good way to handle deleted photos from Apple Photos.
Sometimes I do cleanups and remove/rename old photos.
Apple Photos doesn’t give me an easy way to remove deleted files from its data.
I’m not sure it actually matters as such - it’s just nice to keep the data clean.