Skip to content

Commit d7855b2

Browse files
committed
[markerTagToScene] Add all tags of Scene Marker to the Scene
1 parent 9866c98 commit d7855b2

File tree

2 files changed

+26
-19
lines changed

2 files changed

+26
-19
lines changed

plugins/markerTagToScene/markerTagToScene.py

Lines changed: 23 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44
import requests
55
import log
66

7+
ALL_TAGS = False
8+
79
START_TIME = time.time()
810
FRAGMENT = json.loads(sys.stdin.read())
911

@@ -104,29 +106,34 @@ def graphql_setSceneTags(sceneID, tagIDs: list):
104106
def main():
105107

106108
CONTEXT = FRAGMENT['args']['hookContext']['input']
107-
108-
primaryTagID = CONTEXT['primary_tag_id']
109109
sceneID = CONTEXT['scene_id']
110-
111-
if not primaryTagID or not sceneID:
110+
if not sceneID:
112111
return
112+
113+
prevSceneTags = graphql_getSceneTags(sceneID)
114+
prevSceneTagIDs = []
115+
for prevSceneTag in prevSceneTags:
116+
prevSceneTagIDs.append(prevSceneTag['id'])
113117

114-
sceneTags = graphql_getSceneTags(sceneID)
115-
tagIDs = []
118+
nextTagIDs = []
116119

117-
for sceneTags in sceneTags:
118-
tagID = sceneTags['id'];
119-
if tagID == primaryTagID:
120-
log.LogDebug("Primary tag already exists on scene")
121-
return
120+
# Primary tag
121+
primaryTagID = CONTEXT['primary_tag_id']
122+
if primaryTagID is not None:
123+
nextTagIDs = set(prevSceneTagIDs + [primaryTagID])
122124

123-
tagIDs.append(tagID);
125+
# All tags
126+
if ALL_TAGS:
127+
tagIDs = CONTEXT['tag_ids']
128+
if tagIDs is not None:
129+
nextTagIDs = set(set(nextTagIDs) | set(prevSceneTagIDs) | set(tagIDs))
124130

125-
# set the tag on the scene if not present
126-
tagIDs.append(primaryTagID);
131+
if len(prevSceneTagIDs) >= len(nextTagIDs):
132+
log.LogDebug("No new tag added")
133+
return
127134

128-
graphql_setSceneTags(sceneID, tagIDs);
129-
log.LogDebug("Added primary tag " + primaryTagID + " to scene " + sceneID)
135+
graphql_setSceneTags(sceneID, list(nextTagIDs))
136+
log.LogDebug("Added new tags to scene " + sceneID)
130137

131138

132139

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
name: Scene Marker Tags to Scene
2-
description: Adds primary tag of Scene Marker to the Scene on marker create/update.
2+
description: Adds primary tag and opt-in all tags of Scene Marker to the Scene on marker create/update.
33
url: https://github.com/stashapp/CommunityScripts
4-
version: 2.0.0
4+
version: 2.1.0
55
exec:
66
- python
77
- "{pluginDir}/markerTagToScene.py"
88
interface: raw
99
hooks:
1010
- name: Update scene with scene marker tag
11-
description: Adds primary tag of Scene Marker to the Scene on marker create/update.
11+
description: Adds primary tag and opt-in all tags of Scene Marker to the Scene on marker create/update.
1212
triggeredBy:
1313
- SceneMarker.Create.Post
1414
- SceneMarker.Update.Post

0 commit comments

Comments
 (0)