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

              
               
          
               
                                        
 
          
 
                          
                                                           
                                                                  


                                 




                                                                 
                                                                



                                                                                                
                                                                                                   


                                                                             
                                                           






                                                                                                            



                                                                                             
 



                          
                            
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)