Skip to content

Commit ec63f0c

Browse files
TweeticoatsTweeticoats
andauthored
Adding a plugin to turn performer urls to a stash id. (#598)
Co-authored-by: Tweeticoats <[email protected]>
1 parent c49ef74 commit ec63f0c

File tree

2 files changed

+89
-0
lines changed

2 files changed

+89
-0
lines changed
Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
import stashapi.log as log
2+
from stashapi.stashapp import StashInterface
3+
import sys
4+
import json
5+
import time
6+
import re
7+
8+
9+
def processPerformer(performer):
10+
log.debug(performer["stash_ids"])
11+
stash_boxes = [x["endpoint"] for x in performer["stash_ids"]]
12+
needs_update = False
13+
performer_update = {"id": performer["id"], "stash_ids": performer["stash_ids"]}
14+
for url in performer["urls"]:
15+
log.debug(url)
16+
if "https://fansdb.cc/performers/" in url:
17+
if "https://fansdb.cc/graphql" not in stash_boxes:
18+
performer_update["stash_ids"].append(
19+
{"endpoint": "https://fansdb.cc/graphql", "stash_id": url[-36:]}
20+
)
21+
needs_update = True
22+
if "https://pmvstash.org/performers/" in url:
23+
if "https://pmvstash.org/graphql" not in stash_boxes:
24+
performer_update["stash_ids"].append(
25+
{"endpoint": "https://pmvstash.org/graphql", "stash_id": url[-36:]}
26+
)
27+
needs_update = True
28+
if "https://stashdb.org/performers/" in url:
29+
if "https://stashdb.org/graphql" not in stash_boxes:
30+
performer_update["stash_ids"].append(
31+
{"endpoint": "https://stashdb.org/graphql", "stash_id": url[-36:]}
32+
)
33+
needs_update = True
34+
35+
log.debug(performer_update)
36+
if needs_update:
37+
stash.update_performer(performer_update)
38+
39+
def processAll():
40+
for sbx_config in stash.get_configuration()["general"]["stashBoxes"]:
41+
log.debug("processing stashbox: %s" % (sbx_config['endpoint'],))
42+
query={
43+
"stash_id_endpoint": {
44+
"endpoint": sbx_config['endpoint'],
45+
"modifier": "IS_NULL",
46+
"stash_id": ""
47+
},
48+
"url": {
49+
"modifier": "INCLUDES",
50+
"value": sbx_config['endpoint'][:-7]
51+
}
52+
}
53+
performers=stash.find_performers(f=query)
54+
for performer in performers:
55+
processPerformer(performer)
56+
57+
json_input = json.loads(sys.stdin.read())
58+
FRAGMENT_SERVER = json_input["server_connection"]
59+
stash = StashInterface(FRAGMENT_SERVER)
60+
if "mode" in json_input["args"]:
61+
PLUGIN_ARGS = json_input["args"]["mode"]
62+
# log.debug(json_input)
63+
if "processAll" == PLUGIN_ARGS:
64+
processAll()
65+
66+
elif "hookContext" in json_input["args"]:
67+
id = json_input["args"]["hookContext"]["id"]
68+
if json_input["args"]["hookContext"]["type"] in ["Performer.Update.Post","Performer.Create.Post"]:
69+
p = stash.find_performer(id)
70+
processPerformer(p)
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
name: Performer Stashbox Url to ID
2+
description: If the performer has a url for another stashbox add it as an id to the performer
3+
version: 0.1
4+
url: https://github.com/stashapp/CommunityScripts/
5+
exec:
6+
- python
7+
- "{pluginDir}/performerStashboxUrlToID.py"
8+
interface: raw
9+
hooks:
10+
- name: Process Performer
11+
description: Adds extra tags to scenes
12+
triggeredBy:
13+
- Performer.Update.Post
14+
- Performer.Create.Post
15+
tasks:
16+
- name: Process all
17+
description: Process Performers
18+
defaultArgs:
19+
mode: processPerformers

0 commit comments

Comments
 (0)