Fixing files from Google Photos via Takeout

Started by ExifShmexif, April 08, 2021, 02:03:56 AM

Previous topic - Next topic

ExifShmexif

I received such helpful advice from searching and reading this forum, and the tool itself is amazing, so first of all thank you to all, especially Phil and stargeek. And in some meagre fashion, I wanted to return something by writing up my experience for anyone moving files out of Google Photos via Takeout. Many of the commands here are collected from other posts on this forum, and I'm sure I'll get a few things wrong, but hopefully it'll be helpful.

This will be most useful for anyone who:

  • Has a lot of files to export from Photos
  • Has images from a variety of sources
  • Used the "original" quality storage option when saving images in Photos
  • Wants to recreate and file those images once downloaded
  • Uses Windows
  • ExifTool is already in your $path




Getting images out of Google Photos can be done in two ways.

  • Use takeout.google.com. This lets you download some or all of your photos via a zip file. You can export albums, or alternatively Takeout groups images by year into albums for you (these aren't real albums, they're only visible in takeout.) If you do this, each file will have an associated .json file, which contains the image's metadata (e.g. date it was taken, or which people are in the photo.)
  • Use get.google.com/albumarchive. This lets you download all images in an album -- so if your collection is small enough to add everything to an album, it's a one click download of everything.

I'll assume you're doing the first of these. Assuming you selected images from all years in your export, you'll see a set of folders each corresponding to a year. Note: if your collection is larger than 50GB, and you have multiple zips to download and expand I strongly recommend you combine these into one. Takeout doesn't ensure that the media file and associated json are in the same zip, so combining them will fix it.

For any edited file, Takeout also exports both the original and edited files. If you prefer to not have doubles in your collection, you can delete the edits with:

del /s /q *-edited.jpg

You'll also notice that the file creation date for your media has been updated to today. That's probably correct as Takeout sees it, but for media that doesn't have EXIF data with the create date in -- like MP4 files -- your viewing software will probably just use the creation date for ordering, and these files will appear in the wrong place. So, from the Takeout root directory:

exiftool -d "%s" -tagsfromfile %d%f.%e.json "-DateTimeOriginal<PhotoTakenTimeTimestamp" "-FileCreateDate<PhotoTakenTimeTimestamp" "-FileModifyDate<PhotoTakenTimeTimestamp" -overwrite_original -ext mp4 -ext jpg -r .

I've also read that geolocation data may need to be added back to the EXIF data from the JSON file. I didn't find that to be the case for me -- location data seemed intact for the files. But just in case, again from the root:

exiftool -tagsfromfile %d%f.%e.json -description -title "-gpslatitude<GeoDataLatitude" "-gpslatituderef<GeoDataLatitude" "-gpslongitude<GeoDataLongitude" "-gpslongituderef<GeoDataLongitude" ... -ext mp4 -ext jpg -r .

Then, time to get rid of the .json files:

del /s /q *.json

The next part depends on how you want to organise the files. If you want to just dump everything into a directory and let your viewer sort it out -- maybe something like Synology moments -- you're probably done. I personally wanted to organise the files a little better and recreate a directory structure with my best guess of which camera took the image. This has the advantage of helping you identify which photos came from a friend, or any other source.

exiftool "-directory<%d/${model;}" -r .

You also may know that some actions strip exif data, e.g. uploading an image and sending it via some messaging apps or social networks. Additionally, as mentioned, mp4 files generally don't have exif. So if you want to sort further, I found it helpful to sort by image size:

exiftool "-directory<%d/${ImageSize;}" .

.... which helped me identify and group together images that were saved from various sources, like screenshots or movies. (Note that this will save media from the same source in different folders for portrait and landscape, but it's not a big deal to put those together.)

(One final TODO here, is to find a way to edit creation date for files that don't have an associated json file or any exif data, but present the date in the filename, something like 20130602_175206.jpg or 2012-10-16 09.39.07.jpg.)




I hope this has been helpful in some way. Thanks again!

Phil Harvey

Thanks for this write-up.  I'm sure it will be useful for someone else who wants to do this.

- Phil
...where DIR is the name of a directory/folder containing the images.  On Mac/Linux/PowerShell, use single quotes (') instead of double quotes (") around arguments containing a dollar sign ($).

Nirmitlamed

Wanted to say thank you. It was helpful a lot!

Tyler

In this command:
exiftool -d "%s" -tagsfromfile %d%f.%e.json "-DateTimeOriginal<PhotoTakenTimeTimestamp" "-FileCreateDate<PhotoTakenTimeTimestamp" "-FileModifyDate<PhotoTakenTimeTimestamp" -overwrite_original -ext mp4 -ext jpg -r .

You mention mp4 and jpg but if there are any other extensions, what happens to those?

Phil Harvey

Files with other extensions will be ignored.

- Phil
...where DIR is the name of a directory/folder containing the images.  On Mac/Linux/PowerShell, use single quotes (') instead of double quotes (") around arguments containing a dollar sign ($).

ythiebault

Thanks a lot for your post, it helped me a lot !

I had to adapt it in order to upload an album to a photo book creator service. In case it would help someone else in a common situation:

# suffix used for edited files. Depend on the lang.
EDITED_FILE_SUFFIX="-edited"

# Replace original files by their edited version
for edited_file in *$EDITED_FILE_SUFFIX* ; do
    original_file=$(echo "$edited_file" | sed s/$EDITED_FILE_SUFFIX//g)
    rm "$original_file"
    mv -v "$edited_file" "./${original_file}"
done

# Convert .HEIC to .jpeg (for iphone/mac users)
for file in *.HEIC; do
    sips -s format jpeg "$file" --out "${file%.HEIC}.jpeg"
    mv -v "$file.json" "${file%.HEIC}.jpeg.json"
    rm $file
done

# Update metadata with exiftool
exiftool -d "%s" -tagsfromfile %f.%e.json "-DateTimeOriginal<PhotoTakenTimeTimestamp" "-FileCreateDate<PhotoTakenTimeTimestamp" "-FileModifyDate<PhotoTakenTimeTimestamp" -overwrite_original -ext jpg -ext jpeg -ext mp4 -ext mov .

Edi Nugroho

I tried the code above, i.e.
exiftool -d "%s" -tagsfromfile %d%f.%e.json "-DateTimeOriginal<PhotoTakenTimeTimestamp" "-FileCreateDate<PhotoTakenTimeTimestamp" "-FileModifyDate<PhotoTakenTimeTimestamp" -overwrite_original -ext mp4 -ext jpg -r .
but an error message was displayed: "Warning: Error opening file -xxxxnameOfFile".

What went wrong?

Phil Harvey

It looks like maybe you used something that looks like a dash but isn't.  This can happen if you cut-and-paste a command.  Use the dash (minus sign) on the keyboard for the leading dashes.

Or... Is this a .bat file?  If so, all % characters need to be doubled in ExifTool arguments.

- Phil
...where DIR is the name of a directory/folder containing the images.  On Mac/Linux/PowerShell, use single quotes (') instead of double quotes (") around arguments containing a dollar sign ($).

StarGeek

I strongly suggest double-checking to see if you actually need to do this. Google didn't remove any data when the file was uploaded, so the only problem is if data was entered on the website or if no data was there to begin with.

Run this command to look at all the date/time data. If there is already proper time stamps such as an already existing DateTimeOriginal, then you don't want to run the above command
exiftool -time:all -G1 -a -s file.jpg
* Did you read FAQ #3 and use the command listed there?
* Please use the Code button for exiftool code/output.
 
* Please include your OS, Exiftool version, and type of file you're processing (MP4, JPG, etc).

revo2wheels

Absolutely 100% a problem for most files from 500GB Download from Google photos takeout. I'm very grateful to the OP for this fix.