HashTheStash 0.4.0 can hash galleries

This commit is contained in:
Minasuki Hikimuna
2024-10-30 05:30:42 +02:00
parent 44db6b934f
commit f2d2dfa03f
4 changed files with 138 additions and 18 deletions
+11 -1
View File
@@ -13,6 +13,16 @@
"env": {
"ENABLE_DEV_MODE": "true"
}
}
},
{
"name": "HashTheStash (process_performers_json_input)",
"type": "debugpy",
"request": "launch",
"program": "plugins/HashTheStash/HashTheStash.py",
"console": "integratedTerminal",
"env": {
"ENABLE_DEV_MODE": "true"
}
},
]
}
+1
View File
@@ -0,0 +1 @@
FAKE_INPUT={"server_connection": {"Scheme": "http", "Host": "0.0.0.0", "Port": 6969, "SessionCookie": {"Name": "session", "Value": "MTczMDE5NDYwMHxEWDhFQVFMX2dBQUJFQUVRQUFCc180QUFBZ1p6ZEhKcGJtY01DQUFHZFhObGNrbEVCbk4wY21sdVp3d0hBQVZ6ZEdGemFBWnpkSEpwYm1jTUZRQVRkbWx6YVhSbFpGQnNkV2RwYm5OSWIyOXJjeHRiWFhObGMzTnBiMjR1Vm1semFYUmxaRkJzZFdkcGJraHZiMnZfZ3dJQkF2LUVBQUhfZ2dBQU9mLUJBd0VCRVZacGMybDBaV1JRYkhWbmFXNUliMjlyQWYtQ0FBRUNBUWhRYkhWbmFXNUpSQUVNQUFFSVNHOXZhMVI1Y0dVQkRBQUFBQVhfaEFJQUFBPT188sCZj1eCf6a3DNGjj1ICXAAzBYznEUiHQP2SJQ2URFk=", "Quoted": false, "Path": "", "Domain": "", "Expires": "0001-01-01T00:00:00Z", "RawExpires": "", "MaxAge": 0, "Secure": false, "HttpOnly": false, "SameSite": 0, "Partitioned": false, "Raw": "", "Unparsed": null}, "Dir": "H:\\Stash", "PluginDir": "H:\\Stash\\plugins\\HashTheStash"}, "args": {"mode": "calculate_hashes"}}
+115 -15
View File
@@ -49,24 +49,21 @@ def get_sha1_of_file(file_path):
return hasher.hexdigest()
# Example usage
if __name__ == "__main__":
raw_input = sys.stdin.read()
json_input = json.loads(raw_input)
def get_json_input():
if os.getenv("ENABLE_DEV_MODE"):
import dotenv
dotenv.load_dotenv()
stash = StashInterface(json_input["server_connection"])
configuration = stash.get_configuration()
plugin_configuration = configuration["plugins"]["HashTheStash"]
fake_input = os.getenv("FAKE_INPUT")
if not fake_input:
raise ValueError("FAKE_INPUT environment variable is not set.")
return json.loads(fake_input)
else:
raw_input = sys.stdin.read()
return json.loads(raw_input)
# Get hash settings
use_xxhash = plugin_configuration.get("xxhash", False)
use_sha256 = plugin_configuration.get("sha256", False)
use_sha1 = plugin_configuration.get("sha1", False)
if not use_xxhash and not use_sha256 and not use_sha1:
logger.error("No hash type selected. Please select at least one hash type.")
sys.exit(1)
def hash_scenes(stash, use_xxhash, use_sha256, use_sha1):
fragment = """
id
files {
@@ -137,3 +134,106 @@ if __name__ == "__main__":
page += 1
logger.info(f"Processed a total of {total_scenes} scenes.")
def hash_galleries(stash, use_xxhash, use_sha256, use_sha1):
fragment = """
id
files {
id
path
fingerprints {
type
value
}
}
"""
per_page = 25
page = 1
total_galleries = 0
while True:
galleries_result = stash.find_galleries(
{}, {"per_page": per_page, "page": page}, "", fragment, get_count=True
)
galleries_count = galleries_result[0]
galleries = galleries_result[1]
if not galleries:
break
total_galleries += len(galleries)
for gallery in galleries:
for file in gallery["files"]:
file_path = file["path"]
if not os.path.exists(file_path):
logger.warning(f"File not found: {file_path}")
continue
fingerprints_to_set = []
if use_xxhash and ("fingerprints" not in file or not any(
fp["type"] == "xxhash" for fp in file["fingerprints"]
)):
xxhash_value = get_xxhash_of_file(file_path)
fingerprints_to_set.append(
{"type": "xxhash", "value": xxhash_value}
)
if use_sha256 and ("fingerprints" not in file or not any(
fp["type"] == "sha256" for fp in file["fingerprints"]
)):
sha256_value = get_sha256_of_file(file_path)
fingerprints_to_set.append(
{"type": "sha256", "value": sha256_value}
)
if use_sha1 and ("fingerprints" not in file or not any(
fp["type"] == "sha1" for fp in file["fingerprints"]
)):
sha1_value = get_sha1_of_file(file_path)
fingerprints_to_set.append(
{"type": "sha1", "value": sha1_value}
)
if fingerprints_to_set:
logger.info(
f"File: {file_path}, new fingerprints: {fingerprints_to_set}"
)
stash.file_set_fingerprints(file["id"], fingerprints_to_set)
page += 1
logger.info(f"Processed a total of {total_galleries} galleries.")
# Example usage
if __name__ == "__main__":
json_input = get_json_input()
logger.debug(f"Input: {json_input}")
stash = StashInterface(json_input["server_connection"])
configuration = stash.get_configuration()
plugin_configuration = configuration["plugins"]["HashTheStash"]
# Get hash settings
use_xxhash = plugin_configuration.get("xxhash", False)
use_sha256 = plugin_configuration.get("sha256", False)
use_sha1 = plugin_configuration.get("sha1", False)
if not use_xxhash and not use_sha256 and not use_sha1:
logger.error("No hash type selected. Please select at least one hash type.")
sys.exit(1)
use_hash_galleries = plugin_configuration.get("hash_galleries", False)
use_hash_scenes = plugin_configuration.get("hash_scenes", False)
if not use_hash_scenes and not use_hash_galleries:
logger.error("Neither scenes nor galleries selected for hashing. Please select at least one.")
sys.exit(1)
if use_hash_scenes:
hash_scenes(stash, use_xxhash, use_sha256, use_sha1)
if use_hash_galleries:
hash_galleries(stash, use_xxhash, use_sha256, use_sha1)
+11 -2
View File
@@ -1,6 +1,6 @@
name: HashTheStash
description: Calculates additional fingerprints for scenes.
version: 0.3.0
version: 0.4.0
url: https://github.com/MinasukiHikimuna/MidnightRider-Stash/
exec:
- python
@@ -8,7 +8,7 @@ exec:
interface: raw
tasks:
- name: Hash The Stash!
description: Calculates additional fingerprints for scenes.
description: Calculates additional fingerprints for scenes and galleries.
defaultArgs:
mode: calculate_hashes
settings:
@@ -24,3 +24,12 @@ settings:
displayName: SHA-1 hashing
description: Enable SHA-1 hashing.
type: BOOLEAN
hash_galleries:
displayName: Hash galleries
description: Enable hashing of galleries.
type: BOOLEAN
hash_scenes:
displayName: Hash scenes
description: Enable hashing of scenes.
type: BOOLEAN