forked from mspreitz/ADEL
-
Notifications
You must be signed in to change notification settings - Fork 0
/
_getEXIF.py
74 lines (68 loc) · 3.06 KB
/
_getEXIF.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
#!/usr/bin/python
#
# Copyright (C) 2012 Michael Spreitzenbarth, Sven Schmitt
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
import os
import subprocess
import datetime
import sys
import hashlib
import _adel_log
import _exif
def get_exif_information(backup_dir, outputFile):
picture_position_list = []
picture_dir = backup_dir + "/pictures/"
listing = os.listdir(picture_dir)
for file in listing:
latitude = ""
longitude = ""
readtime = ""
try:
f = open(picture_dir + file, 'rb')
tags = _exif.process_file(f)
for tag in tags.keys():
if tag in ('GPS GPSLatitude'):
lat = str(tags[tag])
lat1 = lat.split(",")[2].split("]")[0].split(" ")[-1]
if "/" in lat1:
lat1_1 = float(lat1.split("/")[0])
lat1_2 = float(lat1.split("/")[1])
lat1 = lat1_1 / lat1_2
else:
lat1 = float(lat1)
lat2 = float(lat.split(",")[1].split(" ")[-1])
lat3 = float(lat.split(",")[0].split("[")[1])
latitude = ((((lat1 / 60) + lat2) / 60) + lat3)
if tag in ('GPS GPSLongitude'):
long = str(tags[tag])
long1 = long.split(",")[2].split("]")[0].split(" ")[-1]
if "/" in long1:
long1_1 = float(long1.split("/")[0])
long1_2 = float(long1.split("/")[1])
long1 = long1_1 / long1_2
else:
long1 = float(long1)
long2 = float(long.split(",")[1].split(" ")[-1])
long3 = float(long.split(",")[0].split("[")[1])
longitude = ((((long1 / 60) + long2) / 60) + long3)
if tag in ('EXIF DateTimeOriginal'):
readtime = str(tags[tag])
readtime = readtime.split(":")[1] + "/" + readtime.split(":")[2].split(" ")[0] + "/" + readtime.split(":")[0].split("0")[1] + " " + readtime.split(" ")[1]
except:
continue
if ((latitude != "") & (longitude != "")):
picture_position_list.append([file, str(latitude), str(longitude), "500", readtime])
outputFile.write('%25s %7d %5d %10s %10s %s \n' % ("JPEG", 500, 0, latitude, longitude, str(readtime)))
return picture_position_list