From 0850f4af391d686383c6aa571eda753c20f6a5fc Mon Sep 17 00:00:00 2001 From: "Antonio J. Delgado" Date: Wed, 8 Sep 2021 14:41:40 +0300 Subject: [PATCH] fix move with no faces --- image_classifier/image_classifier.py | 44 +++++++++++++--------------- 1 file changed, 21 insertions(+), 23 deletions(-) diff --git a/image_classifier/image_classifier.py b/image_classifier/image_classifier.py index ad1b3bf..e2d321a 100755 --- a/image_classifier/image_classifier.py +++ b/image_classifier/image_classifier.py @@ -86,30 +86,28 @@ class image_classifier: self._log.debug(f"Updated file '{file}'.") dirname = os.path.dirname(os.path.realpath(file)) filename = os.path.basename(file) - if not self.no_move: - new_path = False - if 'Exif.Photo.DateTimeOriginal' in self.metadata.exif_keys: - original_date = self.metadata['Exif.Photo.DateTimeOriginal'].value - self._log.debug(f"File creation time: {original_date} (type: {type(original_date)})") - new_path = os.path.join(dirname, original_date.strftime('%Y/%m/%d'), filename) - if not new_path: - match = re.search(r'(?P20[0-9]{2})[\-/\._]?(?P[0-1]?[0-9])[\-/\._]?(?P[0-3]?[0-9])', filename) - if match: - new_path = os.path.join(dirname, match.group('year'), match.group('month'), match.group('day'), filename) - if not new_path: - match = re.search(r'(?P[0-3]?[0-9])[\-/\._]?(?P[0-1]?[0-9])[\-/\._]?(?P20[0-9]{2})', filename) - if match: - new_path = os.path.join(dirname, match.group('year'), match.group('month'), match.group('day'), filename) - if not new_path: - new_path = os.path.join(dirname, 'unknown-time', filename) - os.makedirs(os.path.dirname(new_path), exist_ok=True) - self._log.info(f"Moving file '{file}' to '{new_path}'...") - shutil.move(file, new_path) - else: - self._log.debug('Not moving to subfolders.') + if not self.no_move: + new_path = False + if 'Exif.Photo.DateTimeOriginal' in self.metadata.exif_keys: + original_date = self.metadata['Exif.Photo.DateTimeOriginal'].value + self._log.debug(f"File creation time: {original_date} (type: {type(original_date)})") + new_path = os.path.join(dirname, original_date.strftime('%Y/%m/%d'), filename) + if not new_path: + match = re.search(r'(?P20[0-9]{2})[\-/\._]?(?P[0-1]?[0-9])[\-/\._]?(?P[0-3]?[0-9])', filename) + if match: + new_path = os.path.join(dirname, match.group('year'), match.group('month'), match.group('day'), filename) + if not new_path: + match = re.search(r'(?P[0-3]?[0-9])[\-/\._]?(?P[0-1]?[0-9])[\-/\._]?(?P20[0-9]{2})', filename) + if match: + new_path = os.path.join(dirname, match.group('year'), match.group('month'), match.group('day'), filename) + if not new_path: + new_path = os.path.join(dirname, 'unknown-time', filename) + os.makedirs(os.path.dirname(new_path), exist_ok=True) + self._log.info(f"Moving file '{file}' to '{new_path}'...") + shutil.move(file, new_path) else: - self._log.debug("Doesn't seem to be an image.") - + self._log.debug('Not moving to subfolders.') + def print_metadata(self): print("IPTC keys:") for key in self.metadata.iptc_keys: