Skip to content

Commit afb26fe

Browse files
committed
new plugin to set image tags from performers based on tagScenesWithPerfTags
1 parent 5e98864 commit afb26fe

File tree

4 files changed

+133
-0
lines changed

4 files changed

+133
-0
lines changed
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
id: tagImagesWithPerfTags
2+
name: Tag Images From Performer Tags
3+
metadata:
4+
description: tags images with performer tags.
5+
version: 0.1-private
6+
date: "2025-05-18 19:37:19"
7+
requires: []
8+
files:
9+
- tagImagesWithPerfTags.yml
10+
- requirements.txt
11+
- README.md
12+
- tagImagesWithPerfTags.py
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
stashapp-tools
Lines changed: 90 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,90 @@
1+
from stashapi.stashapp import StashInterface
2+
import sys
3+
import json
4+
5+
def processAll():
6+
query = {
7+
"tags": {
8+
"modifier": "NOT_NULL",
9+
},
10+
"image_count": {
11+
"modifier": "NOT_EQUALS",
12+
"value": 0,
13+
},
14+
}
15+
performersTotal = stash.find_performers(f=query, get_count=True)[0]
16+
i = 0
17+
tags = []
18+
images = []
19+
while i < performersTotal:
20+
perf = stash.find_performers(f=query, filter={"page": i, "per_page": 1})
21+
for tag in perf[0]["tags"]:
22+
tags.append(tag["id"])
23+
for image in perf[0]["images"]:
24+
images.append(image["id"])
25+
stash.update_images(
26+
{
27+
"ids": images,
28+
"tag_ids": {"mode": "ADD", "ids": tags},
29+
}
30+
)
31+
i = i + 1
32+
tags = []
33+
images = []
34+
35+
36+
def processImage(image):
37+
tags = []
38+
performersIds = []
39+
should_tag = True
40+
if settings["excludeImageWithTag"] != "":
41+
for tag in image["tags"]:
42+
if tag["name"] == settings["excludeImageWithTag"]:
43+
should_tag = False
44+
break
45+
46+
if settings['excludeImageOrganized']:
47+
if image['organized']:
48+
should_tag = False
49+
50+
if should_tag:
51+
for perf in image["performers"]:
52+
performersIds.append(perf["id"])
53+
performers = []
54+
for perfId in performersIds:
55+
performers.append(stash.find_performer(perfId))
56+
for perf in performers:
57+
for tag in perf["tags"]:
58+
tags.append(tag["id"])
59+
stash.update_images({"ids": image["id"], "tag_ids": {"mode": "ADD", "ids": tags}})
60+
tags = []
61+
performersIds = []
62+
performers = []
63+
64+
65+
json_input = json.loads(sys.stdin.read())
66+
FRAGMENT_SERVER = json_input["server_connection"]
67+
stash = StashInterface(FRAGMENT_SERVER)
68+
config = stash.get_configuration()
69+
settings = {
70+
"excludeImageWithTag": "",
71+
"excludeImageOrganized": False
72+
}
73+
if "tagImagesWithPerfTags" in config["plugins"]:
74+
settings.update(config["plugins"]["tagImagesWithPerfTags"])
75+
76+
if "mode" in json_input["args"]:
77+
PLUGIN_ARGS = json_input["args"]["mode"]
78+
if "processAll" in PLUGIN_ARGS:
79+
processAll()
80+
elif "hookContext" in json_input["args"]:
81+
id = json_input["args"]["hookContext"]["id"]
82+
if (
83+
(
84+
json_input["args"]["hookContext"]["type"] == "Image.Update.Post"
85+
or "Image.Create.Post"
86+
) and "inputFields" in json_input["args"]["hookContext"]
87+
and len(json_input["args"]["hookContext"]["inputFields"]) > 2
88+
):
89+
image = stash.find_image(id)
90+
processImage(image)
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
name: Tag Images From Performer Tags
2+
description: tags images with performer tags.
3+
version: 0.1
4+
exec:
5+
- python
6+
- "{pluginDir}/tagImagesWithPerfTags.py"
7+
interface: raw
8+
9+
hooks:
10+
- name: update image
11+
description: Will tag image with selected performers tags
12+
triggeredBy:
13+
- Image.Update.Post
14+
- Image.Create.Post
15+
16+
settings:
17+
excludeImageOrganized:
18+
displayName: Exclude Images marked as organized
19+
description: Do not automatically tag images with performer tags if the image is marked as organized
20+
type: BOOLEAN
21+
excludeImageWithTag:
22+
displayName: Exclude Images with Tag from Hook
23+
description: Do not automatically tag images with performer tags if the image has this tag
24+
type: STRING
25+
26+
tasks:
27+
- name: "Tag All Images"
28+
description: Loops through all performers, finds all of their images, then applies the performers tags to each of the images they appear in. Can take a long time on large db's.
29+
defaultArgs:
30+
mode: processAll

0 commit comments

Comments
 (0)