Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Updates TPDBMarkers to allow tag and title changes. #429

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions .idea/CommunityScripts.iml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 9 additions & 0 deletions plugins/TPDBMarkers/TPDBMarkers.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,15 @@ settings:
displayName: Create Movie from scene
description: If there is a Movie linked to the scene in the timestamp.trade database automatically create a movie in stash with that info
type: BOOLEAN
runOnScenesWithMarkers:
displayName: Run on scenes that already have markers.
type: BOOLEAN
addTPDBMarkerTag:
displayName: Add the [TPDBMarker] tag to created markers.
type: BOOLEAN
addTPDBMarkerTitle:
displayName: Add "[TPDBMarker]" to the start of generated marker titles.
type: BOOLEAN
tasks:
- name: "Sync"
description: Get markers for all scenes with a stashid from theporndb.net and no markers
Expand Down
82 changes: 54 additions & 28 deletions plugins/TPDBMarkers/tpdbMarkers.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import math

import stashapi.log as log
from stashapi.stashapp import StashInterface
import stashapi.marker_parse as mp
Expand All @@ -11,8 +13,16 @@
request_s = requests.Session()

TPDB_ENDPOINT = "https://theporndb.net/graphql"
tags_cache={}

def getTag(name):
if name not in tags_cache:
tag = stash.find_tag(name, create=True)
tags_cache[name] = tag.get("id")
return tags_cache[name]

def processScene(scene):
getTag("[TPDBMarker]")
for sid in scene["stash_ids"]:
if sid["endpoint"] == TPDB_ENDPOINT:
log.debug("Scene has a TPDB stash id, looking up %s " % (sid["stash_id"],))
Expand All @@ -26,10 +36,20 @@ def processScene(scene):
markers = []
for m in data["markers"]:
log.debug(m)
marker_title = (
f"[TPDBMarker] {m["title"]}"
if settings["addTPDBMarkerTitle"]
else m["title"]
)
marker_tags = (
["[TPDBMarker]"]
if settings["addTPDBMarkerTag"]
else []
)
marker = {
"title": m["title"],
"title": marker_title,
"primary_tag": m["title"],
"tags": [],
"tags": marker_tags,
"seconds": m["start_time"],
}
markers.append(marker)
Expand All @@ -56,27 +76,29 @@ def processScene(scene):
def processAll():
log.info("Getting scene count")
skip_sync_tag_id = stash.find_tag("[TPDB: Skip Marker]", create=True).get("id")
count = stash.find_scenes(
f={
"stash_id_endpoint": {
"endpoint": TPDB_ENDPOINT,
"modifier": "NOT_NULL",
"stash_id": "",
},
"has_markers": "false",
"tags": {
"depth": 0,
"excludes": [skip_sync_tag_id],
"modifier": "INCLUDES_ALL",
"value": [],
},
f = {
"stash_id_endpoint": {
"endpoint": TPDB_ENDPOINT,
"modifier": "NOT_NULL",
"stash_id": "",
},
"tags": {
"depth": 0,
"excludes": [skip_sync_tag_id],
"modifier": "INCLUDES_ALL",
"value": [],
},
}
if not settings["runOnScenesWithMarkers"]:
f["has_markers"]="false"
count = stash.find_scenes(
f,
filter={"per_page": 1},
get_count=True,
)[0]
log.info(str(count) + " scenes to submit.")
i = 0
for r in range(1, int(count / per_page) + 1):
for r in range(1, math.ceil(count / per_page) + 1):
log.info(
"fetching data: %s - %s %0.1f%%"
% (
Expand All @@ -85,15 +107,17 @@ def processAll():
(i / count) * 100,
)
)
scenes = stash.find_scenes(
f={
"stash_id_endpoint": {
"endpoint": TPDB_ENDPOINT,
"modifier": "NOT_NULL",
"stash_id": "",
},
"has_markers": "false",
f = {
"stash_id_endpoint": {
"endpoint": TPDB_ENDPOINT,
"modifier": "NOT_NULL",
"stash_id": "",
},
}
if not settings["runOnScenesWithMarkers"]:
f["has_markers"]="false"
scenes = stash.find_scenes(
f,
filter={"page": r, "per_page": per_page},
)
for s in scenes:
Expand Down Expand Up @@ -147,17 +171,19 @@ def processMovie(m):


json_input = json.loads(sys.stdin.read())

FRAGMENT_SERVER = json_input["server_connection"]
stash = StashInterface(FRAGMENT_SERVER)

config = stash.get_configuration()["plugins"]
settings = {
"disableSceneMarkerHook": False,
"createMovieFromScene":True,
"addTPDBMarkerTag":False,
"addTPDBMarkerTitle":False,
"runOnScenesWithMarkers":False
}
if "tPdBmarkers" in config:
settings.update(config["tPdBmarkers"])
if "TPDBMarkers" in config:
settings.update(config["TPDBMarkers"])
log.debug("settings: %s " % (settings,))

# Set up the auth token for tpdb
Expand Down
Loading
Loading