-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMetaDataInstater.py
More file actions
78 lines (54 loc) · 2.28 KB
/
MetaDataInstater.py
File metadata and controls
78 lines (54 loc) · 2.28 KB
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
75
76
77
78
from exif import Image
import os
import shutil
from datetime import datetime
from win32_setctime import setctime
import re
import tkinter as tk
from tkinter import filedialog
root = tk.Tk()
root.withdraw()
inputfilepath = filedialog.askdirectory()
outputfilepath = filedialog.askdirectory()
InputPath = inputfilepath
OutputPath = outputfilepath
try:
original_umask = os.umask(0)
os.makedirs(f'{OutputPath}\\Completed', 0o755, exist_ok=True)
finally:
os.umask(original_umask)
try:
original_umask = os.umask(0)
os.makedirs(f'{OutputPath}\\Failed', 0o755, exist_ok=True)
finally:
os.umask(original_umask)
def ChangeData(file, ExpName):
with open(InputPath + '/' + file, 'rb') as InputImg:
img = Image(InputImg)
print(f'Old MetaData{img.get_all()}')
# Date Extraction
ImageName = ExpName.removesuffix('.jpg')
year, month, day = int(ImageName[0:4]), int(ImageName[4:6]), int(ImageName[6:8])
hour, minute, second = int(ImageName[9:11]), int(ImageName[11:13]), int(ImageName[13:15])
# Start To Modify The Required Values
new_date = datetime(year, month, day, hour, minute, second).strftime("%Y:%m:%d %H:%M:%S")
epochtime = int(datetime(year, month, day, hour, minute, second).timestamp())
img.datetime_original, img.datetime_digitized, img.datetime = new_date, new_date, new_date
with open(f'{OutputPath}\\Completed\\{ExpName}.jpg', 'wb') as OutputImg:
OutputImg.write(img.get_file())
print(f'New MetaData{img.get_all()}')
os.utime(f'{OutputPath}\\Completed\\{ExpName}.jpg', (epochtime, epochtime))
setctime(f'{OutputPath}\\Completed\\{ExpName}.jpg', epochtime)
# Process Complete
print('All Files are:',os.listdir(InputPath))
UndoneFiles = []
for file in os.listdir(InputPath):
ExpNameWithout = re.search("[0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9]_[0-9][0-9][0-9][0-9][0-9][0-9]", file)
if ExpNameWithout:
ExpName = ExpNameWithout.group()
ChangeData(file, ExpName)
else:
UndoneFiles.append(file)
shutil.copy(f'{InputPath}\\{file}', f'{OutputPath}\\Failed\\{file}')
print(f'Number Of Failed Files: {len(UndoneFiles)}')
print(f'Failed Files Are: {UndoneFiles}')