Added scheduler support for Clean Generated Files

This commit is contained in:
David Maisonave
2024-08-13 02:19:16 -04:00
parent e64c46eac0
commit 9bfebd8435
5 changed files with 39 additions and 15 deletions

View File

@@ -1,4 +1,4 @@
# FileMonitor: Ver 0.7.9 (By David Maisonave) # FileMonitor: Ver 0.8.0 (By David Maisonave)
FileMonitor is a [Stash](https://github.com/stashapp/stash) plugin with the following two main features: FileMonitor is a [Stash](https://github.com/stashapp/stash) plugin with the following two main features:
- Updates Stash when any file changes occurs in the Stash library. - Updates Stash when any file changes occurs in the Stash library.
- **Task Scheduler**: Runs scheduled task based on the scheduler configuration in filemonitor_config.py. - **Task Scheduler**: Runs scheduled task based on the scheduler configuration in filemonitor_config.py.

View File

@@ -281,24 +281,41 @@ class StashPluginHelper:
# Extends class StashInterface with functions which are not yet in the class # Extends class StashInterface with functions which are not yet in the class
class ExtendStashInterface(StashInterface): class ExtendStashInterface(StashInterface):
def metadata_autotag(self, paths:list=[], dry_run=False): def metadata_autotag(self, paths:list=[], performers:list=[], studios:list=[], tags:list=[]):
if not paths:
return
query = """ query = """
mutation MetadataAutoTag($input:AutoTagMetadataInput!) { mutation MetadataAutoTag($input:AutoTagMetadataInput!) {
metadataAutoTag(input: $input) metadataAutoTag(input: $input)
} }
""" """
metadata_autotag_input = { metadata_autotag_input = {
"paths": paths "paths":paths,
"performers": performers,
"studios":studios,
"tags":tags,
} }
result = self.call_GQL(query, {"input": metadata_autotag_input}) result = self.call_GQL(query, {"input": metadata_autotag_input})
return result return result
def backup_database(self): def backup_database(self):
return self.call_GQL("mutation { backupDatabase(input: {download: false})}") return self.call_GQL("mutation { backupDatabase(input: {download: false})}")
def optimise_database(self): def optimise_database(self):
return self.call_GQL("mutation OptimiseDatabase { optimiseDatabase }") return self.call_GQL("mutation OptimiseDatabase { optimiseDatabase }")
def metadata_clean_generated(self, blobFiles=True, dryRun=False, imageThumbnails=True, markers=True, screenshots=True, sprites=True, transcodes=True):
query = """
mutation MetadataCleanGenerated($input: CleanGeneratedInput!) {
metadataCleanGenerated(input: $input)
}
"""
clean_metadata_input = {
"blobFiles": blobFiles,
"dryRun": dryRun,
"imageThumbnails": imageThumbnails,
"markers": markers,
"screenshots": screenshots,
"sprites": sprites,
"transcodes": transcodes,
}
result = self.call_GQL(query, {"input": clean_metadata_input})
return result

View File

@@ -153,6 +153,8 @@ class StashScheduler: # Stash Scheduler
return return
if task['task'] == "Clean": if task['task'] == "Clean":
plugin.STASH_INTERFACE.metadata_clean(paths=stashPaths, dry_run=plugin.DRY_RUN) plugin.STASH_INTERFACE.metadata_clean(paths=stashPaths, dry_run=plugin.DRY_RUN)
elif task['task'] == "Clean Generated Files":
plugin.STASH_INTERFACE.metadata_clean_generated()
elif task['task'] == "Generate": elif task['task'] == "Generate":
plugin.STASH_INTERFACE.metadata_generate() plugin.STASH_INTERFACE.metadata_generate()
elif task['task'] == "Backup": elif task['task'] == "Backup":
@@ -165,7 +167,7 @@ class StashScheduler: # Stash Scheduler
elif task['task'] == "Scan": elif task['task'] == "Scan":
plugin.STASH_INTERFACE.metadata_scan(paths=stashPaths) plugin.STASH_INTERFACE.metadata_scan(paths=stashPaths)
elif task['task'] == "Auto Tag": elif task['task'] == "Auto Tag":
plugin.STASH_INTERFACE.metadata_autotag(paths=stashPaths, dry_run=plugin.DRY_RUN) plugin.STASH_INTERFACE.metadata_autotag(paths=stashPaths)
elif task['task'] == "Optimise Database": elif task['task'] == "Optimise Database":
plugin.STASH_INTERFACE.optimise_database() plugin.STASH_INTERFACE.optimise_database()
elif task['task'] == "python": elif task['task'] == "python":
@@ -185,7 +187,11 @@ class StashScheduler: # Stash Scheduler
else: else:
# ToDo: Add code to check if plugin is installed. # ToDo: Add code to check if plugin is installed.
plugin.Trace(f"Running plugin task pluginID={task['pluginId']}, task name = {task['task']}") plugin.Trace(f"Running plugin task pluginID={task['pluginId']}, task name = {task['task']}")
plugin.STASH_INTERFACE.run_plugin_task(plugin_id=task['pluginId'], task_name=task['task']) try:
plugin.STASH_INTERFACE.run_plugin_task(plugin_id=task['pluginId'], task_name=task['task'])
except Exception as e:
plugin.LogOnce(f"Failed to call plugin {task['task']} with plugin-ID {task['pluginId']}. Error: {e}")
pass
def trimDbFiles(self, dbPath, maxFiles): def trimDbFiles(self, dbPath, maxFiles):
if not os.path.exists(dbPath): if not os.path.exists(dbPath):

View File

@@ -1,6 +1,6 @@
name: FileMonitor name: FileMonitor
description: Monitors the Stash library folders, and updates Stash if any changes occurs in the Stash library paths. description: Monitors the Stash library folders, and updates Stash if any changes occurs in the Stash library paths.
version: 0.7.9 version: 0.8.0
url: https://github.com/David-Maisonave/Axter-Stash/tree/main/plugins/FileMonitor url: https://github.com/David-Maisonave/Axter-Stash/tree/main/plugins/FileMonitor
settings: settings:
recursiveDisabled: recursiveDisabled:

View File

@@ -22,12 +22,13 @@ config = {
# The frequency field can be in minutes or hours. A zero frequency value disables the task. # The frequency field can be in minutes or hours. A zero frequency value disables the task.
# For weekly and monthly task, use the syntax as done in the **Generate** and **Backup** task below. # For weekly and monthly task, use the syntax as done in the **Generate** and **Backup** task below.
"task_reoccurring_scheduler": [ "task_reoccurring_scheduler": [
{"task" : "Clean", "hours" : 48}, # Maintenance -> [Clean] (every 2 days) {"task" : "Auto Tag", "hours" : 24}, # Auto Tag -> [Auto Tag] (Daily)
{"task" : "Auto Tag", "hours" : 24}, # Auto Tag -> [Auto Tag] (Daily) {"task" : "Clean", "hours" : 48}, # Maintenance -> [Clean] (every 2 days)
{"task" : "Optimise Database", "hours" : 24}, # Maintenance -> [Optimise Database] (Daily) {"task" : "Clean Generated Files", "hours" : 48}, # Maintenance -> [Clean Generated Files] (every 2 days)
{"task" : "Optimise Database", "hours" : 24}, # Maintenance -> [Optimise Database] (Daily)
# The following is the syntax used for plugins. A plugin task requires the plugin name for the [task] field, and the plugin-ID for the [pluginId] field. # The following is the syntax used for plugins. A plugin task requires the plugin name for the [task] field, and the plugin-ID for the [pluginId] field.
{"task" : "Create Tags", "pluginId" : "pathParser", "hours" : 0}, # This task requires plugin [Path Parser]. To enable this task change the zero to a positive number. {"task" : "Create Tags", "pluginId" : "pathParser", "hours" : 24}, # This task requires plugin [Path Parser]. To enable this task change the zero to a positive number.
# Note: For a weekly task use the weekday method which is more reliable. The hour section in time MUST be a two digit number, and use military time format. Example: 1PM = "13:00" # Note: For a weekly task use the weekday method which is more reliable. The hour section in time MUST be a two digit number, and use military time format. Example: 1PM = "13:00"
{"task" : "Generate", "weekday" : "sunday", "time" : "07:00"}, # Generated Content-> [Generate] (Every Sunday at 7AM) {"task" : "Generate", "weekday" : "sunday", "time" : "07:00"}, # Generated Content-> [Generate] (Every Sunday at 7AM)