fix move with no faces

This commit is contained in:
Antonio J. Delgado 2021-09-08 14:41:40 +03:00
parent 7422b25bf6
commit 0850f4af39

View file

@ -86,29 +86,27 @@ class image_classifier:
self._log.debug(f"Updated file '{file}'.") self._log.debug(f"Updated file '{file}'.")
dirname = os.path.dirname(os.path.realpath(file)) dirname = os.path.dirname(os.path.realpath(file))
filename = os.path.basename(file) filename = os.path.basename(file)
if not self.no_move: if not self.no_move:
new_path = False new_path = False
if 'Exif.Photo.DateTimeOriginal' in self.metadata.exif_keys: if 'Exif.Photo.DateTimeOriginal' in self.metadata.exif_keys:
original_date = self.metadata['Exif.Photo.DateTimeOriginal'].value original_date = self.metadata['Exif.Photo.DateTimeOriginal'].value
self._log.debug(f"File creation time: {original_date} (type: {type(original_date)})") 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) new_path = os.path.join(dirname, original_date.strftime('%Y/%m/%d'), filename)
if not new_path: if not new_path:
match = re.search(r'(?P<year>20[0-9]{2})[\-/\._]?(?P<month>[0-1]?[0-9])[\-/\._]?(?P<day>[0-3]?[0-9])', filename) match = re.search(r'(?P<year>20[0-9]{2})[\-/\._]?(?P<month>[0-1]?[0-9])[\-/\._]?(?P<day>[0-3]?[0-9])', filename)
if match: if match:
new_path = os.path.join(dirname, match.group('year'), match.group('month'), match.group('day'), filename) new_path = os.path.join(dirname, match.group('year'), match.group('month'), match.group('day'), filename)
if not new_path: if not new_path:
match = re.search(r'(?P<day>[0-3]?[0-9])[\-/\._]?(?P<month>[0-1]?[0-9])[\-/\._]?(?P<year>20[0-9]{2})', filename) match = re.search(r'(?P<day>[0-3]?[0-9])[\-/\._]?(?P<month>[0-1]?[0-9])[\-/\._]?(?P<year>20[0-9]{2})', filename)
if match: if match:
new_path = os.path.join(dirname, match.group('year'), match.group('month'), match.group('day'), filename) new_path = os.path.join(dirname, match.group('year'), match.group('month'), match.group('day'), filename)
if not new_path: if not new_path:
new_path = os.path.join(dirname, 'unknown-time', filename) new_path = os.path.join(dirname, 'unknown-time', filename)
os.makedirs(os.path.dirname(new_path), exist_ok=True) os.makedirs(os.path.dirname(new_path), exist_ok=True)
self._log.info(f"Moving file '{file}' to '{new_path}'...") self._log.info(f"Moving file '{file}' to '{new_path}'...")
shutil.move(file, new_path) shutil.move(file, new_path)
else:
self._log.debug('Not moving to subfolders.')
else: else:
self._log.debug("Doesn't seem to be an image.") self._log.debug('Not moving to subfolders.')
def print_metadata(self): def print_metadata(self):
print("IPTC keys:") print("IPTC keys:")