aboutsummaryrefslogtreecommitdiff
blob: 3e397ad48c5d6d9bf67dc92ca5b3018b546d8d12 (plain) (blame)
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
import os
import pathlib
import platform
import sys
import exiftool


def exif_rename(dir: str):
    base_directory = pathlib.Path("/pool1/clarkzjw/Media/Photo")
    directory = str(base_directory.joinpath(dir).absolute()) + "/"

    files = os.listdir(directory)
    for file in files:
        filename = directory + file
        ext = file.split(".")[-1]
        if platform.system() == "Windows":
            old_filename = filename.split("\\")[-1].split(".")[0]
        else:
            old_filename = filename.split("/")[-1].split(".")[0]
        img = filename

        if (file.startswith("IMG_") and (file.endswith(".CR2") or file.endswith(".CR3"))) or \
                (file.startswith("R") and (file.endswith(".JPG") or file.endswith(".DNG"))) or \
                (file.startswith("PXL_") and (file.endswith(".jpg") or file.endswith(".dng"))) or \
                (file.startswith("DSC") and file.endswith(".ARW")):
            with exiftool.ExifToolHelper() as et:
                for d in et.get_tags(filename, tags="EXIF:DateTimeOriginal"):
                    if "EXIF:DateTimeOriginal" in d.keys():
                        timestamp = d["EXIF:DateTimeOriginal"].replace(":", "-")
                        filename = directory + timestamp + "-{}.{}".format(old_filename, ext)
                        print(filename)
                        os.rename(img, filename)
                        break


if __name__ == "__main__":
    if len(sys.argv) <= 1:
        exit(0)
    exif_rename(sys.argv[1])
Powered by cgit v1.2.3 (git 2.41.0)