Move no-images files
This commit is contained in:
parent
85d32849a0
commit
2eca1c6c15
1 changed files with 21 additions and 21 deletions
|
@ -76,6 +76,7 @@ class image_classifier:
|
||||||
self.metadata.read()
|
self.metadata.read()
|
||||||
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)
|
||||||
|
new_path = False
|
||||||
people = self.find_faces(file)
|
people = self.find_faces(file)
|
||||||
if people:
|
if people:
|
||||||
self._log.debug(f"Found {len(people)} known people in the image.")
|
self._log.debug(f"Found {len(people)} known people in the image.")
|
||||||
|
@ -86,27 +87,26 @@ class image_classifier:
|
||||||
self._log.debug(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.metadata.write()
|
||||||
self._log.debug(f"Updated file '{file}'.")
|
self._log.debug(f"Updated file '{file}'.")
|
||||||
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)
|
if self.no_move == False:
|
||||||
if self.no_move == False:
|
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:
|
||||||
else:
|
self._log.info(f"NOT moving file '{file}' to '{new_path}' because of --no-move")
|
||||||
self._log.info(f"NOT moving file '{file}' to '{new_path}' because of --no-move")
|
|
||||||
|
|
||||||
def print_metadata(self):
|
def print_metadata(self):
|
||||||
print("IPTC keys:")
|
print("IPTC keys:")
|
||||||
|
|
Loading…
Reference in a new issue