Google Photos to Apple Photos - Some GPS Data Missing

Started by Google Do Lots of Evil, August 17, 2023, 02:00:42 AM

Previous topic - Next topic

Google Do Lots of Evil

Full Disclosure - after using the command line tool and getting the error message shown later below for all files, I decided to go what appeared to be the "ExifTool for Dummies" route and purchased Metadata Fixer which claims to be based on the Exif-Tool. That ran through all the photos and presented successful completion messages.

However upon then importing everything into Apple Photos, I see that GPS location data is missing for many photos, so I don't know if the tool even did anything at all. By creating smart albums I have noticed that all photos from one phone in particular - a Samsung SCH-I545 I owned several years ago - are missing GPS data. However photos from that phone in Google Photos do contain GPS data. There may be photos from some other phones that are missing data, I am not sure. I am sure however that the Samsung is the only phone that once imported into Apple Photos contains 0 GPS data.

1. Do you have any suggestions? I'm more than willing to learn to use the command line program.

2. Hopefully if i can fix the files I can reimport them into Apple Photos and it won't ignore them as duplicates but will instead add the GPS data?

Thanks!

Here are the errors I was getting when using the command line prompt.
======== /Users/johndoe/Dropbox/Personal/Takeout 5/Google Photos/Untitled(17)/0802181402d.jpg [2/1794]
Warning: Error opening file - /Users/johndoe/Dropbox/Personal/Takeout 5/Google Photos/Untitled(17)/0802181402d.jpg.json
Nothing changed in /Users/johndoe/Dropbox/Personal/Takeout 5/Google Photos/Untitled(17)/0802181402d.jpg

Google Do Lots of Evil

Upon further investigation I notice that even if I go to Google Photos and only download a single photo from the Samsung phone in question, the download contains no GPS data. So I have a feeling I am SOL with regard to all photos from this camera?

wywh

#2
Google Photos takeout cookbook for .jpg (movies need somewhat different commands). You can skip to #3-4 if everything looks OK.

1. Google Takeout > clear all and make a desired selection and download it.

https://takeout.google.com/

2. If the user has uploaded images with the same filename to the same Google Photos album, Google Takeout adds copy numbers like (2) to the wrong place in the .json sidecar. For example:

DSC00041(2).JPG
but the copy number is after the .JPG suffix in .json:
DSC00041.JPG(2).json

For exiftool to work, it needs to be:
DSC00041(2).JPG.json

In order to fix this, run the command:

exiftool -ext json -r -if '$Filename=~/(\.[^.]+)(\(\d+\)).json$$/i'  '-Filename<${Filename;s/(\.[^.]+)(\(\d+\)).json$/$2$1.json/}' .

https://exiftool.org/forum/index.php?topic=12882.msg69636#msg69636

Google truncates the length of the .json filenames to something like 30 or so characters or something along those lines. So you'll have to deal with those separately.

0-02-0a-0a8badeecd804330b7263f05e2afef87c6f93d.json
0-02-0a-0a8badeecd804330b7263f05e2afef87c6f93d5.jpg

https://exiftool.org/forum/index.php?topic=14279.msg76940#msg76940

3. Copy tags from the .json to the .jpg:

exiftool -overwrite_original -d %s -tagsFromFile '%d/%F.json' '-GPSLatitude<GeoDataLatitude' '-GPSLatitudeRef<GeoDataLatitude' '-GPSLongitude<GeoDataLongitude' '-GPSLongitudeRef<GeoDataLongitude' '-Caption-Abstract<Description' '-Description<Description' '-AllDates<PhotoTakenTimeTimestamp' -ext jpg .

[-d %s date/time formatting option to accept timestamps in seconds since the epoch. https://exiftool.org/filename.html#codes]

4. Set also file creation & modification dates (works only 1970 UTC or later):

exiftool -overwrite_original '-FileCreateDate<ExifIFD:DateTimeOriginal' '-FileModifyDate<ExifIFD:DateTimeOriginal' .

In macOS the command asks for Xcode Command Line Tools install which can be ignored but then the FileCreateDate moves only backwards in time (the install is quite small and fast, not the huge Xcode install).

3. & 4. as a single combined command with GPS wildcards and ignore any 0.0 latitude and longitude in .json (otherwise the location will be in the Atlantic for location-less images), Rating added:

exiftool -d %s -tagsFromFile '%d/%F.json' '-GPSLatitude*<${GeoDataLatitude;$_ = undef if $_ eq "0.0"}' '-GPSLongitude*<${GeoDataLongitude;$_ = undef if $_ eq "0.0"}' '-Caption-Abstract<Description' '-Description<Description' '-XMP-xmp:Rating<${Favorited;$_=5 if $_=~/true/i}' '-AllDates<PhotoTakenTimeTimestamp' -execute '-FileCreateDate<ExifIFD:DateTimeOriginal' '-FileModifyDate<ExifIFD:DateTimeOriginal' -common_args -overwrite_original -ext jpg .

5. Time is not converted from UTC time of the .json file to the PC time zone (0 is 1970-0101-0000-00 and it works from that).

This has always been one of the big problems with copying data from Google Takeout. They provide the data in UTC with no way of knowing the original time zone.

So after writing the time stamps, then shift them with a command like:

exiftool -overwrite_original -TagsFromFile @ -Time:All -FileModifyDate -globalTimeShift -5 .

https://exiftool.org/forum/index.php?topic=13902.0

I hope this helps,

- Matti

Google Do Lots of Evil

Thanks so much for all the help. Fun times ahead :-).

wywh

Below is a command thats copies .json also to movies and a slightly edited command for images.

The commands copy all .json tags that the current Google Photos version can change, and set also file creation & modification dates. They ignore any 0.0 latitude and longitude value in .json because otherwise the location will be in the Atlantic for files that have no location in Google Photos.

.json to images:

exiftool -overwrite_original -d %s -tagsFromFile '%d/%F.json' '-GPSLatitude*<${GeoDataLatitude;$_ = undef if $_ eq "0.0"}' '-GPSLongitude*<${GeoDataLongitude;$_ = undef if $_ eq "0.0"}' '-Caption-Abstract<Description' '-Description<Description' '-Rating<${Favorited;$_=5 if $_=~/true/i}' '-AllDates<PhotoTakenTimeTimestamp' '-FileCreateDate<PhotoTakenTimeTimestamp' '-FileModifyDate<PhotoTakenTimeTimestamp' -ext jpg -ext heic -ext tif -ext png -ext webp -ext gif .
.json to movies. Here for Apple's apps (QuickTime Player, Photos) where Keys tags currently work best:

exiftool -overwrite_original -d %s -api QuickTimeUTC=1 -api LargeFileSupport=1 -tagsFromFile '%d/%F.json' '-Keys:GPSCoordinates<${GeoDataLatitude;$_ = undef if $_ eq "0.0"}, ${GeoDataLongitude;$_ = undef if $_ eq "0.0"}' '-Keys:Description<Description' '-Keys:UserRating<${Favorited;$_=5 if $_=~/true/i}' '-AllDates<PhotoTakenTimeTimestamp' '-Track*Date<PhotoTakenTimeTimestamp' '-Media*Date<PhotoTakenTimeTimestamp' '-Keys:CreationDate<PhotoTakenTimeTimestamp' '-FileCreateDate<PhotoTakenTimeTimestamp' '-FileModifyDate<PhotoTakenTimeTimestamp' -ext mp4 -ext m4v -ext mov .
After those commands it might be necessary to shift the hour with a command like (here -5 hours):

exiftool -overwrite_original -api QuickTimeUTC=1 -TagsFromFile @ -Time:All -FileCreateDate -FileModifyDate -globalTimeShift -5 .
- Matti

jad

I am having very similar problems with this, except the error message indicates that the json file type is not recognized.

exiftool -overwrite_original -r -d %s -tagsfromfile '%d/%f.JPG.json' "-DateTimeOriginal<PhotoTakenTimeTimestamp" -ext jpg ./exiftool_test2

Error: Unknown file type - ./exiftool_test2/R1-01390-002A.JPG.json
    1 directories scanned
    0 image files updated
    1 files weren't updated due to errors

Any suggestions?

Phil Harvey

Yes.  Attach R1-01390-002A.JPG.json so we can see what the problem is.

- 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 ($).

jad

Thanks so much. Here is what the json file looks like:

less ./R1-01390-002A.JPG.json

{
  "title": "R1-01390-002A.JPG",
  "description": "",
  "imageViews": "1",
  "creationTime": {
    "timestamp": "1663295689",
    "formatted": "Sep 16, 2022, 2:34:49 AM UTC"
  },
  "photoTakenTime": {
    "timestamp": "1661878853",
    "formatted": "Aug 30, 2022, 5:00:53 PM UTC"
  },
  "geoData": {
    "latitude": 0.0,
    "longitude": 0.0,
    "altitude": 0.0,
    "latitudeSpan": 0.0,
    "longitudeSpan": 0.0
  },
  "geoDataExif": {
    "latitude": 0.0,
    "longitude": 0.0,
    "altitude": 0.0,
    "latitudeSpan": 0.0,
    "longitudeSpan": 0.0
  },
  "url": "https://photos.google.com/photo/AF1QipO8A9BTymz1SKFRedIzmimED6MoDapdM24-0TuO",
  "googlePhotosOrigin": {
    "driveDesktopUploader": {
      "version": "DRIVE_FOR_DESKTOP"
    }
  }
}


Phil Harvey

That format looks good, and works for me with ExifTool 12.69 and the command you gave.  What version of ExifTool are you using?

- 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 ($).


Phil Harvey

OK.  Could there be some hidden characters that I'm not getting with copying/pasting?  Could you attach the file instead of pasting it in?  (You may need to zip it because I don't know if .json files are allowed as an attachment.)

- 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 ($).


Phil Harvey

I can't reproduce your problem.  Here is what I get on MacOS using your JSON file and a test JPG that I renamed:

> ls tmp
R1-01390-002A.JPG R1-01390-002A.JPG.json
> exiftool -overwrite_original -r -d %s -tagsfromfile '%d/%f.JPG.json' "-DateTimeOriginal<PhotoTakenTimeTimestamp" -ext jpg tmp
    1 directories scanned
    1 image files updated
> exiftool -ver
12.69

Can you try a controlled test like this, or maybe even this?:

exiftool -tagsfromfile R1-01390-002A.JPG.json test.jpg

Also, be sure to run exiftool -ver to verify you are running the correct version.

And one more thing:  What OS and shell are you using?  Your quoting should be OK for Unix, Mac and Windows PowerShell (I think), but not Windows CMD shell.

- 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 ($).

jad

Embarrassingly, the version was actually 10.10. After downloading the first time, what was installed in a directory called exiftool-12.69 was actually version 10.10. Not sure how that happened. It works swimmingly now. Thank you for your help.