-
Notifications
You must be signed in to change notification settings - Fork 0
/
IndexProcessor.py
47 lines (38 loc) · 1.42 KB
/
IndexProcessor.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
import os
import sys
from pyexiv2 import Image
print('Number of arguments:', len(sys.argv), 'arguments.')
print('Argument List:', str(sys.argv))
path = sys.argv[1]
entries = os.scandir(path)
indexFile = open(path + "\\index.txt", mode="r", encoding="utf-8")
os.mkdir(path + "\\to_delete\\")
next_date_for_pictures = ''
num_photos_with_date = 0
while True:
fileName = indexFile.readline().strip()
description = indexFile.readline().strip()
dateTaken = indexFile.readline().strip()
if not dateTaken: break # EOF
if description != 'delete':
metadata = Image(path + "\\" + fileName)
xmp = {'Xmp.dc.description': description}
metadata.modify_xmp(xmp)
if dateTaken == next_date_for_pictures:
# add a second to make the next picture think that it comes next
split_date = dateTaken.split(":")
minutes = split_date[3]
split_date[3] = str(int(minutes) + num_photos_with_date).zfill(2)
num_photos_with_date += 1
dateTaken = ":".join(split_date)
else:
num_photos_with_date = 1
next_date_for_pictures = dateTaken
exif = {
'Exif.Image.ImageDescription': description,
'Exif.Photo.DateTimeOriginal': dateTaken
}
metadata.modify_exif(exif)
metadata.close()
else:
os.rename(path + "\\" + fileName, path + "\\to_delete\\" + fileName)