Skip to content

Commit 9026d19

Browse files
authored
Enhance TPDBMarkers (#602)
1 parent 532a588 commit 9026d19

File tree

2 files changed

+72
-27
lines changed

2 files changed

+72
-27
lines changed

plugins/TPDBMarkers/TPDBMarkers.yml

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,21 @@ settings:
2121
displayName: Create Movie from scene
2222
description: If there is a Movie linked to the scene in the timestamp.trade database automatically create a movie in stash with that info
2323
type: BOOLEAN
24+
runOnScenesWithMarkers:
25+
displayName: Run on scenes that already have markers.
26+
type: BOOLEAN
27+
addTPDBMarkerTag:
28+
displayName: Add the [TPDBMarker] tag to created markers.
29+
type: BOOLEAN
30+
addTPDBMarkerTitle:
31+
displayName: Add "[TPDBMarker]" to the start of generated marker titles.
32+
type: BOOLEAN
33+
overwriteMarkers:
34+
displayName: Overwrite Markers
35+
type: BOOLEAN
36+
mergeMarkers:
37+
displayName: Merge Markers
38+
type: BOOLEAN
2439
tasks:
2540
- name: "Sync"
2641
description: Get markers for all scenes with a stashid from theporndb.net and no markers

plugins/TPDBMarkers/tpdbMarkers.py

Lines changed: 57 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,18 @@
1111
request_s = requests.Session()
1212

1313
TPDB_ENDPOINT = "https://theporndb.net/graphql"
14+
tags_cache = {}
15+
16+
17+
def getTag(name):
18+
if name not in tags_cache:
19+
tag = stash.find_tag(name, create=True)
20+
tags_cache[name] = tag.get("id")
21+
return tags_cache[name]
22+
1423

1524
def processScene(scene):
25+
getTag("[TPDBMarker]")
1626
for sid in scene["stash_ids"]:
1727
if sid["endpoint"] == TPDB_ENDPOINT:
1828
log.debug("Scene has a TPDB stash id, looking up %s " % (sid["stash_id"],))
@@ -26,24 +36,35 @@ def processScene(scene):
2636
markers = []
2737
for m in data["markers"]:
2838
log.debug(m)
39+
2940
marker = {
3041
"title": m["title"],
31-
"primary_tag": m["title"],
42+
"primary_tag": None,
3243
"tags": [],
3344
"seconds": m["start_time"],
3445
}
46+
if settings["addTPDBMarkerTag"]:
47+
marker["tags"].append(int(getTag("[TPDBMarker]")))
48+
49+
if settings["addTPDBMarkerTitle"]:
50+
marker["title"] = f"[TPDBMarker] {m["title"]}"
51+
3552
markers.append(marker)
3653

3754
if len(markers) > 0:
3855
log.info("Saving markers")
39-
mp.import_scene_markers(stash, markers, scene["id"], 15)
56+
if settings["overwriteMarkers"]:
57+
stash.destroy_scene_markers(scene["id"])
58+
mp.import_scene_markers(stash, markers, scene["id"], 15)
59+
elif (len(scene["scene_markers"]) == 0 or settings["mergeMarkers"]):
60+
mp.import_scene_markers(stash, markers, scene["id"], 15)
4061
# skip if there is already a movie linked
4162
if settings["createMovieFromScene"] and len(scene.get("movies", [])) == 0:
4263
movies=[]
4364
for m in data["movies"]:
44-
movie=processMovie(m)
45-
if movie:
46-
movies.append({"movie_id": movie["id"],"scene_index":None})
65+
movie=processMovie(m)
66+
if movie:
67+
movies.append({"movie_id": movie["id"],"scene_index":None})
4768
log.debug(movies)
4869
if len(movies) > 0:
4970
stash.update_scene({'id':scene["id"],"movies":movies})
@@ -56,21 +77,23 @@ def processScene(scene):
5677
def processAll():
5778
log.info("Getting scene count")
5879
skip_sync_tag_id = stash.find_tag("[TPDB: Skip Marker]", create=True).get("id")
59-
count = stash.find_scenes(
60-
f={
61-
"stash_id_endpoint": {
62-
"endpoint": TPDB_ENDPOINT,
63-
"modifier": "NOT_NULL",
64-
"stash_id": "",
65-
},
66-
"has_markers": "false",
67-
"tags": {
68-
"depth": 0,
69-
"excludes": [skip_sync_tag_id],
70-
"modifier": "INCLUDES_ALL",
71-
"value": [],
72-
},
80+
f = {
81+
"stash_id_endpoint": {
82+
"endpoint": TPDB_ENDPOINT,
83+
"modifier": "NOT_NULL",
84+
"stash_id": "",
85+
},
86+
"tags": {
87+
"depth": 0,
88+
"excludes": [skip_sync_tag_id],
89+
"modifier": "INCLUDES_ALL",
90+
"value": [],
7391
},
92+
}
93+
if not settings["runOnScenesWithMarkers"]:
94+
f["has_markers"] = "false"
95+
count = stash.find_scenes(
96+
f,
7497
filter={"per_page": 1},
7598
get_count=True,
7699
)[0]
@@ -85,15 +108,17 @@ def processAll():
85108
(i / count) * 100,
86109
)
87110
)
88-
scenes = stash.find_scenes(
89-
f={
90-
"stash_id_endpoint": {
91-
"endpoint": TPDB_ENDPOINT,
92-
"modifier": "NOT_NULL",
93-
"stash_id": "",
94-
},
95-
"has_markers": "false",
111+
f = {
112+
"stash_id_endpoint": {
113+
"endpoint": TPDB_ENDPOINT,
114+
"modifier": "NOT_NULL",
115+
"stash_id": "",
96116
},
117+
}
118+
if not settings["runOnScenesWithMarkers"]:
119+
f["has_markers"] = "false"
120+
scenes = stash.find_scenes(
121+
f,
97122
filter={"page": r, "per_page": per_page},
98123
)
99124
for s in scenes:
@@ -155,6 +180,11 @@ def processMovie(m):
155180
settings = {
156181
"disableSceneMarkerHook": False,
157182
"createMovieFromScene":True,
183+
"addTPDBMarkerTag": False,
184+
"addTPDBMarkerTitle": False,
185+
"runOnScenesWithMarkers": False,
186+
"overwriteMarkers": False,
187+
"mergeMarkers": False,
158188
}
159189
if "tPdBmarkers" in config:
160190
settings.update(config["tPdBmarkers"])

0 commit comments

Comments
 (0)