|
4 | 4 | import requests |
5 | 5 | import log |
6 | 6 |
|
| 7 | +ALL_TAGS = False |
| 8 | + |
7 | 9 | START_TIME = time.time() |
8 | 10 | FRAGMENT = json.loads(sys.stdin.read()) |
9 | 11 |
|
@@ -104,29 +106,34 @@ def graphql_setSceneTags(sceneID, tagIDs: list): |
104 | 106 | def main(): |
105 | 107 |
|
106 | 108 | CONTEXT = FRAGMENT['args']['hookContext']['input'] |
107 | | - |
108 | | - primaryTagID = CONTEXT['primary_tag_id'] |
109 | 109 | sceneID = CONTEXT['scene_id'] |
110 | | - |
111 | | - if not primaryTagID or not sceneID: |
| 110 | + if not sceneID: |
112 | 111 | return |
| 112 | + |
| 113 | + prevSceneTags = graphql_getSceneTags(sceneID) |
| 114 | + prevSceneTagIDs = [] |
| 115 | + for prevSceneTag in prevSceneTags: |
| 116 | + prevSceneTagIDs.append(prevSceneTag['id']) |
113 | 117 |
|
114 | | - sceneTags = graphql_getSceneTags(sceneID) |
115 | | - tagIDs = [] |
| 118 | + nextTagIDs = [] |
116 | 119 |
|
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]) |
122 | 124 |
|
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)) |
124 | 130 |
|
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 |
127 | 134 |
|
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) |
130 | 137 |
|
131 | 138 |
|
132 | 139 |
|
|
0 commit comments