Skip to content

Commit bea9ce1

Browse files
TweeticoatsTweeticoats
andauthored
Adding a plugin to get markers from funscripts. (#439)
Co-authored-by: Tweeticoats <[email protected]>
1 parent 1322291 commit bea9ce1

File tree

2 files changed

+108
-0
lines changed

2 files changed

+108
-0
lines changed
Lines changed: 95 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,95 @@
1+
import stashapi.log as log
2+
from stashapi.stashapp import StashInterface
3+
import stashapi.marker_parse as mp
4+
import sys
5+
from pathlib import Path
6+
import json
7+
import re
8+
import time
9+
10+
11+
def processScene(scene):
12+
log.debug(scene["scene_markers"])
13+
if len(scene["scene_markers"]) == 0:
14+
for f in scene["files"]:
15+
scriptfile = Path(f["path"]).parent / (Path(f["path"]).stem + ".funscript")
16+
log.debug(scriptfile)
17+
if scriptfile.exists():
18+
with open(scriptfile) as f2:
19+
script_json = json.load(f2)
20+
if "metadata" in script_json:
21+
markers = []
22+
if "chapters" in script_json["metadata"]:
23+
for c in script_json["metadata"]["chapters"]:
24+
name = c["name"]
25+
if len(name) == 0:
26+
name = "#"
27+
marker = {
28+
"seconds": sum(
29+
x * float(t)
30+
for x, t in zip(
31+
[3600, 60, 1],
32+
re.split(r"[:]", c["startTime"]),
33+
)
34+
),
35+
"primary_tag": name,
36+
"tags": [],
37+
"title": name,
38+
}
39+
log.debug(marker)
40+
markers.append(marker)
41+
if len(markers) > 0:
42+
mp.import_scene_markers(stash, markers, scene["id"], 15)
43+
44+
45+
def processAll():
46+
query = {
47+
"has_markers": "false",
48+
"interactive": True,
49+
}
50+
per_page = 100
51+
log.info("Getting scene count")
52+
count = stash.find_scenes(
53+
f=query,
54+
filter={"per_page": 1},
55+
get_count=True,
56+
)[0]
57+
log.info(str(count) + " scenes to process.")
58+
# i = 0
59+
# 98
60+
for r in range(1, int(count / per_page) + 2):
61+
i = (r - 1) * per_page
62+
log.info(
63+
"fetching data: %s - %s %0.1f%%"
64+
% (
65+
(r - 1) * per_page,
66+
r * per_page,
67+
(i / count) * 100,
68+
)
69+
)
70+
scenes = stash.find_scenes(
71+
f=query,
72+
filter={"page": r, "per_page": per_page},
73+
)
74+
for s in scenes:
75+
processScene(s)
76+
i = i + 1
77+
log.progress((i / count))
78+
time.sleep(2)
79+
80+
81+
json_input = json.loads(sys.stdin.read())
82+
83+
FRAGMENT_SERVER = json_input["server_connection"]
84+
stash = StashInterface(FRAGMENT_SERVER)
85+
86+
if "mode" in json_input["args"]:
87+
PLUGIN_ARGS = json_input["args"]["mode"]
88+
if "processAll" == PLUGIN_ARGS:
89+
processAll()
90+
elif "hookContext" in json_input["args"]:
91+
_id = json_input["args"]["hookContext"]["id"]
92+
_type = json_input["args"]["hookContext"]["type"]
93+
if _type == "Scene.Update.Post":
94+
scene = stash.find_scene(_id)
95+
processScene(scene)
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
name: Funscript Markers
2+
description: Create markers if there is a funscript with "chapters" included in the metadata of the script
3+
version: 0.1
4+
url: https://github.com/stashapp/CommunityScripts/
5+
exec:
6+
- python
7+
- "{pluginDir}/funscriptMarkers.py"
8+
interface: raw
9+
tasks:
10+
- name: "Re-process All"
11+
description: Look at funscript files and see if there are chapters in the metadata
12+
defaultArgs:
13+
mode: processAll

0 commit comments

Comments
 (0)