Fix path and update requirements
This commit is contained in:
parent
aa5a2d7c2e
commit
8b9ab3f6d2
2 changed files with 31 additions and 20 deletions
|
@ -9,6 +9,7 @@ import sys
|
|||
import os
|
||||
import logging
|
||||
import json
|
||||
import shutil
|
||||
import click
|
||||
import click_config_file
|
||||
from logging.handlers import SysLogHandler
|
||||
|
@ -59,12 +60,15 @@ class image_classifier:
|
|||
with os.scandir(directory) as directory_item:
|
||||
for entry in directory_item:
|
||||
if not entry.name.startswith('.') and entry.is_file():
|
||||
self.process_file(directory + os.sep + entry.name)
|
||||
self.process_file(os.path.joing(directory, entry.name))
|
||||
|
||||
def process_file(self, file):
|
||||
''' Process a file, find faces, add EXIF information and
|
||||
move it to the folder of the day'''
|
||||
self._log.debug(f"Looking for faces in file '{file}'...")
|
||||
if not os.access(file, os.R_OK):
|
||||
self._log.error(f"The file '{file}' is not readable.")
|
||||
else:
|
||||
people = self.find_faces(file)
|
||||
if people:
|
||||
self._log.debug(f"Found {len(people)} known people in the image.")
|
||||
|
@ -73,13 +77,21 @@ class image_classifier:
|
|||
self.metadata.read()
|
||||
#self.print_metadata()
|
||||
if 'Xmp.iptcExt.PersonInImage' in self.metadata.xmp_keys:
|
||||
print(f"People (before): {self.metadata['Xmp.iptcExt.PersonInImage'].raw_value} (type: {type(self.metadata['Xmp.iptcExt.PersonInImage'].raw_value)})")
|
||||
self._log.debug(f"People (before): {self.metadata['Xmp.iptcExt.PersonInImage'].raw_value} (type: {type(self.metadata['Xmp.iptcExt.PersonInImage'].raw_value)})")
|
||||
self.append_people(people)
|
||||
print(f"People (after): {self.metadata['Xmp.iptcExt.PersonInImage'].raw_value} (type: {type(self.metadata['Xmp.iptcExt.PersonInImage'].raw_value)})")
|
||||
self._log.debug(f"People (after): {self.metadata['Xmp.iptcExt.PersonInImage'].raw_value} (type: {type(self.metadata['Xmp.iptcExt.PersonInImage'].raw_value)})")
|
||||
self.metadata.write()
|
||||
self._log.debug(f"Updated file '{file}'.")
|
||||
if 'Exif.Photo.DateTimeOriginal' in self.metadata.exif_keys:
|
||||
self._log.debug(f"File time stamp: {self.metadata['Exif.Photo.DateTimeOriginal'].raw_value} (type: {type(self.metadata['Exif.Photo.DateTimeOriginal'].raw_value)})")
|
||||
original_date = self.metadata['Exif.Photo.DateTimeOriginal'].value
|
||||
self._log.debug(f"File creation time: {original_date} (type: {type(original_date)})")
|
||||
dirname = os.path.dirname(os.path.realpath(file))
|
||||
filename = os.path.basename(file)
|
||||
new_path = os.path.join(dirname, original_date.strftime('%Y/%m/%d'), filename)
|
||||
self._log.debug(f"New path: {new_path}")
|
||||
os.makedirs(os.path.dirname(new_path), exist_ok=True)
|
||||
# if new_path:
|
||||
# shutil.move(file, new_path)
|
||||
# move to destination
|
||||
else:
|
||||
self._log.debug("Doesn't seem to be an image.")
|
||||
|
|
|
@ -1,5 +1,4 @@
|
|||
click
|
||||
click_config_file
|
||||
face_recognition
|
||||
exif
|
||||
iptcinfo3
|
||||
py3exiv2
|
Loading…
Reference in a new issue