aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to 'exif.py')
-rw-r--r--exif.py54
1 files changed, 54 insertions, 0 deletions
diff --git a/exif.py b/exif.py
new file mode 100644
index 0000000..15fd059
--- /dev/null
+++ b/exif.py
@@ -0,0 +1,54 @@
1import os
2import pathlib
3import subprocess
4import sys
5
6
7def rename(month):
8 # base_directory = pathlib.Path("/mnt/nas/Photo/RAW/2022/")
9 # base_directory = pathlib.Path("/run/user/1000/kio-fuse-rQvVbo/smb/192.168.1.77/NAS/Photo/RAW/2022/")
10 base_directory = pathlib.Path("/mnt/c/Users/clarkzjw/Desktop/")
11 directory = str(base_directory.joinpath(month).absolute()) + "/"
12
13 files = os.listdir(directory)
14 for file in files:
15 if file.startswith("IMG_") and (file.endswith(".CR2") or file.endswith(".CR3")):
16 filename = directory + file
17 old_filename = filename.split("/")[-1].split(".")[0]
18 img = filename
19
20 if file.endswith(".CR3"):
21 result = subprocess.run(["bash", "-c", "exiftool {} | grep '^Time Stamp'".format(img)],
22 stdout=subprocess.PIPE)
23 timestamp = result.stdout.decode('utf-8').strip("\n").replace(".", "-").strip("Time Stamp")[2:] \
24 .replace(":", "-").strip("\n")
25 filename = directory + timestamp + "-{}.CR3".format(old_filename)
26
27 elif file.endswith(".CR2"):
28 result = subprocess.run(["bash", "-c", "exiftool {} | grep '^Date/Time Original'".format(img)],
29 stdout=subprocess.PIPE)
30 timestamp = result.stdout.decode('utf-8').split('\n')[1].replace(".", "-").strip("Date/Time Original")[
31 2:].replace(":", "-"). \
32 strip("\n")
33 filename = directory + timestamp + "-{}.CR2".format(old_filename)
34 print(filename)
35 os.rename(img, filename)
36
37 elif file.startswith("PXL_") and file.endswith(".dng"):
38 filename = directory + file
39 old_filename = filename.split("/")[-1].split(".")[0]
40 img = filename
41 result = subprocess.run(["bash", "-c", "exiftool {} | grep '^Date/Time Original'".format(img)],
42 stdout=subprocess.PIPE)
43 timestamp = \
44 result.stdout.decode('utf-8').strip("\n").split('\n')[1].strip("Date/Time Original")[2:].split('-')[
45 0][:-4].replace(".", "-").replace(":", "-").strip("\n")
46 filename = directory + timestamp + "-{}.dng".format(old_filename)
47 print(filename)
48 os.rename(img, filename)
49
50
51if __name__ == "__main__":
52 if len(sys.argv) <= 1:
53 exit(0)
54 rename(sys.argv[1])
Powered by cgit v1.2.3 (git 2.41.0)