Skip to content

Commit 80375bd

Browse files
authored
Add files via upload
1 parent 6e6374f commit 80375bd

3 files changed

Lines changed: 76 additions & 0 deletions

File tree

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
name: Clear All Tag Covers
2+
description: Clear the image cover for all tags
3+
version: 0.1
4+
exec:
5+
- python
6+
- "{pluginDir}/clear_tag_covers.py"
7+
8+
interface: raw
9+
10+
tasks:
11+
- name: "Clear All Tag Covers Task"
12+
description: Removes the cover images for all tags in the database.
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
import sys
2+
import json
3+
import requests
4+
import stashapi.log as log
5+
6+
def main():
7+
try:
8+
# Standard way for Stash plugins to receive server info
9+
raw_input = sys.stdin.read()
10+
if not raw_input:
11+
log.error("No input received from Stash.")
12+
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')
22+
except Exception as e:
23+
log.error(f"Initialization failed: {e}")
24+
return
25+
26+
# GraphQL query to find all tags
27+
query = "{ findTags(filter: {per_page: -1}) { tags { id image_path } } }"
28+
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", [])
31+
except Exception as e:
32+
log.error(f"Failed to fetch tags: {e}")
33+
return
34+
35+
# Clear covers only for tags that have one
36+
tags_to_clear = [t for t in tags if t.get("image_path")]
37+
total = len(tags_to_clear)
38+
39+
if total == 0:
40+
log.info("No tag covers found to clear.")
41+
return
42+
43+
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)
46+
log.progress(idx / total)
47+
48+
log.info(f"Successfully cleared {total} tag cover images.")
49+
50+
if __name__ == "__main__":
51+
main()
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
id: Clear All Tag Covers
2+
name: Clear All Tag Covers
3+
metadata:
4+
description: Clear the image cover for all tags.
5+
version: 0.1
6+
date: "2026-02-26 21:14:00"
7+
requires: []
8+
source_repository: https://lurking987.github.io/stash-plugins/main/index.yml
9+
files:
10+
- manifest
11+
- README.md
12+
- clear_tag_covers.py
13+
- Clear All Tag Covers.yml

0 commit comments

Comments
 (0)