Google Takeout .json error with images with no location

Started by wywh, October 07, 2021, 02:01:29 PM

Previous topic - Next topic

wywh

I use the following command to merge updated Google Photos metadata from Google Takeout .json to .jpg:

exiftool -d %s -tagsfromfile '%d/%F.json' '-GPSAltitude<GeoDataAltitude' '-GPSLatitude<GeoDataLatitude' '-GPSLatitudeRef<GeoDataLatitude' '-GPSLongitude<GeoDataLongitude' '-GPSLongitudeRef<GeoDataLongitude' '-Keywords<Tags' '-Subject<Tags' '-Caption-Abstract<Description' '-Description<Description' '-AllDates<PhotoTakenTimeTimestamp' -execute '-FileCreateDate<ExifIFD:DateTimeOriginal' '-FileModifyDate<ExifIFD:DateTimeOriginal' -common_args -overwrite_original_in_place -ext jpg .

It works fine except for some images that don't have location data. Such .json files have dummy zero data:

exiftool -a -G1 -s image.jpg.json
[ExifTool]      ExifToolVersion                 : 12.25
[JSON]          GeoDataAltitude                 : 0.0
[JSON]          GeoDataLatitude                 : 0.0
[JSON]          GeoDataLatitudeSpan             : 0.0
[JSON]          GeoDataLongitude                : 0.0
[JSON]          GeoDataLongitudeSpan            : 0.0
[JSON]          GeoDataExifAltitude             : 0.0
[JSON]          GeoDataExifLatitude             : 0.0
[JSON]          GeoDataExifLatitudeSpan         : 0.0
[JSON]          GeoDataExifLongitude            : 0.0
[JSON]          GeoDataExifLongitudeSpan        : 0.0


Then all such images erroneously get a wrong GPS in the Atlantic:

exiftool -a -G1 -s image.jpg
[GPS]           GPSLatitudeRef                  : North
[GPS]           GPSLatitude                     : 0 deg 0' 0.00"
[GPS]           GPSLongitudeRef                 : East
[GPS]           GPSLongitude                    : 0 deg 0' 0.00"
[GPS]           GPSAltitude                     : 0 m


Is there an elegant way to prevent inserting such erroneous info?

- Matti

StarGeek

Test this out to be sure, but I think this would work
'-GPSLatitude*<${GeoDataLatitude;$_ = undef if $_ eq "0.0"}'

This will throw "Undefined value" warnings for any file that has a 0.0 value

Also, I set this to use a wildcard.  This will allow you to shorten the command by dropping all the reference direction copies, as using GPSLatitude* will set both GPSLatitude and GPSLatitudeRef at the same time.
* 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).

wywh

Thanks, this works fine and ignores any 0.0 latitude and longitude in .json. I wonder why Google Takeout inserts such bogus data out of thin air for location-less images.

exiftool -d %s -tagsfromfile '%d/%F.json' '-GPSAltitude<GeoDataAltitude' '-GPSLatitude*<${GeoDataLatitude;$_ = undef if $_ eq "0.0"}' '-GPSLongitude*<${GeoDataLongitude;$_ = undef if $_ eq "0.0"}' '-Caption-Abstract<Description' '-Description<Description' '-AllDates<PhotoTakenTimeTimestamp' -execute '-FileCreateDate<ExifIFD:DateTimeOriginal' '-FileModifyDate<ExifIFD:DateTimeOriginal' -common_args -overwrite_original_in_place -ext jpg .

Warning: [minor] Advanced formatting expression returned undef for 'GeoDataLatitude' - ./none.jpg.json
    1 directories scanned
    2 image files updated
    1 directories scanned
    2 image files updated


Google Photos does not handle keywords so I removed '-Keywords<Tags' '-Subject<Tags'.

I tried to add '-XMP-xmp:Rating=5<Favorited=true' but got an error "Warning: Not a floating point number for XMP-xmp:Rating".

I was surprised to find that Google Photos does not allow editing an existing GPS. And that it does not support pasting GPS as numbers.

I'll leave merging .json Dates, Captions and GPS to movies later because it is still such a mess. Google Photos imports dates (QuickTime:CreateDate for 1970 or later and Keys:CreationDate for 1902 or later movies) and GPS (Keys:GPSCoordinates) but ignores other Keys I occasionally use for movies (DisplayName, Title, Description, Author, Keywords).

I stumbled on a nice page at:

https://www.reddit.com/r/googlephotos/comments/fnsfv8/merge_json_and_jpg_files_from_google_takeout/

- Matti

StarGeek

Quote from: wywh on October 08, 2021, 12:05:01 PM
I tried to add '-XMP-xmp:Rating=5<Favorited=true' but got an error "Warning: Not a floating point number for XMP-xmp:Rating".

Try this.  It will return a warning if Favorited is not true.
'-XMP-xmp:Rating<${Favorited;$_=5 if $_=~/true/i}'
* 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).

wywh

Thanks again, this works fine and handles all tags that Google Photos currently can edit. I removed '-GPSAltitude<GeoDataAltitude' because Google Photos does not support it.

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_in_place -ext jpg .

- Matti

wywh

p.s. 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

wywh

Additionally Google Takeout truncates long filenames so jpg filenames over 47 chars fail to get a matching .json:

a2345678901234567890123456789012345678901.jpg
b23456789012345678901234567890123456789012.jpg
c234567890123456789012345678901234567890123.jpg
d2345678901234567890123456789012345678901234.jpg
e23456789012345678901234567890123456789012345.jpg
f234567890123456789012345678901234567890123456.jpg
g2345678901234567890123456789012345678901234567.jpg
h23456789012345678901234567890123456789012345678.jpg
i234567890123456789012345678901234567890123456789.jpg


...to 51 characters as follows:

a2345678901234567890123456789012345678901.jpg
a2345678901234567890123456789012345678901.jpg.json
b23456789012345678901234567890123456789012.jpg
b23456789012345678901234567890123456789012.jpg.json
c234567890123456789012345678901234567890123.jpg
c234567890123456789012345678901234567890123.jp.json
d2345678901234567890123456789012345678901234.jpg
d2345678901234567890123456789012345678901234.j.json
e23456789012345678901234567890123456789012345.jpg
e23456789012345678901234567890123456789012345..json
f234567890123456789012345678901234567890123456.jpg
f234567890123456789012345678901234567890123456.json
g2345678901234567890123456789012345678901234567.jpg
g234567890123456789012345678901234567890123456.json
h2345678901234567890123456789012345678901234567.jpg
h234567890123456789012345678901234567890123456.json
i2345678901234567890123456789012345678901234567.jpg
i234567890123456789012345678901234567890123456.json


So merging fails in those unless the filenames are fixed to match:

Warning: Error opening file - ./c234567890123456789012345678901234567890123.jpg.json
Warning: Error opening file - ./d2345678901234567890123456789012345678901234.jpg.json
Warning: Error opening file - ./e23456789012345678901234567890123456789012345.jpg.json
Warning: Error opening file - ./f234567890123456789012345678901234567890123456.jpg.json
Warning: Error opening file - ./g2345678901234567890123456789012345678901234567.jpg.json
Warning: Error opening file - ./h2345678901234567890123456789012345678901234567.jpg.json
Warning: Error opening file - ./i2345678901234567890123456789012345678901234567.jpg.json


- Matti