This commit is contained in:
David Maisonave
2024-08-20 23:07:02 -04:00
parent 64076f078e
commit bec3e33950
8 changed files with 58 additions and 44 deletions

View File

@@ -43,6 +43,9 @@ stash.Trace(f"(stashPaths={stash.STASH_PATHS})")
listSeparator = stash.pluginConfig['listSeparator'] if stash.pluginConfig['listSeparator'] != "" else ','
addPrimaryDupPathToDetails = stash.pluginConfig['addPrimaryDupPathToDetails']
mergeDupFilename = stash.pluginSettings['mergeDupFilename']
moveToTrashCan = stash.pluginSettings['moveToTrashCan']
alternateTrashCanPath = stash.pluginConfig['dup_path']
def realpath(path):
"""
@@ -136,7 +139,7 @@ def setTagId(tagId, tagName, sceneDetails, PrimeDuplicateScene = ""):
elif sceneDetails['details'] == "":
PrimeDuplicateScene = f"Primary Duplicate = {PrimeDuplicateScene}"
else:
PrimeDuplicateScene = f"Primary Duplicate = {PrimeDuplicateScene}; {sceneDetails['details']}"
PrimeDuplicateScene = f"Primary Duplicate = {PrimeDuplicateScene};\n{sceneDetails['details']}"
for tag in sceneDetails['tags']:
if tag['name'] == tagName:
if PrimeDuplicateScene != "" and addPrimaryDupPathToDetails:
@@ -193,10 +196,11 @@ def mangeDupFiles(merge=False, deleteDup=False, tagDuplicates=False):
QtyAlmostDup = 0
QtyTagForDel = 0
QtySkipForDel = 0
stash.Log("#########################################################################")
stash.Log("#########################################################################")
stash.Log("Waiting for find_duplicate_scenes_diff to return results...")
DupFileSets = stash.find_duplicate_scenes_diff(duration_diff=duration_diff)
stash.Log("#########################################################################")
stash.Log("#########################################################################")
for DupFileSet in DupFileSets:
stash.Trace(f"DupFileSet={DupFileSet}")
QtyDupSet+=1
@@ -207,7 +211,8 @@ def mangeDupFiles(merge=False, deleteDup=False, tagDuplicates=False):
for DupFile in DupFileSet:
QtyDup+=1
Scene = stash.find_scene(DupFile['id'])
stash.Trace(f"Scene = {Scene.encode('ascii','ignore')}")
sceneData = f"Scene = {Scene}"
stash.Trace(sceneData.encode('ascii','ignore'))
DupFileDetailList = DupFileDetailList + [Scene]
if DupFileToKeep != "":
if DupFileToKeep['files'][0]['duration'] == Scene['files'][0]['duration']:
@@ -243,9 +248,17 @@ def mangeDupFiles(merge=False, deleteDup=False, tagDuplicates=False):
QtySkipForDel+=1
else:
if deleteDup:
stash.Log(f"Deleting duplicate '{DupFile['files'][0]['path'].encode('ascii','ignore')}'")
# ToDo: Add logic to check if moving file to deletion folder, or doing full delete.
DupFileName = DupFile['files'][0]['path']
DupFileNameOnly = pathlib.Path(DupFileName).stem
stash.Log(f"Deleting duplicate '{DupFileName.encode('ascii','ignore')}'")
# ToDo: Add logic to check if tag merging is needed before performing deletion.
if alternateTrashCanPath != "":
shutil.move(DupFileName, f"{alternateTrashCanPath }{os.sep}{DupFileNameOnly}")
elif moveToTrashCan:
from send2trash import send2trash # Requirement: pip install Send2Trash
send2trash(DupFileName)
else:
os.remove(DupFileName)
elif tagDuplicates:
if QtyTagForDel == 0:
stash.Log(f"Tagging duplicate {DupFile['files'][0]['path'].encode('ascii','ignore')} for deletion with tag {duplicateMarkForDeletion}.")

View File

@@ -6,37 +6,6 @@ config = {
"listSeparator" : ",",
# If enabled, adds the primary duplicate path to the scene detail.
"addPrimaryDupPathToDetails" : True,
# If enabled, ignore reparsepoints. For Windows NT drives only.
"ignoreReparsepoints" : True,
# If enabled, ignore symbolic links.
"ignoreSymbolicLinks" : True,
# If enabled, swap higher resolution duplicate files to preferred path.
"swapHighRes" : True,
# If enabled, swap longer length media files to preferred path. Longer will be determine by significantLongerTime value.
"swapLongLength" : True,
# If enabled, swap longer file name to preferred path.
"swapLongFileName" : False,
# If enabled, when finding exact duplicate files, keep file with the shorter name. The default is to keep file name with the longer name.
"keepShorterFileName" : False,
# If enabled, when finding duplicate files, keep media with the shorter time length. The default is to keep media with longer time length.
"keepShorterLength" : False,
# If enabled, when finding duplicate files, keep media with the lower resolution. The default is to keep media with higher resolution.
"keepLowerResolution" : False,
# If enabled, keep duplicate media with high resolution over media with significant longer time.
"keepHighResOverLen" : False, # Requires keepBothHighResAndLongerLen = False
# The threshold as to what percentage is consider a significant longer time. Default is 15% longer.
"significantLongerTime" : 15, # 15% longer time
# If enabled, keep both duplicate files if the LOWER resolution file is significantly longer.
"keepBothHighResAndLongerLen" : True,
# Define ignore list to avoid specific directories. No action is taken on any file in the ignore list.
"ignore_paths": [], #Example: "ignore_paths": ['C:\\SomeMediaPath\\subpath', "E:\\YetAnotherPath\\subpath', "E:\\YetAnotherPath\\secondSubPath']
# Keep empty to check all paths, or populate it with the only paths to check for duplicates
"onlyCheck_paths": [], #Example: "onlyCheck_paths": ['C:\\SomeMediaPath\\subpath', "E:\\YetAnotherPath\\subpath', "E:\\YetAnotherPath\\secondSubPath']
# Alternative path to move duplicate files. Path needs to be in the same drive as the duplicate file.
"dup_path": "", #Example: "C:\\TempDeleteFolder"

View File

@@ -0,0 +1,30 @@
# Below fields are in the development stage, and should not be used.
config_dev = {
# If enabled, ignore reparsepoints. For Windows NT drives only.
"ignoreReparsepoints" : True,
# If enabled, ignore symbolic links.
"ignoreSymbolicLinks" : True,
# If enabled, swap higher resolution duplicate files to preferred path.
"swapHighRes" : True,
# If enabled, swap longer length media files to preferred path. Longer will be determine by significantLongerTime value.
"swapLongLength" : True,
# If enabled, swap longer file name to preferred path.
"swapLongFileName" : False,
# If enabled, when finding exact duplicate files, keep file with the shorter name. The default is to keep file name with the longer name.
"keepShorterFileName" : False,
# If enabled, when finding duplicate files, keep media with the shorter time length. The default is to keep media with longer time length.
"keepShorterLength" : False,
# If enabled, when finding duplicate files, keep media with the lower resolution. The default is to keep media with higher resolution.
"keepLowerResolution" : False,
# If enabled, keep duplicate media with high resolution over media with significant longer time.
"keepHighResOverLen" : False, # Requires keepBothHighResAndLongerLen = False
# The threshold as to what percentage is consider a significant longer time. Default is 15% longer.
"significantLongerTime" : 15, # 15% longer time
# If enabled, keep both duplicate files if the LOWER resolution file is significantly longer.
"keepBothHighResAndLongerLen" : True,
# Keep empty to check all paths, or populate it with the only paths to check for duplicates
"onlyCheck_paths": [], #Example: "onlyCheck_paths": ['C:\\SomeMediaPath\\subpath', "E:\\YetAnotherPath\\subpath', "E:\\YetAnotherPath\\secondSubPath']
}

View File

@@ -26,6 +26,7 @@ This Plugin is under construction!!!
`pip install stashapp-tools`
`pip install --upgrade stashapp-tools`
`pip install pyYAML`
`pip install Send2Trash`
### Installation
- Follow **Requirements** instructions.

View File

@@ -1,3 +1,4 @@
stashapp-tools >= 0.2.50
pyYAML
watchdog
watchdog
Send2Trash

View File

@@ -1,4 +1,4 @@
# RenameFile: Ver 0.4.3 (By David Maisonave)
# RenameFile: Ver 0.4.4 (By David Maisonave)
RenameFile is a [Stash](https://github.com/stashapp/stash) plugin which performs the following tasks.
- **Rename Scene File Name** (On-The-Fly)
- **Append tag names** to file name

View File

@@ -66,7 +66,7 @@ settings = {
"studioAppend": False,
"tagAppend": False,
"z_keyFIeldsIncludeInFileName": False,
"zafileRenameViaMove": False,
"zafileRenameViaRaname": False,
"zfieldKeyList": DEFAULT_FIELD_KEY_LIST,
"zmaximumTagKeys": 12,
"zseparators": DEFAULT_SEPERATOR,
@@ -133,7 +133,7 @@ endpoint = f"{json_input['server_connection']['Scheme']}://{endpointHost}:{json_
if debugTracing: logger.info(f"Debug Tracing (endpoint={endpoint})................")
# Extract rename_files and move_files settings from renamefile_settings.py
rename_files = config["rename_files"]
move_files = settings["zafileRenameViaMove"]
move_files = False if settings["zafileRenameViaRaname"] else True
if debugTracing: logger.info("Debug Tracing................")
fieldKeyList = settings["zfieldKeyList"] # Default Field Key List with the desired order
if not fieldKeyList or fieldKeyList == "":

View File

@@ -1,6 +1,6 @@
name: RenameFile
description: Renames video (scene) file names when the user edits the [Title] field located in the scene [Edit] tab.
version: 0.4.3
version: 0.4.4
url: https://github.com/David-Maisonave/Axter-Stash/tree/main/plugins/RenameFile
settings:
performerAppend:
@@ -19,9 +19,9 @@ settings:
displayName: Include Existing Key Field
description: Enable to append performer, tags, studios, & galleries even if name already exists in the original file name.
type: BOOLEAN
zafileRenameViaMove:
displayName: Rename Using Move
description: Enable to have file moved when renaming file.
zafileRenameViaRaname:
displayName: Rename Instead of Move
description: Enable to rename file instead of Move file. (Not recommended for Windows OS)
type: BOOLEAN
zfieldKeyList:
displayName: Key Fields