get date from metadata, implement sd card cleanup.
This commit is contained in:
parent
63a4124837
commit
c884753f09
|
@ -34,6 +34,7 @@ import shutil
|
||||||
import hashlib
|
import hashlib
|
||||||
from datetime import datetime
|
from datetime import datetime
|
||||||
import exifread
|
import exifread
|
||||||
|
import ffmpeg
|
||||||
|
|
||||||
config_file = 'config.yaml'
|
config_file = 'config.yaml'
|
||||||
|
|
||||||
|
@ -75,12 +76,14 @@ def get_capture_date(p, t):
|
||||||
if t == 'image':
|
if t == 'image':
|
||||||
with open(p, 'rb') as f:
|
with open(p, 'rb') as f:
|
||||||
tags = exifread.process_file(f)
|
tags = exifread.process_file(f)
|
||||||
captured = tags['EXIF DateTimeOriginal']
|
stamp = datetime.strptime(str(tags['EXIF DateTimeOriginal']), '%Y:%m:%d %H:%M:%S')
|
||||||
year = str(captured).split(' ')[0].split(':')[0]
|
elif t == 'video':
|
||||||
month = str(captured).split(' ')[0].split(':')[1]
|
stamp = datetime.strptime(ffmpeg.probe(p)['format']['tags']['creation_time'], '%Y-%m-%dT%H:%M:%S.%f%z')
|
||||||
day = str(captured).split(' ')[0].split(':')[2]
|
elif t == 'audio':
|
||||||
|
stamp = datetime.strptime(ffmpeg.probe(p)['format']['tags']['date'], '%Y-%m-%d')
|
||||||
else:
|
else:
|
||||||
stamp = datetime.fromtimestamp(os.path.getctime(p))
|
stamp = datetime.fromtimestamp(os.path.getctime(p))
|
||||||
|
|
||||||
year = stamp.strftime("%Y")
|
year = stamp.strftime("%Y")
|
||||||
month = stamp.strftime("%m")
|
month = stamp.strftime("%m")
|
||||||
day = stamp.strftime("%d")
|
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)):
|
if os.path.exists(os.path.join(dest_folder, file)):
|
||||||
check_match = cmp_files(p, os.path.join(dest_folder, file))
|
check_match = cmp_files(p, os.path.join(dest_folder, file))
|
||||||
if check_match == False:
|
if check_match == False:
|
||||||
|
print(f'Found duplicate for {p}, renaming destination with md5 appended.')
|
||||||
base, extension = os.path.splitext(file)
|
base, extension = os.path.splitext(file)
|
||||||
file_name_hash = base + '_' + md5_hash(os.path.join(dest_folder, file)) + extension
|
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))
|
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))
|
print(dest_orig_folder + '/' + file, ': ', md5_hash(dest_orig_folder + '/' + file))
|
||||||
exit
|
exit
|
||||||
|
|
||||||
|
# Blindly assume md5 check has passed...
|
||||||
|
if config['cleanup_sd'] == True:
|
||||||
|
os.remove(p)
|
||||||
|
|
||||||
def process_file(p, t, file, ext):
|
def process_file(p, t, file, ext):
|
||||||
capture_date = get_capture_date(p, t)
|
capture_date = get_capture_date(p, t)
|
||||||
y = capture_date[0]
|
y = capture_date[0]
|
||||||
|
|
Loading…
Reference in New Issue