aboutsummaryrefslogblamecommitdiff
blob: f526683191c21a110443a1c7d34ce358b0d4e280 (plain) (tree)
1
2
3
4
5
6
7
8
9
10

              
               
          
               

 


                                                                   


                                 




                                                                 
                                                                











                                                                                                


                                    



                          
                            
import os
import pathlib
import platform
import sys
import exiftool


def exif_rename(dir: str):
    base_directory = pathlib.Path("C:\\Users\\clarkzjw\\Desktop")
    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(".dng")) or \
                (file.startswith("DSC") and file.endswith(".ARW")):
            with exiftool.ExifToolHelper() as et:
                for d in et.get_tags(filename, tags="EXIF:DateTimeOriginal"):
                    timestamp = d["EXIF:DateTimeOriginal"].replace(":", "-")
                    break

            filename = directory + timestamp + "-{}.{}".format(old_filename, ext)
            print(filename)
            os.rename(img, filename)


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)