aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--exif.py81
-rw-r--r--requirements.txtbin295 -> 666 bytes
2 files changed, 23 insertions, 58 deletions
diff --git a/exif.py b/exif.py
index 233ceb5..f526683 100644
--- a/exif.py
+++ b/exif.py
@@ -1,69 +1,34 @@
1import os 1import os
2import pathlib 2import pathlib
3import subprocess 3import platform
4import sys 4import sys
5import exiftool
5 6
6 7
7def rename(month): 8def exif_rename(dir: str):
8 base_directory = pathlib.Path("/Users/clarkzjw/Desktop/") 9 base_directory = pathlib.Path("C:\\Users\\clarkzjw\\Desktop")
9 directory = str(base_directory.joinpath(month).absolute()) + "/" 10 directory = str(base_directory.joinpath(dir).absolute()) + "\\"
10 11
11 files = os.listdir(directory) 12 files = os.listdir(directory)
12 for file in files: 13 for file in files:
13 if file.startswith("IMG_") and (file.endswith(".CR2") or file.endswith(".CR3")): 14 filename = directory + file
14 filename = directory + file 15 ext = file.split(".")[-1]
16 if platform.system() == "Windows":
17 old_filename = filename.split("\\")[-1].split(".")[0]
18 else:
15 old_filename = filename.split("/")[-1].split(".")[0] 19 old_filename = filename.split("/")[-1].split(".")[0]
16 img = filename 20 img = filename
17 21
18 if file.endswith(".CR3"): 22 if (file.startswith("IMG_") and (file.endswith(".CR2") or file.endswith(".CR3"))) or \
19 result = subprocess.run(["bash", "-c", "exiftool {} | grep '^Time Stamp'".format(img)], 23 (file.startswith("R") and (file.endswith(".JPG") or file.endswith(".DNG"))) or \
20 stdout=subprocess.PIPE) 24 (file.startswith("PXL_") and file.endswith(".dng")) or \
21 timestamp = result.stdout.decode('utf-8').strip("\n").replace(".", "-").strip("Time Stamp")[2:] \ 25 (file.startswith("DSC") and file.endswith(".ARW")):
22 .replace(":", "-").strip("\n") 26 with exiftool.ExifToolHelper() as et:
23 filename = directory + timestamp + "-{}.CR3".format(old_filename) 27 for d in et.get_tags(filename, tags="EXIF:DateTimeOriginal"):
24 28 timestamp = d["EXIF:DateTimeOriginal"].replace(":", "-")
25 elif file.endswith(".CR2"): 29 break
26 result = subprocess.run(["bash", "-c", "exiftool {} | grep '^Date/Time Original'".format(img)], 30
27 stdout=subprocess.PIPE) 31 filename = directory + timestamp + "-{}.{}".format(old_filename, ext)
28 timestamp = result.stdout.decode('utf-8').split('\n')[1].replace(".", "-").strip("Date/Time Original")[
29 2:].replace(":", "-"). \
30 strip("\n")
31 filename = directory + timestamp + "-{}.CR2".format(old_filename)
32 print(filename)
33 os.rename(img, filename)
34
35 elif file.startswith("PXL_") and file.endswith(".dng"):
36 filename = directory + file
37 old_filename = filename.split("/")[-1].split(".")[0]
38 img = filename
39 result = subprocess.run(["bash", "-c", "exiftool {} | grep '^Date/Time Original'".format(img)],
40 stdout=subprocess.PIPE)
41 timestamp = \
42 result.stdout.decode('utf-8').strip("\n").split('\n')[1].strip("Date/Time Original")[2:].split('-')[
43 0][:-4].replace(".", "-").replace(":", "-").strip("\n")
44 filename = directory + timestamp + "-{}.dng".format(old_filename)
45 print(filename)
46 os.rename(img, filename)
47
48 elif file.startswith("R") and file.endswith(".DNG"):
49 filename = directory + file
50 old_filename = filename.split("/")[-1].split(".")[0]
51 img = filename
52 result = subprocess.run(["bash", "-c", "exiftool {} | grep '^Date/Time Original'".format(img)],
53 stdout=subprocess.PIPE)
54 timestamp = result.stdout.decode('utf-8').strip("\n").strip("Date/Time Original")[2:].replace(":", "-")
55 filename = directory + timestamp + "-{}.DNG".format(old_filename)
56 print(filename)
57 os.rename(img, filename)
58
59 elif file.startswith("R") and file.endswith(".JPG"):
60 filename = directory + file
61 old_filename = filename.split("/")[-1].split(".")[0]
62 img = filename
63 result = subprocess.run(["bash", "-c", "exiftool {} | grep '^Date/Time Original'".format(img)],
64 stdout=subprocess.PIPE)
65 timestamp = result.stdout.decode('utf-8').strip("\n").strip("Date/Time Original")[2:].replace(":", "-")
66 filename = directory + timestamp + "-{}.JPG".format(old_filename)
67 print(filename) 32 print(filename)
68 os.rename(img, filename) 33 os.rename(img, filename)
69 34
@@ -71,4 +36,4 @@ def rename(month):
71if __name__ == "__main__": 36if __name__ == "__main__":
72 if len(sys.argv) <= 1: 37 if len(sys.argv) <= 1:
73 exit(0) 38 exit(0)
74 rename(sys.argv[1]) 39 exif_rename(sys.argv[1])
diff --git a/requirements.txt b/requirements.txt
index 0febcdd..141dec7 100644
--- a/requirements.txt
+++ b/requirements.txt
Binary files differ
Powered by cgit v1.2.3 (git 2.41.0)