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