|
| 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) |
0 commit comments