aboutsummaryrefslogtreecommitdiff
blob: 79c0624719f8ec0ee2a63996da5c64033c42a138 (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
40
41
42
43
44
45
46
47
import os
import pathlib
import platform
import sys
import exiftool
from datetime import datetime, timedelta

offset = 1

def exif_rename(dir: str):
    base_directory = pathlib.Path("/mnt/pool1/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():
                        #serial = int(filename.split("/")[-1].split(".")[0][1:])
                        datetime_object = datetime.strptime(d["EXIF:DateTimeOriginal"], '%Y:%m:%d %H:%M:%S')
                        #if serial > 8630:
                        #    datetime_object += timedelta(hours=10)
                        #else:
                        #    datetime_object += timedelta(hours=offset)
                        timestamp = str(datetime_object).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)