get date from metadata, implement sd card cleanup.

This commit is contained in:
Kameron Kenny 2023-08-08 11:33:16 -04:00
parent 63a4124837
commit c884753f09
1 changed files with 15 additions and 7 deletions

View File

@ -34,6 +34,7 @@ import shutil
import hashlib
from datetime import datetime
import exifread
import ffmpeg
config_file = 'config.yaml'
@ -75,12 +76,14 @@ def get_capture_date(p, t):
if t == 'image':
with open(p, 'rb') as f:
tags = exifread.process_file(f)
captured = tags['EXIF DateTimeOriginal']
year = str(captured).split(' ')[0].split(':')[0]
month = str(captured).split(' ')[0].split(':')[1]
day = str(captured).split(' ')[0].split(':')[2]
stamp = datetime.strptime(str(tags['EXIF DateTimeOriginal']), '%Y:%m:%d %H:%M:%S')
elif t == 'video':
stamp = datetime.strptime(ffmpeg.probe(p)['format']['tags']['creation_time'], '%Y-%m-%dT%H:%M:%S.%f%z')
elif t == 'audio':
stamp = datetime.strptime(ffmpeg.probe(p)['format']['tags']['date'], '%Y-%m-%d')
else:
stamp = datetime.fromtimestamp(os.path.getctime(p))
year = stamp.strftime("%Y")
month = stamp.strftime("%m")
day = stamp.strftime("%d")
@ -96,6 +99,7 @@ def copy_from_source(p, dest_folder, dest_orig_folder, file):
if os.path.exists(os.path.join(dest_folder, file)):
check_match = cmp_files(p, os.path.join(dest_folder, file))
if check_match == False:
print(f'Found duplicate for {p}, renaming destination with md5 appended.')
base, extension = os.path.splitext(file)
file_name_hash = base + '_' + md5_hash(os.path.join(dest_folder, file)) + extension
os.rename(os.path.join(dest_folder, file), os.path.join(dest_folder, file_name_hash))
@ -134,6 +138,10 @@ def copy_from_source(p, dest_folder, dest_orig_folder, file):
print(dest_orig_folder + '/' + file, ': ', md5_hash(dest_orig_folder + '/' + file))
exit
# Blindly assume md5 check has passed...
if config['cleanup_sd'] == True:
os.remove(p)
def process_file(p, t, file, ext):
capture_date = get_capture_date(p, t)
y = capture_date[0]