Created
August 13, 2023 19:58
-
-
Save d0ugal/9f5208f6eece96b4f4a106c6948f9654 to your computer and use it in GitHub Desktop.
Adds the date info to a file based on the file name
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from datetime import datetime | |
import piexif #piexif==1.1.3 | |
import os | |
import sys | |
dir = sys.argv[1] | |
for file in os.listdir(dir): | |
if file.endswith('.png'): | |
continue | |
if file.endswith('.mp4'): | |
continue | |
print(file) | |
year, month, date, _ = file.split('_', 3) | |
filename =f"{dir}/{file}" | |
exif_dict = piexif.load(filename) | |
new_date = datetime(int(year), int(month), int(date)).strftime("%Y:%m:%d %H:%M:%S") | |
exif_dict['0th'][piexif.ImageIFD.DateTime] = new_date | |
exif_dict['Exif'][piexif.ExifIFD.DateTimeOriginal] = new_date | |
exif_dict['Exif'][piexif.ExifIFD.DateTimeDigitized] = new_date | |
print(exif_dict) | |
exif_bytes = piexif.dump(exif_dict) | |
piexif.insert(exif_bytes, filename) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment