Google Photos API for export (and one day, an Ubuntu screensaver?)

tldr: I recently wanted to create a screensaver showing all my Google Photos photos on my Ubuntu Linux machine. The screensaver part is a WIP but it mostly works and wasn’t as gnarly as I feared. The code is at https://github.com/daveagp/google-photos-api-python-quickstart

Once upon a time, in early January 2001, I got a digital camera. I am not an avid photographer but over time my collection of photos grew, and I’d keep exporting them from the camera(s) I had over time onto my hard drive in a reasonably-organized set of Year/Month/Day folders and subfolders.

Checking in 23 years later,

  • At some point Picasa was an important part of my photo organizing routine. It’s now obsolete but I was reminded of it due to vestigial albums in Google Photos. Thank you for your service!
  • I started using my cell phone to take photos around 2014, and it’s now my primary camera (with the last notable exceptions being long overseas trips such as Iran and the Inca Trail).
  • I use Google phones (e.g. Nexus, Pixel), and these automatically back up photos to Google Photos. For a while I would download new pictures periodically from Google Photos to my hard drive, but I stopped this a few years ago.

So Google Photos has become where things live by default. Even though I am probably more-skeptical-than-average of Big Tech than most Google engineers, I found the tradeoff pretty good: I can share and edit photos easily both on my laptop and phone; it loads location data in a helpful way; is searchable by text (e.g. I can look for “cows”) and it sometimes re-surfaces old memories in the phone app in a nice way.

What’s new: I recently relocated my Ubuntu desktop into a part of my house where I thought it would be nice to turn my photos into a screensaver (it feels like there is not as much point in keeping all these photos around if nobody ever sees them). Could I be lucky enough that there’s some pre-developed Linux things to make Google Photos into your screensaver?

There doesn’t seem to be anything that works fully out of the box and so I dug in a little bit to see if I could jury-rig enough things together to accomplish this goal. I’ve assumed it makes the most sense to break this into two steps: (1) download photos to my machine, (2) configure a screensaver. To my surprise,

So as a result I do have something to do the #1/download step, while #2/screensaver is really just a command where I manually start the random photo slideshow whenever I am done using my computer. Not the fanciest technology, but it felt like a pretty good accomplishment. At https://github.com/daveagp/google-photos-api-python-quickstart I am keeping the actual software that does this.

In the spirit of “Falsehoods Programmers Believe about $X“, I think the most interesting callout on the details of putting it together has to do with getting dates right. I wanted the screensaver to overlay the photo’s date as a means to try to be able to figure out the context for each photo.

Google Photos puts a date on every photo, so this should be easy, right?

  • Well, the screensaver will just read .jpg files, not connect to Google Photos API, but I can use EXIF metadata embedded in most .jpg files, right? This seems like it should just work out of the box.
  • Oh, sometimes a .jpg doesn’t have an EXIF. So I have to sometimes use the Google Photos date. They do return it in the photo metadata, so when the EXIF date is missing, I can just copy it in and should be done?
  • Oh, sometimes the EXIF date makes no sense (e.g. is years in the future). So I can just detect that case of dates far apart and use the Google Photos date instead, right?
  • Oh, sometimes the EXIF date is 0000-00-00, which doesn’t parse in all tools. So I can also detect that case and should be done, right?
  • The final problem is timezones. Modern EXIFs allow handling for timezones and your phone probably does the right thing for photos it takes. But older pictures or ones imported from non-GPS-having cameras give problems: there may be no EXIF date in the jpg, but Google Photos does some invisible selection of a time zone that it does not surface in the API. So I use EXIF dates mostly, and accept by hard-coding a single time zone in my program, that some handful of my non-EXIF-having photos show a different-by-1 date in Google Photos than in my screensaver.

Nonetheless I feel pretty good about declaring temporary victory and it helped motivate me to review and clean up about 10k photos (with another ~10k to go). Please enjoy the following cow from my archives:

Published by

daveagp

A 1980s Torontonian

Leave a comment

This site uses Akismet to reduce spam. Learn how your comment data is processed.