Debian Codegraph @

contrib/gps2url

raw
1 #!/bin/bash
2
3 # small script to extract GPS coordinates from an image and
4 # call firefox with google maps url if the GPS info exists
5 #
6 # 2015-2023 Andy Spiegl - GPL
7 # ORIGINAL IDEA (python version): 2012 Thomas Wiegner - GPL
8
9 # my own program name
10 self=$(basename $0)
11
12 # defaults
13 #BROWSER="firefox"
14 BROWSER="sensible-browser"
15 #MAPSURL="http://maps.google.de/maps?q="
16 MAPSURL="https://www.google.de/maps/place/"
17
18 # syntax help
19 Usage()
20 {
21 echo "Usage: $self [--browser <BROWSER>] [--mapsurl <URLtoMAPSapp>] IMAGE_WITH_GPS_EXIFDATA"
22 echo " [-h|--help]"
23 echo "Extracts GPS data from image and calls Google maps in webbrowser."
24 exit $1
25 }
26
27 # process params
28 while [ $# -gt 0 ]
29 do
30 case $1 in
31 --browser) shift; BROWSER="$1"; shift; continue;;
32 --mapsurl) shift; MAPSURL="$1"; shift; continue;;
33 -h | --help) Usage 0;;
34 -*) Usage 1;;
35 *) imgfile="$1"; shift; continue;;
36 esac
37 break
38 done
39
40 # run exiftool to extract GPS coords
41 COORDS=$( exiftool -t -GPSPosition -c "%d°%d'%.3f''" "$imgfile" | sed -e"s|.* ||" -e"s| ||g" )
42 #echo GPS coords in "$imgfile": $COORDS
43 echo GPS coords: $COORDS
44
45 # check for errors
46 errstat=$?
47 if [ $errstat != 0 ]; then
48 echo "Error $errstat while calling exiftool and sed: $!"
49 fi
50
51 # send it to the webbrowser (avoid glib error messages)
52 $BROWSER "${MAPSURL}${COORDS}" 2> /dev/null
53
54 exit