Skip to content

Commit

Permalink
[TPDBMarkers] Adding movie support if tpdb have this information (#308)
Browse files Browse the repository at this point in the history
Co-authored-by: Tweeticoats <[email protected]>
  • Loading branch information
Tweeticoats and Tweeticoats authored May 25, 2024
1 parent 8e2a89b commit a419887
Show file tree
Hide file tree
Showing 2 changed files with 72 additions and 7 deletions.
8 changes: 6 additions & 2 deletions plugins/TPDBMarkers/TPDBMarkers.yml
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
name: The Porn DB Markers
description: Sync Markers from The Porn DB aka theporndb.net
version: 0.2
version: 0.3
url: https://github.com/stashapp/CommunityScripts/
exec:
- python
- "{pluginDir}/tpdbMarkers.py"
interface: raw

hooks:
- name: Add Marker to Scene
description: Makes Markers checking against The Porn DB aka theporndb.net
Expand All @@ -16,7 +17,10 @@ settings:
disableSceneMarkerHook:
displayName: Disable the Scene Markers hook
type: BOOLEAN

createMovieFromScene:
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
tasks:
- name: "Sync"
description: Get markers for all scenes with a stashid from theporndb.net and no markers
Expand Down
71 changes: 66 additions & 5 deletions plugins/TPDBMarkers/tpdbMarkers.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ def processScene(scene):
if res.status_code == 200:
if "data" in res.json():
data = res.json()["data"]

markers = []
for m in data["markers"]:
log.debug(m)
Expand All @@ -35,7 +36,18 @@ def processScene(scene):
if len(markers) > 0:
log.info("Saving markers")
mp.import_scene_markers(stash, markers, scene["id"], 15)

# skip if there is already a movie linked
if settings["createMovieFromScene"] and len(scene["movies"]) ==0:
movies=[]
for m in data["movies"]:
movie=processMovie(m)
if movie:
movies.append({"movie_id": movie["id"],"scene_index":None})
log.debug(movies)
if len(movies) > 0:
stash.update_scene({'id':scene["id"],"movies":movies})
else:
log.error('bad response from tpdb: %s' % (res.status_code,))

# log.debug(res.content)

Expand Down Expand Up @@ -89,6 +101,49 @@ def processAll():
log.progress((i / count))
time.sleep(1)

def processMovie(m):
log.debug(m)
log.debug(m.keys())
# check if the movie exists with the url, then match to the scene
sm = stash.find_movies(
f={
"url": {
"modifier": "EQUALS",
"value": m["url"],
}
}
)
log.debug("sm: %s" % (sm,))
if len(sm) >0:
return sm[0]
# find the movie by name
sm=stash.find_movies(q=m['title'])
for mov in sm:
if mov['name']==m['title']:
return mov


# just create the movie with the details from tpdb
new_movie={
'name': m['title'],
'date': m['date'],
'synopsis': m['description'],
'front_image': m['image'],
'back_image': m['back_image'],
'url': m['url'],
}
if m['site']:
studio=stash.find_studio(m['site'],create=True)
if studio:
new_movie['studio_id']=studio['id']

mov=stash.create_movie(new_movie)
log.debug(mov)
return mov





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

Expand All @@ -98,6 +153,7 @@ def processAll():
config = stash.get_configuration()["plugins"]
settings = {
"disableSceneMarkerHook": False,
"createMovieFromScene":True,
}
if "tPdBmarkers" in config:
settings.update(config["tPdBmarkers"])
Expand All @@ -113,14 +169,19 @@ def processAll():

if "mode" in json_input["args"]:
PLUGIN_ARGS = json_input["args"]["mode"]
if "processScene" in PLUGIN_ARGS:
processAll()
if "processScene" == PLUGIN_ARGS:
if "scene_id" in json_input["args"]:
scene = stash.find_scene(json_input["args"]["scene_id"])
processScene(scene)
else:
processAll()
elif "hookContext" in json_input["args"]:
_id = json_input["args"]["hookContext"]["id"]
_type = json_input["args"]["hookContext"]["type"]
if _type == "Scene.Update.Post" and not settings["disableSceneMarkerHook"]:
scene = stash.find_scene(_id)
processScene(scene)
stash.run_plugin_task("TPDBMarkers", "Sync", args={"scene_id": _id})
# scene = stash.find_scene(_id)
# processScene(scene)

else:
log.warning("The Porn DB endpoint not configured")

0 comments on commit a419887

Please sign in to comment.