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:
|
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 '''
|
''' Initial function called when object is created '''
|
||||||
self.debug_level = debug_level
|
self.debug_level = debug_level
|
||||||
if log_file is None:
|
if log_file is None:
|
||||||
|
@ -55,6 +55,7 @@ class image_classifier:
|
||||||
self.faces_directory = faces_directory
|
self.faces_directory = faces_directory
|
||||||
self.directory = directory
|
self.directory = directory
|
||||||
self.known_people = self.load_known_people()
|
self.known_people = self.load_known_people()
|
||||||
|
self.no_move = no_move
|
||||||
|
|
||||||
if os.access(directory, os.R_OK):
|
if os.access(directory, os.R_OK):
|
||||||
with os.scandir(directory) as directory_item:
|
with os.scandir(directory) as directory_item:
|
||||||
|
@ -82,17 +83,17 @@ 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}'.")
|
||||||
if 'Exif.Photo.DateTimeOriginal' in self.metadata.exif_keys:
|
if not self.no_move:
|
||||||
original_date = self.metadata['Exif.Photo.DateTimeOriginal'].value
|
if 'Exif.Photo.DateTimeOriginal' in self.metadata.exif_keys:
|
||||||
self._log.debug(f"File creation time: {original_date} (type: {type(original_date)})")
|
original_date = self.metadata['Exif.Photo.DateTimeOriginal'].value
|
||||||
dirname = os.path.dirname(os.path.realpath(file))
|
self._log.debug(f"File creation time: {original_date} (type: {type(original_date)})")
|
||||||
filename = os.path.basename(file)
|
dirname = os.path.dirname(os.path.realpath(file))
|
||||||
new_path = os.path.join(dirname, original_date.strftime('%Y/%m/%d'), filename)
|
filename = os.path.basename(file)
|
||||||
self._log.debug(f"New path: {new_path}")
|
new_path = os.path.join(dirname, original_date.strftime('%Y/%m/%d'), filename)
|
||||||
os.makedirs(os.path.dirname(new_path), exist_ok=True)
|
self._log.debug(f"New path: {new_path}")
|
||||||
# if new_path:
|
os.makedirs(os.path.dirname(new_path), exist_ok=True)
|
||||||
# shutil.move(file, new_path)
|
if new_path:
|
||||||
# move to destination
|
shutil.move(file, new_path)
|
||||||
else:
|
else:
|
||||||
self._log.debug("Doesn't seem to be an image.")
|
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('--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("--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("--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()
|
@click_config_file.configuration_option()
|
||||||
def __main__(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)
|
object = image_classifier(debug_level, log_file, faces_directory, directory, no_move)
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
__main__()
|
__main__()
|
||||||
|
|
Loading…
Reference in a new issue