From 4b67f639061911f07442f05484114f0c4cddc64e Mon Sep 17 00:00:00 2001 From: Leonard Kugis Date: Sun, 9 Apr 2023 05:40:53 +0200 Subject: Implemented metadata tagging --- file-tagger.py | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) (limited to 'file-tagger.py') diff --git a/file-tagger.py b/file-tagger.py index 9708dfa..67e1102 100644 --- a/file-tagger.py +++ b/file-tagger.py @@ -9,6 +9,7 @@ from tmsu import * from util import * from predictor import * from PIL import Image +import datetime ''' Walk over all files for the given base directory and all subdirectories recursively. @@ -54,6 +55,28 @@ def walk(tmsu, args): if args["open_system"]: open_system(file_path) + if args["tag_metadata"]: + # Base name and extension + base = os.path.splitext(os.path.basename(file_path)) + if base[1]: + tags.update({base[0], base[1]}) + else: + tags.update({base[0]}) + # File creation and modification time + time_c = datetime.datetime.fromtimestamp(os.path.getctime(file_path)) + time_m = datetime.datetime.fromtimestamp(os.path.getmtime(file_path)) + tags.update({time_c.strftime("%Y-%m-%d"), + time_c.strftime("%Y"), + time_c.strftime("%B"), + time_c.strftime("%A"), + time_c.strftime("%Hh")}) + if time_c != time_m: + tags.update({time_m.strftime("%Y-%m-%d"), + time_m.strftime("%Y"), + time_m.strftime("%B"), + time_m.strftime("%A"), + time_m.strftime("%Hh")}) + # Detect MIME-type for file mime_type = mime.from_file(file_path) @@ -106,6 +129,7 @@ if __name__ == "__main__": parser.add_argument('-f', '--file-dir', nargs='?', default='.', type=dir_path, help='File directory for walking (default: %(default)s)') parser.add_argument('-g', '--gui', nargs='?', const=1, default=False, type=bool, help='Show main GUI (default: %(default)s)') parser.add_argument('--tmsu-command', nargs='?', const=1, default="tmsu", type=str, help='TMSU command override (default: %(default)s)') + parser.add_argument('--tag-metadata', nargs='?', const=1, default=True, type=bool, help='Use metadata as default tags (default: %(default)s)') parser.add_argument('--predict-images', nargs='?', const=1, default=False, type=bool, help='Use prediction for image tagging (default: %(default)s)') parser.add_argument('--predict-images-backend', nargs='?', const=1, choices=["torch", "tensorflow", "keras"], default="torch", type=str.lower, help='Determines which backend should be used for keyword prediction (default: %(default)s)') parser.add_argument('--predict-images-top', nargs='?', const=1, default=10, type=int, help='Defines how many top prediction keywords should be used (default: %(default)s)') @@ -135,6 +159,7 @@ if __name__ == "__main__": "file_dir": args.file_dir, "gui": args.gui, "tmsu_command": args.tmsu_command, + "tag_metadata": args.tag_metadata, "predict_images": args.predict_images, "predict_images_backend": args.predict_images_backend, "predict_images_top": args.predict_images_top, -- cgit v1.2.1