-
Notifications
You must be signed in to change notification settings - Fork 0
/
run.py
59 lines (48 loc) · 1.28 KB
/
run.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
#!/usr/bin/env python3
# -*- encoding: utf-8 -*-
from sys import version_info as vf
if not (vf.major == 3 and vf.minor >= 8):
print('\033[40;33;1mOnly for Python >= 3.8\033[0m')
exit(-1)
from pathlib import Path
try:
import ujson as json
except ModuleNotFoundError:
import json
from PIL import Image
from PIL.ExifTags import TAGS
import time
filepath = (Path(__file__).parent / '..').rglob(r'*.*')
outpath = Path(__file__).parent / 'exif.json'
start = time.time()
print('loading...')
x = 0
n = len(filepath := list(filepath))
content = dict()
for pic in filepath:
x += 1
y = int(float(x) / n * 20)
print(
f"\r[{'='*y}{' '*(20-y)}] {y*5}% {time.time()-start:.2f}s",
end=' ', flush=True
)
try:
img = Image.open(pic).getexif()
except Exception as e:
continue
tags = dict()
for k,v in img.items():
tag = TAGS.get(k,k)
if isinstance(v, tuple):
v = list(v)
elif isinstance(v, bytes):
v = v.decode('unicode-escape').replace('\x00', '')
elif not isinstance(v, int):
v = str(v)
tags.update({tag: v})
content.update({pic.name: tags})
outpath.write_text(
json.dumps(content, indent=2, ensure_ascii=False),
encoding='utf-8'
)
print('done.')