I am writing a bash script that renames JPG files based on their EXIF tags. My source files are named like this:
IMG_2110.JPG
IMG_2112.JPG
IMG_2113.JPG
IMG_2114.JPG
I need to rename them as follows:
2015-06-07_11-21-38_iPhone6Plus_USA-CA-Los_Angeles_IMG_2110.JPG
2015-06-07_11-22-41_iPhone6Plus_USA-CA-Los_Angeles_IMG_2112.JPG
2015-06-13_19-05-10_iPhone6Plus_Morocco-Fez_IMG_2113.JPG
2015-06-13_19-12-55_iPhone6Plus_Morocco-Fez_IMG_2114.JPG
My bash script uses exiftool to parse the EXIF header and rename the files. For those files that do not contain the EXIF creation date, I use the file modification time.
#!/bin/bash
IFS=$'\n'
for i in *.*; do
MOD=`stat -f %Sm -t %Y-%m-%d_%H-%m-%S $i`
model=$( exiftool -f -s3 -"Model" "${i}" )
datetime=$( exiftool -f -s3 -"DateTimeOriginal" "${i}" )
stamp=${datetime//:/-}"_"${model// /}
echo ${stamp// /_}$i
done
I'm stuck in place. I need to identify the country and city using the GPS information from the EXIF tag. exiftool provides a field called GPS Position. Of all the fields, this seems the most useful for locating.
GPS Position : 40 deg 44' 49.36" N, 73 deg 56' 28.18" W
Google provides a public API for geolocation, but this requires latitude / longitude coordinates in this format:
40.7470444°, -073.9411611°
API ( , ):
https://maps.googleapis.com/maps/api/geocode/json?latlng=40.7470444,-073.9411611
:
GPS /, , Google?
JSON, , , ? , ? Id , - . - , COUNTRY-City.
bash script. pygeocoder gpsbabel, , , . -, API (http://www.earthpoint.us/Convert.aspx).