From b8788494eead978a460dafdf9a5623a0c61824dc Mon Sep 17 00:00:00 2001 From: Elkorol Date: Mon, 19 Feb 2024 03:00:50 +0000 Subject: [PATCH 1/6] Additional Files Deleter --- plugins/addtionalFilesDeleter/README.md | 18 ++ plugins/addtionalFilesDeleter/deleter.py | 236 ++++++++++++++++++ plugins/addtionalFilesDeleter/deleter.yml | 32 +++ .../addtionalFilesDeleter/requirements.txt | 1 + 4 files changed, 287 insertions(+) create mode 100644 plugins/addtionalFilesDeleter/README.md create mode 100644 plugins/addtionalFilesDeleter/deleter.py create mode 100644 plugins/addtionalFilesDeleter/deleter.yml create mode 100644 plugins/addtionalFilesDeleter/requirements.txt diff --git a/plugins/addtionalFilesDeleter/README.md b/plugins/addtionalFilesDeleter/README.md new file mode 100644 index 00000000..3621cab8 --- /dev/null +++ b/plugins/addtionalFilesDeleter/README.md @@ -0,0 +1,18 @@ +# Addtional Files Deleter + +This is a plugin that will scan your Stash for either scenes or images where the file count is above 1. It will then skip over the primary file for each scene or image object and delete these extra files. Usually scene that contain multiple files are identical Phash matches (Unless you have manually merged unidentical Phashed files). Image objects that contain multiple files are grouped together under identical checksums, not Phashes. (You can't manually merge images as of yet.) + +## Usage + +Copy repository into Stash plugins folder or add via the new plugins system and refresh your plugins from the Settings. + +If on first run you may want to run the Create Tag task, which creates an ignore tag that you can apply to Scenes or Images, so that they are bypassed when any of the other tasks are run. + +Other than Create Tag task you can run the following tasks. + +Images - Delete +Images - Delete & Record +Scenes - Delete +Scenes - Delete & Record + +Tasks that just specify delete will just delete addtional files from their respective objects and Delete & Record will take the file paths of the files to be deleted, prefix them with "File: " (For latter easy searching) and it will append them to the current list of urls the object has and update the object. This is just a precaution to record perhaps usefull metadata an additional file path may hold for later use. diff --git a/plugins/addtionalFilesDeleter/deleter.py b/plugins/addtionalFilesDeleter/deleter.py new file mode 100644 index 00000000..9e556506 --- /dev/null +++ b/plugins/addtionalFilesDeleter/deleter.py @@ -0,0 +1,236 @@ +import sys +import json + +import stashapi.log as log +from stashapi.stashapp import StashInterface + +SVG_IMAGE = ( + "data:image/svg+xml;base64,PCFET0NUWVBFIHN2ZyBQVUJMSUMgIi0vL1czQy8vRFREIFNWRyAxLjEvL0VOIi" + "AiaHR0cDovL3d3dy53My5vcmcvR3JhcGhpY3MvU1ZHLzEuMS9EVEQvc3ZnMTEuZHRkIj4KDTwhLS0gVXBsb2FkZW" + "QgdG86IFNWRyBSZXBvLCB3d3cuc3ZncmVwby5jb20sIFRyYW5zZm9ybWVkIGJ5OiBTVkcgUmVwbyBNaXhlciBUb2" + "9scyAtLT4KPHN2ZyB3aWR0aD0iODAwcHgiIGhlaWdodD0iODAwcHgiIHZpZXdCb3g9IjAgMCAyNCAyNCIgZmlsbD" + "0ibm9uZSIgeG1sbnM9Imh0dHA6Ly93d3cudzMub3JnLzIwMDAvc3ZnIj4KDTxnIGlkPSJTVkdSZXBvX2JnQ2Fycm" + "llciIgc3Ryb2tlLXdpZHRoPSIwIi8+Cg08ZyBpZD0iU1ZHUmVwb190cmFjZXJDYXJyaWVyIiBzdHJva2UtbGluZW" + "NhcD0icm91bmQiIHN0cm9rZS1saW5lam9pbj0icm91bmQiLz4KDTxnIGlkPSJTVkdSZXBvX2ljb25DYXJyaWVyIj" + "4gPHBhdGggZD0iTTUuNjM2MDUgNS42MzYwNUwxOC4zNjQgMTguMzY0TTUuNjM2MDUgMTguMzY0TDE4LjM2NCA1Lj" + "YzNjA1TTIxIDEyQzIxIDE2Ljk3MDYgMTYuOTcwNiAyMSAxMiAyMUM3LjAyOTQ0IDIxIDMgMTYuOTcwNiAzIDEyQz" + "MgNy4wMjk0NCA3LjAyOTQ0IDMgMTIgM0MxNi45NzA2IDMgMjEgNy4wMjk0NCAyMSAxMloiIHN0cm9rZT0iI2ZmZm" + "ZmZiIgc3Ryb2tlLXdpZHRoPSIxLjUiIHN0cm9rZS1saW5lY2FwPSJyb3VuZCIvPiA8L2c+Cg08L3N2Zz4=" +) + + +tag_exclude = { + "name": "Addtional Files Deleter: Scenes/Images: Ignore", + "description": "Addtional Files Deleter: Scene/Image Objects that contain addtional files " + "will not be deleted", + "image": SVG_IMAGE +} + + +def main(): + global stash + + json_input = json.loads(sys.stdin.read()) + mode_arg = json_input["args"]["mode"] + + stash = StashInterface(json_input["server_connection"]) + + if mode_arg == "create_tag": + create_tag(tag_exclude) + if mode_arg == "remove_tag": + remove_tag() + if mode_arg == "images_delete": + images_delete() + if mode_arg == "images_delete_record_paths": + images_delete_record_paths() + if mode_arg == "scenes_delete": + scenes_delete() + if mode_arg == "scenes_delete_record_paths": + scenes_delete_record_paths() + + +def update_image(image_id, paths): + update = stash.update_image( + {'id': image_id, 'urls': paths}) + return update + + +def update_scene(scene_id, paths): + update = stash.update_scene( + {'id': scene_id, 'urls': paths}) + return update + + +def find_images(find_images_tag): + log.debug(f"Hello: {find_images_tag}") + images = stash.find_images( + f={ + "file_count": {"modifier": "GREATER_THAN", "value": 1}, + "tags": {"modifier": "EXCLUDES", "value": find_images_tag}, + }, + filter={ + "per_page": "-1" + } + ) + return images + + +def find_scenes(find_scenes_tag): + scenes = stash.find_scenes( + f={ + "file_count": {"modifier": "GREATER_THAN", "value": 1}, + "tags": {"modifier": "EXCLUDES", "value": find_scenes_tag}, + } + ) + return scenes + + +def find_tag(name, create=False): + find_tag_tag = stash.find_tag(name, create) + if find_tag_tag is None: + log.error(f"Tag does not exist: {tag_exclude['name']}") + else: + log.info(f"Found Tag: ID:{find_tag_tag['id']} Name: { + find_tag_tag['name']}") + return find_tag_tag + + +def create_tag(obj): + create_tag_tag = stash.create_tag(obj) + + if create_tag_tag is None: + log.error(f'Tag already exists: {tag_exclude["name"]}') + else: + log.info(f"Created Tag: ID:{create_tag_tag['id']} Name: { + create_tag_tag['name']}") + return create_tag_tag + + +def remove_tag(): + remove_tag_tag = find_tag(tag_exclude["name"]) + if remove_tag_tag is not None: + stash.destroy_tag(remove_tag_tag['id']) + log.info( + f"Deleted Tag - ID:{remove_tag_tag['id']}: Name: {remove_tag_tag['name']}") + + +def images_delete(): + log.info("Addtional Files Deleter: Initialised with Args: images_delete") + images_delete_tag = find_tag(tag_exclude) + + if images_delete_tag is None: + images_delete_tag = create_tag(tag_exclude) + + images = find_images(images_delete_tag["id"]) + + for image in images: + log.info( + f"ID:{image['id']} - Deleting addtional files from Image Object") + for i, file in enumerate(image["visual_files"]): + if i == 0: # skip first ID + continue + delete = stash.destroy_files(file["id"]) + if delete is True: + log.info(f"File ID:{file['id']} - Deleted: {file['path']}") + else: + log.error( + f"File ID:{file['id']} - Could not be Deleted: {file['path']}") + + +def images_delete_record_paths(): + log.info( + "Addtional Files Deleter: Initialised with Args: images_delete_record_paths") + images_delete_record_tag = find_tag(tag_exclude) + + if images_delete_record_tag is None: + images_delete_record_tag = create_tag(tag_exclude) + + images = find_images(images_delete_record_tag["id"]) + for image in images: + image_id = image["id"] + paths = image["urls"] + log.info(f"ID:{image_id} - Image object: Deleting addtional files and recording path(s) " + "in URLs Field") + for i, file in enumerate(image["visual_files"]): + if i == 0: # skip first ID + continue + path = file["path"] + delete = stash.destroy_files(file["id"]) + if delete is True: + log.info(f"ID:{file['id']} - deleted: {path}") + paths.append("File: " + path) + else: + log.error(f"ID:{file['id']} - Could not be deleted: {path}") + log.info(f"Updating Image ID:{ + image_id}: URLs with path(s): {paths}") + update = update_image(image_id, paths) + if update is not None: + log.info( + f"Image ID:{image_id}: Updated with path(s) as URLs: {path}") + else: + log.error(f"Image ID:{image_id}: Could not be updated with path(s) as URLs: " + "{path}") + + +def scenes_delete(): + log.info("Addtional Files Deleter: Initialised with Args: scenes_delete") + scenes_delete_tag = find_tag(tag_exclude) + + if scenes_delete_tag is None: + scenes_delete_tag = create_tag(tag_exclude) + + scenes = find_scenes(scenes_delete_tag["id"]) + for scene in scenes: + log.info(f"Scene: {scene}") + + log.info( + f"ID:{scene['id']} - Deleting addtional files from Scene Object") + for i, file in enumerate(scene["files"]): + if i == 0: # skip first ID + continue + delete = stash.destroy_files(file["id"]) + if delete is True: + log.info(f"File ID:{file['id']} - Deleted: {file['path']}") + else: + log.error( + f"File ID:{file['id']} - Ccould not be Deleted: {file['path']}") + + +def scenes_delete_record_paths(): + log.info( + "Addtional Files Deleter: Initialised with Args: scenes_delete_record_paths") + # ... rest of the function + scenes_delete_record_tag = find_tag(tag_exclude) + + if scenes_delete_record_tag is None: + scenes_delete_record_tag = create_tag(tag_exclude) + + scenes = find_scenes(scenes_delete_record_tag["id"]) + for scene in scenes: + scene_id = scene["id"] + paths = scene["urls"] + log.info(f"ID:{id} - Scene object: Deleting addtional files and recording path(s) in URLs" + "Field") + for i, file in enumerate(scene["files"]): + if i == 0: # skip first ID + continue + path = file["path"] + delete = stash.destroy_files(file["id"]) + if delete is True: + log.info(f"ID:{file['id']} - Deleted: {path}") + paths.append("File: " + path) + else: + log.error(f"ID:{file['id']} - Could not be Deleted: {path}") + log.info(f"Updating Scene ID:{ + scene_id}: URLs with path(s): {paths}") + update = update_scene(scene_id, paths) + if update is not None: + log.info( + f"Scene ID:{scene_id}: Updated with path(s) as URLs: {path}") + else: + log.error(f"Scene ID:{scene_id}: Could not be updated with path(s) as URLs: " + "{path}") + + +if __name__ == "__main__": + main() diff --git a/plugins/addtionalFilesDeleter/deleter.yml b/plugins/addtionalFilesDeleter/deleter.yml new file mode 100644 index 00000000..456e7ceb --- /dev/null +++ b/plugins/addtionalFilesDeleter/deleter.yml @@ -0,0 +1,32 @@ +name: Addtional Files Deleter +description: Deletes addtional files assosiated with an image or scene object. Which will usually have identical PHashes for scenes or Checksum for images. Unless is a scene manually merged. Apply ignore tag to scene/image object for plugin to bypass. +version: 0.1 +exec: + - python + - "{pluginDir}/deleter.py" +interface: raw +tasks: + - name: Create Tag + description: Create the plugin Ignore Tag + defaultArgs: + mode: create_tag + - name: Remove Tag + description: Remove the plugin Ignore Tag + defaultArgs: + mode: remove_tag + - name: Images - Delete + description: Image objects that contain addtional files will be deleted + defaultArgs: + mode: images_delete + - name: Images - Delete & Record + description: Addtional files will be deleted & old paths will be stored in Image object URLs field (Incase they contain future needed metadata) + defaultArgs: + mode: images_delete_record_paths + - name: Scenes - Delete + description: Scene objects that contain addtional files will be deleted + defaultArgs: + mode: scenes_delete + - name: Scenes - Delete & Record + description: Addtional files will be deleted & old paths will be stored in Scene object URLs field (Incase they contain future needed metadata) + defaultArgs: + mode: scenes_delete_record_paths diff --git a/plugins/addtionalFilesDeleter/requirements.txt b/plugins/addtionalFilesDeleter/requirements.txt new file mode 100644 index 00000000..eeba91d4 --- /dev/null +++ b/plugins/addtionalFilesDeleter/requirements.txt @@ -0,0 +1 @@ +stashapp-tools==0.2.40 \ No newline at end of file From de8b83c1aa01233afc8d9a23d0b0a92324717093 Mon Sep 17 00:00:00 2001 From: Elkorol Date: Mon, 19 Feb 2024 03:14:07 +0000 Subject: [PATCH 2/6] Ran Formatter --- plugins/addtionalFilesDeleter/deleter.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/plugins/addtionalFilesDeleter/deleter.py b/plugins/addtionalFilesDeleter/deleter.py index 9e556506..7eaebed4 100644 --- a/plugins/addtionalFilesDeleter/deleter.py +++ b/plugins/addtionalFilesDeleter/deleter.py @@ -90,8 +90,7 @@ def find_tag(name, create=False): if find_tag_tag is None: log.error(f"Tag does not exist: {tag_exclude['name']}") else: - log.info(f"Found Tag: ID:{find_tag_tag['id']} Name: { - find_tag_tag['name']}") + log.info(f"Found Tag: ID:{find_tag_tag['id']} Name: {find_tag_tag['name']}") return find_tag_tag From 2ad89877c17e97aec8fd4a9590e47b39d9388847 Mon Sep 17 00:00:00 2001 From: Elkorol Date: Mon, 19 Feb 2024 03:17:17 +0000 Subject: [PATCH 3/6] Ran Formatter Again --- plugins/addtionalFilesDeleter/deleter.py | 40 ++++++++---------------- 1 file changed, 13 insertions(+), 27 deletions(-) diff --git a/plugins/addtionalFilesDeleter/deleter.py b/plugins/addtionalFilesDeleter/deleter.py index 7eaebed4..77730060 100644 --- a/plugins/addtionalFilesDeleter/deleter.py +++ b/plugins/addtionalFilesDeleter/deleter.py @@ -100,8 +100,7 @@ def create_tag(obj): if create_tag_tag is None: log.error(f'Tag already exists: {tag_exclude["name"]}') else: - log.info(f"Created Tag: ID:{create_tag_tag['id']} Name: { - create_tag_tag['name']}") + log.info(f"Created Tag: ID:{create_tag_tag['id']} Name: {create_tag_tag['name']}") return create_tag_tag @@ -109,8 +108,7 @@ def remove_tag(): remove_tag_tag = find_tag(tag_exclude["name"]) if remove_tag_tag is not None: stash.destroy_tag(remove_tag_tag['id']) - log.info( - f"Deleted Tag - ID:{remove_tag_tag['id']}: Name: {remove_tag_tag['name']}") + log.info(f"Deleted Tag - ID:{remove_tag_tag['id']}: Name: {remove_tag_tag['name']}") def images_delete(): @@ -123,8 +121,7 @@ def images_delete(): images = find_images(images_delete_tag["id"]) for image in images: - log.info( - f"ID:{image['id']} - Deleting addtional files from Image Object") + log.info(f"ID:{image['id']} - Deleting addtional files from Image Object") for i, file in enumerate(image["visual_files"]): if i == 0: # skip first ID continue @@ -132,13 +129,11 @@ def images_delete(): if delete is True: log.info(f"File ID:{file['id']} - Deleted: {file['path']}") else: - log.error( - f"File ID:{file['id']} - Could not be Deleted: {file['path']}") + log.error(f"File ID:{file['id']} - Could not be Deleted: {file['path']}") def images_delete_record_paths(): - log.info( - "Addtional Files Deleter: Initialised with Args: images_delete_record_paths") + log.info("Addtional Files Deleter: Initialised with Args: images_delete_record_paths") images_delete_record_tag = find_tag(tag_exclude) if images_delete_record_tag is None: @@ -148,8 +143,7 @@ def images_delete_record_paths(): for image in images: image_id = image["id"] paths = image["urls"] - log.info(f"ID:{image_id} - Image object: Deleting addtional files and recording path(s) " - "in URLs Field") + log.info(f"ID:{image_id} - Image object: Deleting addtional files and recording path(s) in URLs Field") for i, file in enumerate(image["visual_files"]): if i == 0: # skip first ID continue @@ -160,15 +154,12 @@ def images_delete_record_paths(): paths.append("File: " + path) else: log.error(f"ID:{file['id']} - Could not be deleted: {path}") - log.info(f"Updating Image ID:{ - image_id}: URLs with path(s): {paths}") + log.info(f"Updating Image ID:{image_id}: URLs with path(s): {paths}") update = update_image(image_id, paths) if update is not None: - log.info( - f"Image ID:{image_id}: Updated with path(s) as URLs: {path}") + log.info(f"Image ID:{image_id}: Updated with path(s) as URLs: {path}") else: - log.error(f"Image ID:{image_id}: Could not be updated with path(s) as URLs: " - "{path}") + log.error(f"Image ID:{image_id}: Could not be updated with path(s) as URLs: {path}") def scenes_delete(): @@ -182,8 +173,7 @@ def scenes_delete(): for scene in scenes: log.info(f"Scene: {scene}") - log.info( - f"ID:{scene['id']} - Deleting addtional files from Scene Object") + log.info(f"ID:{scene['id']} - Deleting addtional files from Scene Object") for i, file in enumerate(scene["files"]): if i == 0: # skip first ID continue @@ -196,9 +186,7 @@ def scenes_delete(): def scenes_delete_record_paths(): - log.info( - "Addtional Files Deleter: Initialised with Args: scenes_delete_record_paths") - # ... rest of the function + log.info("Addtional Files Deleter: Initialised with Args: scenes_delete_record_paths") scenes_delete_record_tag = find_tag(tag_exclude) if scenes_delete_record_tag is None: @@ -208,8 +196,7 @@ def scenes_delete_record_paths(): for scene in scenes: scene_id = scene["id"] paths = scene["urls"] - log.info(f"ID:{id} - Scene object: Deleting addtional files and recording path(s) in URLs" - "Field") + log.info(f"ID:{id} - Scene object: Deleting addtional files and recording path(s) in URLs Field") for i, file in enumerate(scene["files"]): if i == 0: # skip first ID continue @@ -227,8 +214,7 @@ def scenes_delete_record_paths(): log.info( f"Scene ID:{scene_id}: Updated with path(s) as URLs: {path}") else: - log.error(f"Scene ID:{scene_id}: Could not be updated with path(s) as URLs: " - "{path}") + log.error(f"Scene ID:{scene_id}: Could not be updated with path(s) as URLs: {path}") if __name__ == "__main__": From ab93d38eae1f06f6e7f3f44f9784855469639126 Mon Sep 17 00:00:00 2001 From: Elkorol Date: Mon, 19 Feb 2024 03:18:37 +0000 Subject: [PATCH 4/6] Ran Format again --- plugins/addtionalFilesDeleter/deleter.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/plugins/addtionalFilesDeleter/deleter.py b/plugins/addtionalFilesDeleter/deleter.py index 77730060..c12dca8b 100644 --- a/plugins/addtionalFilesDeleter/deleter.py +++ b/plugins/addtionalFilesDeleter/deleter.py @@ -207,8 +207,7 @@ def scenes_delete_record_paths(): paths.append("File: " + path) else: log.error(f"ID:{file['id']} - Could not be Deleted: {path}") - log.info(f"Updating Scene ID:{ - scene_id}: URLs with path(s): {paths}") + log.info(f"Updating Scene ID:{scene_id}: URLs with path(s): {paths}") update = update_scene(scene_id, paths) if update is not None: log.info( From 7456e067432ceee01999a8062f5ac7c759c8c722 Mon Sep 17 00:00:00 2001 From: Elkorol Date: Mon, 19 Feb 2024 17:28:55 +0000 Subject: [PATCH 5/6] Made Logging Better --- plugins/addtionalFilesDeleter/deleter.py | 123 +++++++++++------------ 1 file changed, 59 insertions(+), 64 deletions(-) diff --git a/plugins/addtionalFilesDeleter/deleter.py b/plugins/addtionalFilesDeleter/deleter.py index c12dca8b..50165b87 100644 --- a/plugins/addtionalFilesDeleter/deleter.py +++ b/plugins/addtionalFilesDeleter/deleter.py @@ -1,5 +1,4 @@ -import sys -import json +import sys, json import stashapi.log as log from stashapi.stashapp import StashInterface @@ -48,42 +47,42 @@ def main(): if mode_arg == "scenes_delete_record_paths": scenes_delete_record_paths() - def update_image(image_id, paths): update = stash.update_image( - {'id': image_id, 'urls': paths}) + {'id': image_id, 'urls': paths}) return update - def update_scene(scene_id, paths): update = stash.update_scene( - {'id': scene_id, 'urls': paths}) + {'id': scene_id, 'urls': paths}) return update - def find_images(find_images_tag): - log.debug(f"Hello: {find_images_tag}") - images = stash.find_images( - f={ - "file_count": {"modifier": "GREATER_THAN", "value": 1}, - "tags": {"modifier": "EXCLUDES", "value": find_images_tag}, - }, - filter={ - "per_page": "-1" - } - ) - return images + image_count, images = stash.find_images( + f={ + "file_count": {"modifier": "GREATER_THAN", "value": 1}, + "tags": {"modifier": "EXCLUDES", "value": find_images_tag}, + }, + filter={ + "per_page": "-1" + }, + get_count=True, +) + return image_count, images def find_scenes(find_scenes_tag): - scenes = stash.find_scenes( - f={ - "file_count": {"modifier": "GREATER_THAN", "value": 1}, - "tags": {"modifier": "EXCLUDES", "value": find_scenes_tag}, - } - ) - return scenes - + scene_count, scenes = stash.find_scenes( + f={ + "file_count": {"modifier": "GREATER_THAN", "value": 1}, + "tags": {"modifier": "EXCLUDES", "value": find_scenes_tag}, + }, + filter={ + "per_page": "-1" + }, + get_count=True, +) + return scene_count, scenes def find_tag(name, create=False): find_tag_tag = stash.find_tag(name, create) @@ -93,7 +92,6 @@ def find_tag(name, create=False): log.info(f"Found Tag: ID:{find_tag_tag['id']} Name: {find_tag_tag['name']}") return find_tag_tag - def create_tag(obj): create_tag_tag = stash.create_tag(obj) @@ -103,118 +101,115 @@ def create_tag(obj): log.info(f"Created Tag: ID:{create_tag_tag['id']} Name: {create_tag_tag['name']}") return create_tag_tag - def remove_tag(): remove_tag_tag = find_tag(tag_exclude["name"]) if remove_tag_tag is not None: stash.destroy_tag(remove_tag_tag['id']) log.info(f"Deleted Tag - ID:{remove_tag_tag['id']}: Name: {remove_tag_tag['name']}") - def images_delete(): - log.info("Addtional Files Deleter: Initialised with Args: images_delete") images_delete_tag = find_tag(tag_exclude) if images_delete_tag is None: images_delete_tag = create_tag(tag_exclude) - images = find_images(images_delete_tag["id"]) + image_count, images = find_images(images_delete_tag["id"]) + log.info(f"Deleting Addtional files of {image_count} image objects") + + for j, image in enumerate(images): + log.progress(j / image_count) - for image in images: - log.info(f"ID:{image['id']} - Deleting addtional files from Image Object") for i, file in enumerate(image["visual_files"]): if i == 0: # skip first ID continue delete = stash.destroy_files(file["id"]) if delete is True: - log.info(f"File ID:{file['id']} - Deleted: {file['path']}") + log.info(f"Image ID:{image['id']} - File ID:{file['id']} - Deleted: {file['path']}") else: - log.error(f"File ID:{file['id']} - Could not be Deleted: {file['path']}") - + log.error(f"Image ID:{image['id']} - File ID:{file['id']} - Could not be Deleted: {file['path']}") def images_delete_record_paths(): - log.info("Addtional Files Deleter: Initialised with Args: images_delete_record_paths") images_delete_record_tag = find_tag(tag_exclude) if images_delete_record_tag is None: images_delete_record_tag = create_tag(tag_exclude) - images = find_images(images_delete_record_tag["id"]) - for image in images: + image_count, images = find_images(images_delete_record_tag["id"]) + log.info(f"Deleting Addtional Images of {image_count} image objects and recording paths in URLs Field") + + for j, image in enumerate(images): image_id = image["id"] paths = image["urls"] - log.info(f"ID:{image_id} - Image object: Deleting addtional files and recording path(s) in URLs Field") + log.progress(j / image_count) + for i, file in enumerate(image["visual_files"]): if i == 0: # skip first ID continue path = file["path"] delete = stash.destroy_files(file["id"]) if delete is True: - log.info(f"ID:{file['id']} - deleted: {path}") + log.info(f"Image ID:{image['id']} - File ID:{file['id']} - Deleted: {path}") paths.append("File: " + path) else: - log.error(f"ID:{file['id']} - Could not be deleted: {path}") - log.info(f"Updating Image ID:{image_id}: URLs with path(s): {paths}") + log.error(f"Image ID:{image['id']} - File ID:{file['id']} - Could not be Deleted: {path}") update = update_image(image_id, paths) if update is not None: log.info(f"Image ID:{image_id}: Updated with path(s) as URLs: {path}") else: log.error(f"Image ID:{image_id}: Could not be updated with path(s) as URLs: {path}") - def scenes_delete(): - log.info("Addtional Files Deleter: Initialised with Args: scenes_delete") scenes_delete_tag = find_tag(tag_exclude) if scenes_delete_tag is None: scenes_delete_tag = create_tag(tag_exclude) - scenes = find_scenes(scenes_delete_tag["id"]) - for scene in scenes: - log.info(f"Scene: {scene}") + scene_count, scenes = find_scenes(scenes_delete_tag["id"]) + log.info(f"Deleting Addtional files of {scene_count} scene objects and recording paths in URLs Field") + + for j, scene in enumerate(scenes): + log.progress(j / scene_count) - log.info(f"ID:{scene['id']} - Deleting addtional files from Scene Object") for i, file in enumerate(scene["files"]): if i == 0: # skip first ID continue delete = stash.destroy_files(file["id"]) if delete is True: - log.info(f"File ID:{file['id']} - Deleted: {file['path']}") + log.info(f"Scene ID:{scene['id']} - File ID:{file['id']} - Deleted: {file['path']}") else: - log.error( - f"File ID:{file['id']} - Ccould not be Deleted: {file['path']}") - + log.error(f"Scene ID:{scene['id']} - File ID:{file['id']} - Could not be Deleted: {file['path']}") def scenes_delete_record_paths(): - log.info("Addtional Files Deleter: Initialised with Args: scenes_delete_record_paths") scenes_delete_record_tag = find_tag(tag_exclude) if scenes_delete_record_tag is None: scenes_delete_record_tag = create_tag(tag_exclude) - scenes = find_scenes(scenes_delete_record_tag["id"]) - for scene in scenes: + scene_count, scenes = find_scenes(scenes_delete_record_tag["id"]) + log.info(f"Deleting Addtional files of {scene_count} scene objects and recording paths in URLs Field") + + for j, scene in enumerate(scenes): + log.progress(j / scene_count) + scene_id = scene["id"] paths = scene["urls"] - log.info(f"ID:{id} - Scene object: Deleting addtional files and recording path(s) in URLs Field") + for i, file in enumerate(scene["files"]): if i == 0: # skip first ID continue path = file["path"] delete = stash.destroy_files(file["id"]) if delete is True: - log.info(f"ID:{file['id']} - Deleted: {path}") + log.info(f"Scene ID:{scene['id']} - File ID:{file['id']} - Deleted: {path}") paths.append("File: " + path) else: - log.error(f"ID:{file['id']} - Could not be Deleted: {path}") - log.info(f"Updating Scene ID:{scene_id}: URLs with path(s): {paths}") + log.error(f"Scene ID:{scene['id']} - File ID:{file['id']} - Could not be Deleted: {path}") update = update_scene(scene_id, paths) if update is not None: - log.info( - f"Scene ID:{scene_id}: Updated with path(s) as URLs: {path}") + log.info(f"Scene ID:{scene_id}: Updated with path(s) as URLs: {path}") else: - log.error(f"Scene ID:{scene_id}: Could not be updated with path(s) as URLs: {path}") - + log.error(f"Scene ID:{scene_id}: Could not be updated with path(s) as URLs: " + "{path}") if __name__ == "__main__": main() From f6523bc503f2ea6c6794bfbb0bf57475d9c6a3dc Mon Sep 17 00:00:00 2001 From: Elkorol Date: Mon, 19 Feb 2024 19:49:39 +0000 Subject: [PATCH 6/6] Fixed Folder Name Typo --- .../{addtionalFilesDeleter => additionalFilesDeleter}/README.md | 0 .../{addtionalFilesDeleter => additionalFilesDeleter}/deleter.py | 0 .../{addtionalFilesDeleter => additionalFilesDeleter}/deleter.yml | 0 .../requirements.txt | 0 4 files changed, 0 insertions(+), 0 deletions(-) rename plugins/{addtionalFilesDeleter => additionalFilesDeleter}/README.md (100%) rename plugins/{addtionalFilesDeleter => additionalFilesDeleter}/deleter.py (100%) rename plugins/{addtionalFilesDeleter => additionalFilesDeleter}/deleter.yml (100%) rename plugins/{addtionalFilesDeleter => additionalFilesDeleter}/requirements.txt (100%) diff --git a/plugins/addtionalFilesDeleter/README.md b/plugins/additionalFilesDeleter/README.md similarity index 100% rename from plugins/addtionalFilesDeleter/README.md rename to plugins/additionalFilesDeleter/README.md diff --git a/plugins/addtionalFilesDeleter/deleter.py b/plugins/additionalFilesDeleter/deleter.py similarity index 100% rename from plugins/addtionalFilesDeleter/deleter.py rename to plugins/additionalFilesDeleter/deleter.py diff --git a/plugins/addtionalFilesDeleter/deleter.yml b/plugins/additionalFilesDeleter/deleter.yml similarity index 100% rename from plugins/addtionalFilesDeleter/deleter.yml rename to plugins/additionalFilesDeleter/deleter.yml diff --git a/plugins/addtionalFilesDeleter/requirements.txt b/plugins/additionalFilesDeleter/requirements.txt similarity index 100% rename from plugins/addtionalFilesDeleter/requirements.txt rename to plugins/additionalFilesDeleter/requirements.txt