-
Notifications
You must be signed in to change notification settings - Fork 12
/
adjust_exif_dates.py
executable file
·52 lines (42 loc) · 1.46 KB
/
adjust_exif_dates.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
#!/usr/bin/env python
#
# Adjust EXIF dates with exiftool. This will take a batch of JPEG files,
# sort them by name, and then change the EXIF date in each one with an
# offset of one second per image, ending in the current time.
#
# This requires the "exiftool" utility to be installed: http://www.sno.phy.queensu.ca/~phil/exiftool/
#
# Maintained at https://github.com/liyanage/macosx-shell-scripts
#
import sys
import os
import re
import argparse
import logging
import subprocess
import glob
import datetime
class Tool(object):
def __init__(self, args):
self.args = args
def run(self):
paths = sorted(glob.glob(self.args.pattern))
paths.reverse()
now = datetime.datetime.now()
delta = datetime.timedelta(seconds=1)
for path in paths:
now -= delta
cmd = ['exiftool', '-AllDates={}'.format(now.strftime('%Y:%m:%d %H:%M:%S')), path]
print ' '.join(cmd)
subprocess.check_call(cmd)
@classmethod
def main(cls):
parser = argparse.ArgumentParser(description='Adjust EXIF dates with exiftool.')
parser.add_argument('pattern', help='Glob pattern for image files to change')
parser.add_argument('-v', '--verbose', action='store_true', help='Enable verbose debug logging')
args = parser.parse_args()
if args.verbose:
logging.basicConfig(level=logging.DEBUG)
cls(args).run()
if __name__ == "__main__":
Tool.main()