Skip to content

Commit c573177

Browse files
authored
Merge branch 'main' into fix-graphql
2 parents dedb378 + a313a93 commit c573177

File tree

2 files changed

+55
-59
lines changed

2 files changed

+55
-59
lines changed

plugins/TPDBMarkers/TPDBMarkers.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,8 @@ settings:
1818
displayName: Disable the Scene Markers hook
1919
type: BOOLEAN
2020
createMovieFromScene:
21-
displayName: Create Movie from scene
22-
description: If there is a Movie linked to the scene in the timestamp.trade database automatically create a movie in stash with that info
21+
displayName: Create Group from scene
22+
description: If there is a Group linked to the scene in the timestamp.trade database automatically create a group in stash with that info
2323
type: BOOLEAN
2424
runOnScenesWithMarkers:
2525
displayName: Run on scenes that already have markers.

plugins/TPDBMarkers/tpdbMarkers.py

Lines changed: 53 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,7 @@ def processScene(scene):
2525
getTag("[TPDBMarker]")
2626
for sid in scene["stash_ids"]:
2727
if sid["endpoint"] == TPDB_ENDPOINT:
28-
log.debug("Scene has a TPDB stash id, looking up %s " %
29-
(sid["stash_id"],))
28+
log.debug("Scene has a TPDB stash id, looking up %s " % (sid["stash_id"],))
3029
res = request_s.get(
3130
"https://api.theporndb.net/scenes/%s" % (sid["stash_id"],)
3231
)
@@ -56,23 +55,19 @@ def processScene(scene):
5655
log.info("Saving markers")
5756
if settings["overwriteMarkers"]:
5857
stash.destroy_scene_markers(scene["id"])
59-
mp.import_scene_markers(
60-
stash, markers, scene["id"], 15)
58+
mp.import_scene_markers(stash, markers, scene["id"], 15)
6159
elif (len(scene["scene_markers"]) == 0 or settings["mergeMarkers"]):
62-
mp.import_scene_markers(
63-
stash, markers, scene["id"], 15)
64-
# skip if there is already a movie linked
65-
if settings["createMovieFromScene"] and len(scene.get("movies", [])) == 0:
66-
movies = []
67-
for m in data["movies"]:
68-
movie = processMovie(m)
69-
if movie:
70-
movies.append(
71-
{"movie_id": movie["id"], "scene_index": None})
72-
log.debug(movies)
73-
if len(movies) > 0:
74-
stash.update_scene(
75-
{'id': scene["id"], "movies": movies})
60+
mp.import_scene_markers(stash, markers, scene["id"], 15)
61+
# skip if there is already a group linked
62+
if settings["createMovieFromScene"] and len(scene.get("groups", [])) == 0:
63+
groups=[]
64+
for g in data["groups"]:
65+
group=processGroup(g)
66+
if group:
67+
groups.append({"group_id": group["id"],"scene_index":None})
68+
log.debug(groups)
69+
if len(groups) > 0:
70+
stash.update_scene({'id':scene["id"],"groups":groups})
7671
else:
7772
log.error('bad response from tpdb: %s' % (res.status_code,))
7873

@@ -81,8 +76,7 @@ def processScene(scene):
8176

8277
def processAll():
8378
log.info("Getting scene count")
84-
skip_sync_tag_id = stash.find_tag(
85-
"[TPDB: Skip Marker]", create=True).get("id")
79+
skip_sync_tag_id = stash.find_tag("[TPDB: Skip Marker]", create=True).get("id")
8680
f = {
8781
"stash_id_endpoint": {
8882
"endpoint": TPDB_ENDPOINT,
@@ -133,45 +127,48 @@ def processAll():
133127
log.progress((i / count))
134128
time.sleep(1)
135129

136-
137-
def processMovie(m):
138-
log.debug(m)
139-
log.debug(m.keys())
140-
# check if the movie exists with the url, then match to the scene
141-
sm = stash.find_groups(
142-
f={
143-
"url": {
144-
"modifier": "EQUALS",
145-
"value": m["url"],
146-
}
130+
def processGroup(g):
131+
log.debug(g)
132+
log.debug(g.keys())
133+
# check if the group exists with the url, then match to the scene
134+
sg = stash.find_groups(
135+
f={
136+
"url": {
137+
"modifier": "EQUALS",
138+
"value": g["url"],
147139
}
140+
}
148141
)
149-
log.debug("sm: %s" % (sm,))
150-
if len(sm) > 0:
151-
return sm[0]
152-
# find the movie by name
153-
sm = stash.find_groups(q=m['title'])
154-
for mov in sm:
155-
if mov['name'] == m['title']:
156-
return mov
157-
158-
# just create the movie with the details from tpdb
159-
new_movie = {
160-
'name': m['title'],
161-
'date': m['date'],
162-
'synopsis': m['description'],
163-
'front_image': m['image'],
164-
'back_image': m['back_image'],
165-
'urls': [m['url']],
142+
log.debug("sg: %s" % (sg,))
143+
if len(sg) >0:
144+
return sg[0]
145+
# find the group by name
146+
sg=stash.find_groups(q=g['title'])
147+
for grp in sg:
148+
if grp['name']==g['title']:
149+
return grp
150+
151+
152+
# just create the group with the details from tpdb
153+
new_group={
154+
'name': g['title'],
155+
'date': g['date'],
156+
'synopsis': g['description'],
157+
'front_image': g['image'],
158+
'back_image': g['back_image'],
159+
'urls': [g['url']],
166160
}
167-
if m['site']:
168-
studio = stash.find_studio(m['site'], create=True)
161+
if g['site']:
162+
studio=stash.find_studio(g['site'],create=True)
169163
if studio:
170-
new_movie['studio_id'] = studio['id']
164+
new_group['studio_id']=studio['id']
165+
166+
grp=stash.create_group(new_group)
167+
log.debug(grp)
168+
return grp
169+
170+
171171

172-
mov = stash.create_movie(new_movie)
173-
log.debug(mov)
174-
return mov
175172

176173

177174
json_input = json.loads(sys.stdin.read())
@@ -182,7 +179,7 @@ def processMovie(m):
182179
config = stash.get_configuration()["plugins"]
183180
settings = {
184181
"disableSceneMarkerHook": False,
185-
"createMovieFromScene": True,
182+
"createMovieFromScene":True,
186183
"addTPDBMarkerTag": False,
187184
"addTPDBMarkerTitle": False,
188185
"runOnScenesWithMarkers": False,
@@ -215,8 +212,7 @@ def processMovie(m):
215212
_id = json_input["args"]["hookContext"]["id"]
216213
_type = json_input["args"]["hookContext"]["type"]
217214
if _type == "Scene.Update.Post" and not settings["disableSceneMarkerHook"]:
218-
stash.run_plugin_task("TPDBMarkers", "Sync",
219-
args={"scene_id": _id})
215+
stash.run_plugin_task("TPDBMarkers", "Sync", args={"scene_id": _id})
220216
# scene = stash.find_scene(_id)
221217
# processScene(scene)
222218

0 commit comments

Comments
 (0)