Apple Photos database import/sync

What are the plans (if any) for support of Apple Photos databases? I’ve recently come across two very interesting projects that can interrogate/export Apple Photos database and pictures and was curious if you were familiar with them or have any thoughts. The interesting thing to me is being able to leverage and extract the machine learning and tagging that Apple does on-device and then extract it into other databases. I would love to see Photostructure able to take all Apple Photos database information and incorporate into it’s own database either as a one-time import or a periodic sync. Thoughts?

Here’s the two projects I was referring to:

1 Like

Thanks for taking the time to share this! I saw Simon’s post when it was on hackernews, which pointed to osxphotos: both are excellent work.

(full disclosure: I’ve had some horrible experiences with Apple Photos corrupting my library ((several times!)), so personally, I don’t use it, but I understand the desire to not re-do any organization or curation work that people have done in other apps, which is why the next version pulls in Picasa and IPTC tags).

Caution: the following is me prattling on, rubber-ducky style.

Ideally there would be a way to plug in third party “curators” into PhotoStructure, so if someone wanted to incorporate new tags from different sources, they could.

The reason why I haven’t just pulled this all into PhotoStructure already is because, at least currently, the exact same code runs on all 5 different flavors of PhotoStructure, and my only runtime requirement for every PhotoStructure edition is Node.

Both of these projects require a Python 3 runtime (which, if I could make as a dependency, would help so many other things, especially with ML/AI related projects, but would be a bear to package into the already-large PhotoStructure for Desktops editions).

The other issue with curation is very similar to the problem with keyword and other metadata editing: when there are several “variants” for a given asset, which variant (just the “best”, or all of them?) should contribute to the final asset’s metadata?

Currently metadata tag values are “layered”: the variants are sorted given a set of heuristics, and for any given tag, the “best” variant with a value is the value for the asset.

Apple Photos doesn’t really de-dupe things (at least in my library) very well, so there is likely to be metadata in the photos library for more than one variant. I guess the layering strategy still makes sense in this case, as well?

In any case, osxphotos supports a one-time extraction of library metadata into sidecars. PhotoStructure already looks for and reads from these sidecars (and support for Title and Description are coming as well). So, if you’re willing to run osxphotos export ... --sidecar ..., the metadata that gets added to those sidecars will already make it’s way into your PhotoStructure library.

A couple beta users are already using osxphotos to feed PhotoStructure, fwiw.

For tags that aren’t added as sidecars: I’m already spinning up ExifTool to do metadata extraction: there could be 1 or more tools that are configured as a setting, that when given a path to a filename, returns a JSON object with N tags (like the ZOVERALLAESTHETICSCORE). I guess this could be translated into a star rating for photos, and labels could be interpreted as additional keywords, perhaps?

And thus concludes this rubber-ducky episode. Thanks for tuning in.

Aside from interrogating and incorporating the Mac Photos database info into PhotoStructure, it seems like I may be having trouble getting v1 beta 2 of PhotoStructure to even ingest the photos from the Mac Photos library.

I’ve already pointed PStrct to to the Mac Photos library. Did I miss something in the documentation about needing to manually export the photos (from Mac Photos app) so that PhotoStructure can see and process them?

No: it should “just work.”

PhotoStructure may need to be granted read access to your Photos library (via macOS’s permissions-by-app system). macOS is supposed to pop up a dialog saying “are you OK with PhotoStructure reading your Photos?”, but in practice, rendering this dialog is unfortunately hit-or-miss.

These settings can be checked (on Mojave, at least) via System Preferences > Security & Privacy > Privacy, and adding PhotoStructure to either the “Photos” or “Full Disk Access” sections.

(In general, it’s a good security practice to only give an app the minimal permissions it needs to do work, so just giving access to Photos should be sufficient for PhotoStructure)

So on Big Sur, PhotoStructure doesn’t appear in the ‘full disk access’ list, nor is it available to be added to the list, oddly.

It is listed under ‘Files and folders’, with all options checked, including ‘Removable volumes’ (a Mac Photos library I want to ingest is located there).

There are no entries in the ‘Photos’ section of ‘Security and Privacy’.

Really? Did you click padlock in the bottom-left of the dialog, and then click the “+” button in the bottom left of the application list? I was able to add PhotoStructure on my x64 Big Sur test mac just now (I had to navigate to Applications and pick PhotoStructure).

The Photos section, I believe, only shows the applications that macOS has detected trying to open your Photos library database.

PhotoStructure only imports files it finds in the Masters or Originals subdirectories in iPhoto or Apple Photos library directories, and it’s unclear whether just trying to read the contents of those directories trips the “Photos” permission gate.

Sorry this is such a hassle!

...macOS rant...

macOS has, by far, taken the most time to rejigger code signing, handle new permission gates, and in general not behave nicely out of all my supported OSes. And this is coming from an Apple Fanboy. It’s typical for macOS to say that it’s copied a file, but actually truncated it: PhotoStructure has file-operation-retries specifically for macOS, and then re-reads the file into a SHA to verify it actually did what it said it did. I’m actually re-installing Big Sur, again, because the last Big Sur update made my mac mini not bootable…

1 Like

Well, as I’m sure you were expecting, the app was there to add, I just wasn’t seeing it. I could blame it on allergies and all the eye rubbing I’ve been doing. But I actually think it’s because that window defaulted to sorting by date and I didn’t realize it. So PhotoStructure is now added to full access.

In adding it to the full disk access list I noticed something I’ve seen a couple times: after I or the system quits the app —as you have to do when changing Security & Privacy permissions— there’s a period of time right after when opening PhotoStructure the app gives an error indicating something to the effect of the database or library is in use – retry, quit, or chose another library. I’m guessing this is due to the app closing abruptly and the database not being shut down gracefully. Some minutes later (after ~4 restart attempts) the app seems to start just fine. But it could be a little disconcerting. My Photostructure library and target photos are on an external USB hard drive, if that matters (I can imagine it might).

One interesting thing I noticed right after starting the app after adding it to full disk access, is that it immediately started processing the directories that I had designated in preferences some hours ago during the past session, but that it hadn’t begun processing yet; for those hours in between it was still processing a network drive directory even though I had removed that from the target directories in preferences. I don’t know if the restart got it doing the directories and drive I wanted, or if it was the full disk permissions.

I’m glad you found the buttons: I’m pretty sure I’ve opened that privacy panel and not seen the plus/minus buttons, too!

(Did you know that holding down the option key when opening certain dialogs will expose advanced options?)

That’s about what I would expect.

When PhotoStructure starts a sync, it works through it’s list of directories to scan.

For each directory, there are two steps: scanning the directories for possible files to import and adding those paths to a to-do list, and remembering what the last-scanned directory was, in case it hasn’t finished scanning and it is restarted.

If a given directory had been scanned in the last day (this time period is configurable), it moves on to the next directory.

Did it find and import the photos and videos from your Photos library?

It seems as though it hasn’t. When looking in PhotoStructure at photos taken this year, there are only a few compared to hundreds of unique photos taken this year in that Mac Photos library. (PhotoStructure is definitely looking in and processing photos from that external drive, though, and also from the directory the Photos library file is in.)

So I’m not sure what to do next. I’ve tried restarting PhotoStructure, restarting the sync, removing the target directories saving then re-adding. Nothing seems to get it to look at that Mac Photos library file.

Update: based on the latest version’s features, and mentions that HEIC/HEIF now works without intervention on Macs, I was assuming PhotoStructure could import HEICs from Mac Photos. But based on this documentation page, maybe it can’t?

PhotoStructure doesn’t currently supportHEIC/HEIF format out of the box due to licensing. (Please tell Apple not to use a closed, patent-encumbered format for something as important as your photos!)
PhotoStructure | Why didn't my file get imported into my Library?

It can if you’re running v1.0.0 (which is still in beta, but it’s pretty stable: it’s what I run personally). Are you on v0.9?

I tried designating a new PhotoStructure library and restarting sync with just the directory with the Mac Photos library in the target directories, but still. I lick importing any photos from the Photos library.

Is the method to send logs still the same as it is in the documentation page? I also see that there’s now a feature in the ‘help’ menu for it, but nothing seems to happen.

1 Like

Yes: the one built into the help window and nav menu only sends the last hundred log entries, which typically isn’t enough for me to gather enough context to figure out what’s going on.

v1.0.0-beta.10 adds a new call to scandir from the main process, which should let macOS pop up the file access entitlements security dialog properly (hopefully!)