diff options
-rw-r--r-- | exif.py | 81 | ||||
-rw-r--r-- | requirements.txt | bin | 295 -> 666 bytes |
2 files changed, 23 insertions, 58 deletions
@@ -1,69 +1,34 @@ | |||
1 | import os | 1 | import os |
2 | import pathlib | 2 | import pathlib |
3 | import subprocess | 3 | import platform |
4 | import sys | 4 | import sys |
5 | import exiftool | ||
5 | 6 | ||
6 | 7 | ||
7 | def rename(month): | 8 | def 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): | |||
71 | if __name__ == "__main__": | 36 | if __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 | |||