Fixing files from Google Photos via Takeout

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

Previous topic - Next topic

eddified

The Original Post is really great. Thank you!

But, I have some google json files that contain 0 for gps data (ie invalid data):

Quote"geoData": {
    "latitude": 0.0,
    "longitude": 0.0,
    "altitude": 0.0,
    "latitudeSpan": 0.0,
    "longitudeSpan": 0.0
  },

exiftool is writing these 0 values, and I would prefer not to write these 0 values. How can I modify this to only write the data if it's valid and non-zero?

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

wywh

Quote from: eddified on March 25, 2025, 12:15:18 AMgoogle json files that contain 0 for gps data (ie invalid data)
Yes, .json files might have dummy zero data, and such images erroneously get a wrong GPS in the Atlantic. Here is the fix from StarGeek:

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

I have used this command to copy .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 .
...and to movies:

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 .
You might have to convert single quotes ' to double quotes " in Windows.

- Matti

eddified

Quote from: wywh on March 25, 2025, 02:34:25 AMI have used this command to copy .json to images:


...and to movies:


Thank you, this looks extremely helpful!

eddified

Quote from: wywh on March 25, 2025, 02:34:25 AMI have used this command to copy .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 .

What does the asterisk modifier do when used with the "<" writing operator? Ie, "*<". I've searched around and not been able to find it. (Punctuation is not the easiest thing to have search engines look for)

Phil Harvey

"*" and "?" may be used as wildcards in a tag name.

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

eddified

Quote from: wywh on March 25, 2025, 02:34:25 AM'-GPSLongitude*<${GeoDataLongitude;$_ = undef if $_ eq "0.0"}'

Update: got it working. See my other post.

This is great and all, but... it doesn't actually work (by "work" i mean: write the tag when non-zero, and don't write the tag when zero). In all my attempts, it either writes the tag for both zero and non-zero cases, or doesn't write the tag for both zero and non-zero cases. The tag names and json are as expected, since I am seeing the tags being written with correct values. I just can't get the conditional nature of the expression to work properly.

I am wondering if it has to do with data type? The json actually uses a number 0.0, not a string "0.0". So I tried replacing the expression with
Quote'-GPSLongitude*<${GeoDataLongitude;$_ = undef if $_ eq 0.0}'
and also tried just using 0 (without decimal places). I just can't get it working properly.

Please help.

Update: got it working. See my other post.

eddified

Quote from: eddified on March 25, 2025, 11:41:39 PMPlease help.

Figured it out! When using numbers instead of strings, it suddenly came to me to use `==` instead of `eq`:

Quote'-GPSLongitude*<${GeoDataLongitude;$_ = undef if $_ == 0}'

It suddenly came to me what was wrong. (I had a little Perl experience from 20 years ago...)

wywh

#22
Quote from: eddified on March 25, 2025, 11:41:39 PM'-GPSLongitude*<${GeoDataLongitude;$_ = undef if $_ eq 0.0}'

It should work if "0.0" is double quoted (inside single quotes on the Mac), without them it writes those zero .json GPS locations.

'-GPSLongitude*<${GeoDataLongitude;$_ = undef if $_ eq "0.0"}'
My cheatsheet for Perl operators.