Add option to not move
This commit is contained in:
parent
449f04bf9d
commit
c1e3e17e7d
1 changed files with 16 additions and 14 deletions
|
@ -45,7 +45,7 @@ class CustomFormatter(logging.Formatter):
|
|||
|
||||
class image_classifier:
|
||||
|
||||
def __init__(self, debug_level, log_file, faces_directory, directory):
|
||||
def __init__(self, debug_level, log_file, faces_directory, directory, no_move):
|
||||
''' Initial function called when object is created '''
|
||||
self.debug_level = debug_level
|
||||
if log_file is None:
|
||||
|
@ -55,6 +55,7 @@ class image_classifier:
|
|||
self.faces_directory = faces_directory
|
||||
self.directory = directory
|
||||
self.known_people = self.load_known_people()
|
||||
self.no_move = no_move
|
||||
|
||||
if os.access(directory, os.R_OK):
|
||||
with os.scandir(directory) as directory_item:
|
||||
|
@ -82,6 +83,7 @@ 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.metadata.write()
|
||||
self._log.debug(f"Updated file '{file}'.")
|
||||
if not self.no_move:
|
||||
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)})")
|
||||
|
@ -90,9 +92,8 @@ class image_classifier:
|
|||
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
|
||||
if new_path:
|
||||
shutil.move(file, new_path)
|
||||
else:
|
||||
self._log.debug("Doesn't seem to be an image.")
|
||||
|
||||
|
@ -200,9 +201,10 @@ class image_classifier:
|
|||
@click.option('--log-file', '-l', help="File to store all debug messages.")
|
||||
@click.option("--faces-directory","-f", required=True, help="Folder containing the pictures that identify people. The filename would be used as the name for the person. Just one person per picture.")
|
||||
@click.option("--directory","-d", required=True, help="Folder containing the pictures to classify.")
|
||||
@click.option("--no-move","-n", is_flag=True, help="Don't move files, just add people's tag.")
|
||||
@click_config_file.configuration_option()
|
||||
def __main__(debug_level, log_file, faces_directory, directory):
|
||||
object = image_classifier(debug_level, log_file, faces_directory, directory)
|
||||
def __main__(debug_level, log_file, faces_directory, directory, no_move):
|
||||
object = image_classifier(debug_level, log_file, faces_directory, directory, no_move)
|
||||
|
||||
if __name__ == "__main__":
|
||||
__main__()
|
||||
|
|
Loading…
Reference in a new issue