Google Time Zone lookup config

Started by StarGeek, April 05, 2020, 10:30:51 PM

Previous topic - Next topic

StarGeek

A few years ago, I made a config file that would use Google's APIs to determine the time zone (and some other things) based upon the GPS coordinates and DateTimeOriginal tags in a file.  It was a hot mess, requiring several CPAN modules, which prevented it from working with the Windows executable.  I revisited that config in order to see if I could make it easier to use and this is the result.

This config requires that cURL is installed somewhere in the PATH or set directly in the file.  cURL is already included with Linux (and Mac?), but Windows will probably need to add it (see here).  There may also be a complication with the fact the PowerShell uses cURL as an alias for it's own  Invoke-WebRequest command so the full path will probably be needed.

The config also requires that a Google Maps API Key be generated.  That can be done here.  Be warned, Google terms of service for this is a bit messy.  It costs $5/1,000 hits, but the first $200 are free, so that's 40,000 hits allowed per month for free.  This config attempts to create a simple cache so that locations within the same hour and within about 10 meters won't create additional calls, though you can alter this for lesser or greater accuracy.

The tag names are a bit awkward ATM, I'm open to better suggestions.  But I'm also thinking of looking at some other web APIs (maybe OpenStreetMaps), so that's something to keep in mind.

The tags available are:

  • GoogleLookUpTimeZone:  Returns the time zone based upon DateTimeOriginal and GPS Coordinates in ±HH:MM format.  This can be used to add on to or replace faulty XMP timestamps tags or added to EXIF:OffsetTimeOriginal, EXIF:OffsetTime, and EXIF:OffsetTimeDigitized tags. It cannot be added to the EXIF:TimeZoneOffset tag without modification as that tag is required to be an integer value.
  • GoogleLookUpTimeZoneDaylightSavings: Returns True/False depending upon whether Daylight Savings Time was in effect at that location and time.
  • GoogleLookUpTimeZoneName: Returns the time zone name for that location and time, e.g. Pacific Daylight Time, China Standard Time, or Central European Standard Time.
  • GoogleLookUpTimeZoneID: Returns the time zone id, such as America/Los_Angeles, Asia/Shanghai, or Europe/Paris
  • GoogleLookUpTimeZoneRaw: Returns the raw time zone data as a list of KEY=VALUE pairs.

Example output:
C:\>exiftool -config TimezoneLookUp.config -G1 -s -DateTimeOriginal -gpsL*# -GoogleLookUpTimeZone* y:\!temp\Test3.jpg y:\!temp\Test4.jpg
======== y:/!temp/Test3.jpg
[ExifIFD]       DateTimeOriginal                : 2019:12:25 12:00:00
[Composite]     GPSLatitude                     : 36.1103
[Composite]     GPSLongitude                    : -115.1554
[Composite]     GPSLatitudeRef                  : N
[Composite]     GPSLongitudeRef                 : W
[Composite]     GoogleLookUpTimeZone            : -08:00
[Composite]     GoogleLookUpTimeZoneDaylightSavings: False
[Composite]     GoogleLookUpTimeZoneID          : America/Los_Angeles
[Composite]     GoogleLookUpTimeZoneName        : Pacific Standard Time
[Composite]     GoogleLookUpTimeZoneRaw         : dst=False, timezone=-08:00, timezonename=Pacific Standard Time, timezoneid=America/Los_Angeles
======== y:/!temp/Test4.jpg
[ExifIFD]       DateTimeOriginal                : 2020:04:04 12:57:04
[Composite]     GPSLatitude                     : 40.6892
[Composite]     GPSLongitude                    : -74.0445
[Composite]     GPSLatitudeRef                  : N
[Composite]     GPSLongitudeRef                 : W
[Composite]     GoogleLookUpTimeZone            : -04:00
[Composite]     GoogleLookUpTimeZoneDaylightSavings: True
[Composite]     GoogleLookUpTimeZoneID          : America/New_York
[Composite]     GoogleLookUpTimeZoneName        : Eastern Daylight Time
[Composite]     GoogleLookUpTimeZoneRaw         : timezoneid=America/New_York, timezonename=Eastern Daylight Time, timezone=-04:00, dst=True
    2 image files read


* 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).

Phil Harvey

#1
Hi StarGeek,

This is great!  I'll try this out when I get a chance.  If I have time, and if it isn't too difficult, I will look into replacing the curl call with a function using the Perl socket library.

- Phil

Edit:  I hope regular http works because implementing https protocol would be much more painful.

BTW, why have MyProcessJson() as a separate subroutine since it is a one-liner, and is called only from one place?
...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

Quote from: Phil Harvey on April 06, 2020, 07:29:29 AM
Edit:  I hope regular http works because implementing https protocol would be much more painful.

Unforunately, no.  Google forces https.  This is why I never released my original.  The Windows modules I tried that would access the web (LWP, I think) included .dll files with the SSL part.  These won't load when called from the par code.

QuoteBTW, why have MyProcessJson() as a separate subroutine since it is a one-liner, and is called only from one place?[/i]

I set it aside during my testing trying to get things to work and I was heading down the wrong path. I thought it was going to be more complicated as well.  But if I can expand this config to other Google API calls, it will probably get called again.  And I don't know how OpenStreetMaps works yet, so if they return json, it might be called again.
* 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).