From 6a44a6143f453346f74c4f160200460adc7cbb54 Mon Sep 17 00:00:00 2001 From: Leonard Kugis Date: Tue, 11 Apr 2023 02:49:17 +0200 Subject: Implemented renaming schemes --- file-tagger.py | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) (limited to 'file-tagger.py') diff --git a/file-tagger.py b/file-tagger.py index d7d572b..4d25e90 100644 --- a/file-tagger.py +++ b/file-tagger.py @@ -48,6 +48,20 @@ def walk(tmsu, args): not_empty = bool(tags) logger.info("Existing tags: {}".format(tags)) + if ".tmsu" in file_path: + logger.info("Database meta file, skipping.") + continue + + logger.info("Renaming file {}".format(file_path)) + file_path = files[i] = { + "none": lambda x: x, + "sha1": rename_sha1, + "sha256": rename_sha256, + "cdate": rename_cdate, + "mdate": rename_mdate + }.get(args["rename"])(file_path) + logger.info("New file name: {}".format(file_path)) + if (not_empty and args["skip_tagged"]): logger.info("Already tagged, skipping.") continue @@ -158,6 +172,7 @@ def walk(tmsu, args): if ((not args["gui_tag"]) and (not args["skip_prompt"])): tags = set(input_with_prefill("\nTags for file {}:\n".format(file_path), ','.join(tags)).split(",")) + tags = { tag.lower().replace(" ", "_") for tag in tags } logger.info("Tagging {}".format(tags)) tmsu.tag(file_path, tags, untag=not_empty) @@ -168,6 +183,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('-r', '--rename', nargs='?', const=1, choices=["none", "sha1", "sha256", "cdate", "mdate"], default="none", type=str.lower, help='Rename files based on given scheme (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)') @@ -200,6 +216,7 @@ if __name__ == "__main__": "file_dir": args.file_dir, "gui": args.gui, "tmsu_command": args.tmsu_command, + "rename": args.rename, "tag_metadata": args.tag_metadata, "predict_images": args.predict_images, "predict_images_backend": args.predict_images_backend, -- cgit v1.2.1