|
@@ -0,0 +1,52 @@
|
|
|
+#!/usr/bin/python3
|
|
|
+
|
|
|
+import sys
|
|
|
+import piexif as x
|
|
|
+import datetime as dt
|
|
|
+
|
|
|
+shift = dt.timedelta(hours = 1)
|
|
|
+print('Shift exif date time by', shift)
|
|
|
+
|
|
|
+if len(sys.argv) < 1:
|
|
|
+ print('shift img1.jpg img2.jpg')
|
|
|
+ quit()
|
|
|
+
|
|
|
+
|
|
|
+timeTagCodes = [36867, 36868]
|
|
|
+
|
|
|
+filenames = sys.argv[1:]
|
|
|
+
|
|
|
+formatDate = '%Y:%m:%d %H:%M:%S'
|
|
|
+formatFrom = f"b'{formatDate}'"
|
|
|
+
|
|
|
+def describeExif(exif):
|
|
|
+ for k in timeTagCodes:
|
|
|
+ if k in exif.keys():
|
|
|
+ t = dt.datetime.strptime(str(exif[k]), formatFrom)
|
|
|
+ print('Exif[', k, ']=', t, '->', x.TAGS['Exif'][k]['name'])
|
|
|
+ else:
|
|
|
+ print('Exif[', k, ']=', '?', '->', x.TAGS['Exif'][k]['name'])
|
|
|
+ return t
|
|
|
+
|
|
|
+
|
|
|
+def shiftThisFile(filename: str):
|
|
|
+ m = x.load(filename)
|
|
|
+ e = m['Exif']
|
|
|
+ t = describeExif(e)
|
|
|
+
|
|
|
+ targetDateTime = t + shift
|
|
|
+ print('Shifting')
|
|
|
+ print(t)
|
|
|
+ print('to')
|
|
|
+ print(targetDateTime)
|
|
|
+
|
|
|
+ for k in timeTagCodes:
|
|
|
+ e[k] = targetDateTime.strftime(formatDate).encode()
|
|
|
+
|
|
|
+ describeExif(e)
|
|
|
+
|
|
|
+
|
|
|
+for filename in filenames:
|
|
|
+ print(filename)
|
|
|
+ t = shiftThisFile(filename)
|
|
|
+ print()
|