-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathduplicated_jpg_file_move.py
More file actions
82 lines (63 loc) · 3.47 KB
/
Copy pathduplicated_jpg_file_move.py
File metadata and controls
82 lines (63 loc) · 3.47 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
79
80
81
82
# -*- coding: utf-8 -*-
"""
Spyder Editor
ModuleNotFoundError: No module named 'cv2'
conda install opencv
pip install piexif
pip install exifread
There are only just five functions.
load(filename) - Get exif data as dict.
dump(exif_dict) - Get exif as bytes.
insert(exif_bytes, filename) - Insert exif into JPEG, or WebP.
remove(filename) - Remove exif from JPEG, or WebP.
transplant(filename, filename) - Transplant exif from JPEG to JPEG.
created by guitar79@naver.com
"""
import os
from datetime import datetime
import _photo_utilities
log_dir = "logs/"
log_file = "{}{}.log".format(log_dir, os.path.basename(__file__)[:-3])
err_log_file = "{}{}_err.log".format(log_dir, os.path.basename(__file__)[:-3])
print ("log_file: {}".format(log_file))
print ("err_log_file: {}".format(err_log_file))
base_dir_name = '../../jpgfile/2022/'
fullnames = _python_utilities.getFullnameListOfallFiles(base_dir_name)
save_base_dir_name = '../duplicated/'
image_Num = 0
for i in range(len(fullnames[:])):
if i < len(fullnames[:]) \
and fullnames[i][-4:].lower() == ".jpg" \
and fullnames[i+1][-4:].lower() == ".jpg":
print('#'*40,
"\n{2:.01f}% ({0}/{1}) {3}".format(image_Num, len(fullnames), (image_Num/len(fullnames))*100, os.path.basename(__file__)))
print ("Starting... fullname: {}".format(fullnames[i]))
image_Num += 1
if _photo_utilities.checkDuplicated_jpg(fullnames[i], fullnames[i+1]) :
print("{} is duplicated with {}".format(fullnames[i], fullnames[i+1]))
try :
image_datetime = _photo_utilities.get_image_datetime_str(fullnames[i]).replace(':','')
image_datetime = image_datetime.replace(' ','-')
image_ModelID = _photo_utilities.get_image_Model_name(fullnames[i]).replace(' ','')
image_Software = _photo_utilities.get_image_Software(fullnames[i])
save_dir_name = '{0}{1}/{1}-{2}-{3}_{4}_{5}/'\
.format(save_base_dir_name, image_datetime[0:4],
image_datetime[4:6], image_datetime[6:8], image_ModelID, image_Software)
while not os.path.exists(save_dir_name):
os.makedirs(save_dir_name)
print ('*'*80)
print ('{0} is created'.format(save_dir_name))
if not os.path.exists('{0}{1}_{2:08d}_py.jpg'.\
format(save_dir_name, image_datetime, image_Num)):
os.rename(fullnames[i], '{0}{1}_{2:08d}_{3}_py.jpg'.\
format(save_dir_name, image_datetime, image_Num, image_Software))
_photo_utilities.write_log(log_file,
"{3} is moved to {0}{1}_{2:08d}_py.jpg".\
format(save_dir_name, image_datetime, image_Num, fullnames[i]))
else :
_photo_utilities.write_log(log_file, \
"{3} is cannot moved because {0}{1}_{2:08d}_py.jpg is already exist..".\
format(save_dir_name, image_datetime, image_Num, fullnames[i]))
except Exception as err :
_photo_utilities.write_log(log_file,
"{2} ::: {0} error with {1}".format(err, fullnames[i], datetime.now()))