Skip to content

Commit 58a7576

Browse files
authored
Update clear_tag_covers.py
1 parent b2475f4 commit 58a7576

1 file changed

Lines changed: 13 additions & 19 deletions

File tree

plugins/Clear All Tag Covers/clear_tag_covers.py

Lines changed: 13 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,48 +1,42 @@
11
import sys
22
import json
3-
import requests
43
import stashapi.log as log
4+
from stashapi.stashapp import StashInterface
55

66
def main():
77
try:
8-
# Standard way for Stash plugins to receive server info
98
raw_input = sys.stdin.read()
109
if not raw_input:
1110
log.error("No input received from Stash.")
1211
return
13-
14-
input_data = json.loads(raw_input)
15-
server = input_data.get("server_connection", {})
16-
17-
# Use dynamic base_url to handle local vs remote connections
18-
base_url = f"{server.get('Scheme', 'http')}://{server.get('Host', 'localhost')}:{server.get('Port', 9999)}"
19-
headers = {'Content-Type': 'application/json'}
20-
if server.get('ApiKey'):
21-
headers['ApiKey'] = server.get('ApiKey')
12+
13+
json_input = json.loads(raw_input)
14+
stash = StashInterface(json_input["server_connection"])
15+
2216
except Exception as e:
2317
log.error(f"Initialization failed: {e}")
2418
return
2519

26-
# GraphQL query to find all tags
27-
query = "{ findTags(filter: {per_page: -1}) { tags { id image_path } } }"
2820
try:
29-
res = requests.post(f"{base_url}/graphql", json={'query': query}, headers=headers, timeout=10).json()
30-
tags = res.get("data", {}).get("findTags", {}).get("tags", [])
21+
result = stash.call_GQL("{ findTags(filter: {per_page: -1}) { tags { id image_path } } }")
22+
tags = result.get("findTags", {}).get("tags", [])
3123
except Exception as e:
3224
log.error(f"Failed to fetch tags: {e}")
3325
return
3426

35-
# Clear covers only for tags that have one
3627
tags_to_clear = [t for t in tags if t.get("image_path")]
3728
total = len(tags_to_clear)
38-
29+
3930
if total == 0:
4031
log.info("No tag covers found to clear.")
4132
return
4233

34+
mutation = "mutation($id: ID!) { tagUpdate(input: { id: $id, image: \"\" }) { id } }"
4335
for idx, tag in enumerate(tags_to_clear, 1):
44-
mutation = "mutation($id: ID!) { tagUpdate(input: { id: $id, image: \"\" }) { id } }"
45-
requests.post(f"{base_url}/graphql", json={'query': mutation, 'variables': {"id": tag['id']}}, headers=headers)
36+
try:
37+
stash.call_GQL(mutation, {"id": tag["id"]})
38+
except Exception as e:
39+
log.error(f"Failed to clear tag {tag['id']}: {e}")
4640
log.progress(idx / total)
4741

4842
log.info(f"Successfully cleared {total} tag cover images.")

0 commit comments

Comments
 (0)