Advertisement
metalx1000

Sort Images Based by Address Based on GPS

Jan 24th, 2017
734
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 1.86 KB | None | 0 0
  1. #!/bin/bash
  2.  
  3. #
  4. # This file is part of the Maps-and-Locations (https://github.com/metalx1000/Maps-and-Locations http://FilmsByKris.com).
  5. # Copyright (c) 2017 Kris Occhipinti.
  6. #
  7. # This program is free software: you can redistribute it and/or modify  
  8. # it under the terms of the GNU General Public License as published by  
  9. # the Free Software Foundation, version 3.
  10. #
  11. # This program is distributed in the hope that it will be useful, but
  12. # WITHOUT ANY WARRANTY; without even the implied warranty of
  13. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  14. # General Public License for more details.
  15. #
  16. # You should have received a copy of the GNU General Public License
  17. # along with this program. If not, see <http://www.gnu.org/licenses/>.
  18. #
  19.  
  20. if [ "$#" -lt 1 ]
  21. then
  22.   echo "input error"
  23.   echo "example usage: $0 photo.jpg"
  24.   exit 1
  25. fi
  26.  
  27. image="$1"
  28.  
  29. function noGPS(){
  30.   echo "No GPS Found in Image..."
  31.   exit 1
  32. }
  33.  
  34. exiftool "$image"|grep "GPS Position"||noGPS
  35.  
  36.  
  37. lat="$(exiftool "$image"|grep "GPS Position"|cut -d\: -f2|sed 's/ deg /+(/g'|sed "s/' /\/60)+(/"|sed 's/"/\/3600)/'|awk '{print $1}'|bc -l)"
  38. long="-$(exiftool "$image"|grep "GPS Position"|cut -d\, -f2|sed 's/ deg /+(/g'|sed "s/' /\/60)+(/"|sed 's/"/\/3600)/'|awk '{print $1}'|bc -l)"
  39.  
  40. url="http://maps.google.com/maps/api/geocode/xml?latlng=$lat,$long&sensor=false"
  41.  
  42. echo "$lat,$long"
  43. echo "$url"
  44.  
  45. data="$(wget -O- -q "$url")"
  46.  
  47. echo "$data"|\
  48.  grep formatted|\
  49.  head -n1|\
  50.  cut -d\> -f2|\
  51.  cut -d\< -f1
  52.  
  53. street="$(echo "$data"|grep '<type>route</type>' -B 1|head -n1|cut -d\> -f2|cut -d\< -f1)"
  54. echo "$street"
  55.  
  56. number="$(echo "$data"|grep '<type>street_number</type>' -B 1|head -n1|cut -d\> -f2|cut -d\< -f1)"
  57. echo "$number"
  58.  
  59. mkdir -p "./photos/${street}/${number}"
  60. echo "Moving $image to ./photos/${street}/${number}/"
  61. mv "$image" "./photos/${street}/${number}/"
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement