Exporting albums from Google Photos
In Google Photos, you can arrange photos in an album with text and maps to tell a story. Since all my photos are uploaded there, it's a very convenient place to write up and share trips I've gone on with family and friends. I think it's great, and have been using it for years, but it seems like not many folks have heard of this feature.
What I like the most is that it's not just a collection of images - it lets me tell a story. I can use maps to show where we went, and use the text to provide context to specific photos and collections of photos to illustrate the trip.
However, because this is Google, I'm nervous about them deciding to sunset it. Ideally my trip photo albums would be hosted on my own website, which would also let me collect them all in one place, link between them, customize the maps, and do all the other things that HTML affords.
Currently, it's not possible to export the albums including all their metadata with any official method I can find. Google Takeout and Download Album only exports the photos, and doesn't preserve any of the arrangement information like ordering, text or maps. The albums API only returns name and cover information, and no part of the API returns "enrichments" like text and locations, with no plans to add that. The page itself is minified Javascript, and saving it doesn't produce anything resembling HTML and CSS that I could put on my website.
Clearly, the solution is to write an exporter myself.
Goal
To recreate the photo album, I needed a minimum set of information from the album:
- Download links for every image in the album
- Text
- Location names, for single locations and both ends of the travel map
- The relative ordering of the above
And there's several things that would be useful to have too, but aren't required:
- Album name
- Date range of all the photos (displayed at the top of the album)
- File names of the images
- File format of the images, since they can also be video
- Size of the images, and the ability to resize them
- Latitude and longitude of the locations
And some code to turn the above information into a webpage.
Reverse Engineering
The first step was to see what data I could extract.
Initially it was rough going since my experience making sense of Javascript is limited, especially when it's minified. The first breakthrough was finding a data structure of nested lists that a friend recognized as a protobuf containing all the album data. I used beautifulsoup, regex and looking for the last ] to extract the data structure and write it to a json file for examination.
Once I had the data, the next step was to make sense of it.
Some things were easy, since they were right there in plain text: the name of the album, links to images in the album, or text I had added. Some things made sense with their neighbours, like a location name and the latitude/longitude for that location in the same sub list.
Others required a little more digging.
I saw several numbers like 1766970855000 or 1767035799000 which seemed like the right range to be unix timestamps. I checked, and they converted to times on Dec 29, 2025, which matched when photos in the album were taken. The suspiciously round number -28800000 was often in the same section, which corresponded to the timezone offset in milliseconds for my timezone (UTC-8 at the time).
Working back up from the details, I was able to figure out the overall structure of the data protobuf.
[
null,
[list of images],
"",
[album info],
[list of enrichments]
]
The album info contained the album name, the date range of the photos in it, and a bunch of fields related to sharing that wasn't relevant to me.
The list of images contained a sub-list for each image and video in the album, in a random order. Each image block contained the image URL, the image height & width, a stable random ID, and a lot of other information that I couldn't make sense of. Additionally, I found documentation about downloading images that explains how to resize the image, so I could download smaller images more suitable for websites. Sadly, this discarded the exif data, but I didn't need that.
The list of enrichments contained a sub list for each enrichment, regardless of type (text, location, map between two points). Fortunately, type-specific information was in an object with a consistent key (99218341) and marked with a number indicating what type of enrichment it was. Since the type-specific section was so small, it was easy to figure out the text, location names and latitude/longitude.
Let's look at what data I needed, and see how much I've found:
- 🗹 Download links for every image in the album
- 🗹 Text
- 🗹 Location names, for single locations and both ends of the travel map
- ☐ The relative ordering of the above
Looking pretty good!
Ordering
The last important piece of the puzzle was the ordering of the elements. Because enrichments and images were stored unsorted in separate arrays, I needed a way to reconstruct a complete ordering of how they were interleaved in the album.
Fortunately, every image and enrichment contained a dictionary with key 101428965 that always had a value like [0, "vdegbero06vv00000000004k"]. By creating a small album, reordering the items in it and seeing how the string changed, I determined that I could sort the string alphabetically and that gave me the same display order as the album. Success!
Now I had everything I needed:
- 🗹 Download links for every image in the album
- 🗹 Text
- 🗹 Location names, for single locations and both ends of the travel map
- 🗹 The relative ordering of the above
Missing data
Since I had found all the required data, let's see how much nice-to-have data I had also found:
- 🗹 Album name
- 🗹 Date range of all the photos (displayed at the top of the album)
- ☐ File names of the images
- ☐ File format of the images, since they can also be video
- 🗹 Size of the images, and the ability to resize them
- 🗹 Latitude/longitude of the locations
Pretty good!
The big miss was image names. I only had a base64 string as the image ID, and couldn't find the original filename anywhere. The ID doesn't correspond to anything in the official API that I could find, and even if I download the EXIF data it doesn't include the filename. This is pretty annoying for working with the resulting images, since they're all named a random 27 character alphanumeric string, so if you know how to get the real filename please let me know!
I also couldn't find a mimetype or file format for any of the images. To solve this, I used python-magic and Python's builtin mimetypes module to guess the format and figure out the extension. Since I know all the files are common image and video formats, this worked well enough to give every image a file extension.
While running this on real albums, I also learned that the protobuf only returns information for the first 300 images. (Possibly also only the first 300 enrichments but I don't have that many.) If I scroll down in the album on Google Photos I can see images past the 300th, but I couldn't find where or when it got that information. I tried watching the network tab in the browser while scrolling from the top but never caught the request where that was added. Since I only had one album with more than 300 images in it, I eventually just downloaded the last few images with takeout and added them manually.
- 🗷 Download links for every image in the album (usually)
- 🗹 Text
- 🗹 Location names, for single locations and both ends of the travel map
- 🗹 The relative ordering of the above
After doing all that, there's still a lot of data that I don't know what it means, but I had most of what I needed so I was comfortable ignoring the rest of it.
Rendering
Now that I had the data, I could render it into any format I liked.
I knew I wanted a website so I started by rendering it directly to HTML, but this had some problems. While I could re-render the album from the saved protobuf when I changed the HTML templates, I would lose any updates I had made to the content, such as changing the text or adding more images. It felt like a tight coupling between the content and the presentation.
At around the same time, I had been introduced to Lektor, a static site generator that PyCascades uses. I was considering switching my website to use it, and the feature that convinced me was Flow blocks.
Flow blocks let you define a model (such as image, text, map) for a set of data that is stored in markdown, and separately define a template for each model that is rendered when the site generates. Notably, you can mix and match many different flow blocks and flow block types on the same page. Using this, the album scraper can output a single file with all the images and enrichments in markdown, and Lektor can render that to HTML. This lets me adjust how I want maps and images to display as much as I want without losing changes to content.
So that's what I did! I redid my site using Lektor, defined models and templates for the different album components, and spent a while learning all the new things that CSS can do to make it display nicely - but that's a different project.
Result
I'm very happy with the result! I've now used my photos album exporter to export over a dozen albums from Google Photos to a new section on my website. The first couple took a while, as I worked out the bugs and tinkered with the layout, but now it's a pretty straightforward process. I still use Photos as an editor for new albums, since Lektor isn't well set up for that.
Photos-album-scraper was definitely written as a personal project. While I have a README with installation instructions and a robust --help message, there's minimal error checking and no guarantee it works on any version of Python but the latest (at time of my last album). There's no tests and given that the data I'm scraping can change at any time, I don't see much point in adding them. That said, I licensed it AGPL, and you're free to use any part of it you think would be useful. I hope someone else finds it useful, and good luck!