Skip to content

Commit 6bd09d8

Browse files
author
arch
committed
add windows ofs example extension
1 parent 815fa8b commit 6bd09d8

File tree

3 files changed

+113
-6
lines changed

3 files changed

+113
-6
lines changed

contrib/OpenFunscripter/extensions/Funscript Generator Linux/main.lua

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,8 @@ configFile = ofs.ExtensionDir() .. "/config"
33
pythonScript = ""
44

55

6-
function getPath(str, sep)
7-
return str:match("(.*"..sep..")")
8-
end
9-
10-
116
function funscript_generator()
12-
local tmpFile = getPath(pythonScript, '/') .. "funscript_actions.csv"
7+
local tmpFile = ofs.ExtensionDir() .. "/funscript_actions.csv"
138
local video = player.CurrentVideo()
149
local script = ofs.Script(ofs.ActiveIdx())
1510
local currentTimeMs = player.CurrentTime() * 1000
@@ -42,6 +37,7 @@ function funscript_generator()
4237

4338
print(command)
4439
os.execute(command)
40+
-- ofs.SilentCmd(command, true)
4541

4642
local f = io.open(tmpFile)
4743
if not f then
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
pythonFunscriptGenerator=C:/Users/win10/Desktop/funscript-editor/funscript-editor.exe
Lines changed: 110 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,110 @@
1+
2+
configFile = ofs.ExtensionDir() .. "/config"
3+
pythonFunscriptGenerator = ""
4+
5+
function funscript_generator()
6+
local tmpFile = ofs.ExtensionDir() .. "/funscript_actions.csv"
7+
local video = player.CurrentVideo()
8+
local script = ofs.Script(ofs.ActiveIdx())
9+
local currentTimeMs = player.CurrentTime() * 1000
10+
11+
print("tmpFile: ", tmpFile)
12+
print("video: ", video)
13+
print("currentScriptIdx: ", ofs.ActiveIdx())
14+
print("currentTimeMs: ", currentTimeMs)
15+
16+
local next_action = ofs.ClosestActionAfter(script, currentTimeMs)
17+
if next_action and next_action.at < currentTimeMs + 500.0 then
18+
next_action = ofs.ClosestActionAfter(script, next_action.at)
19+
end
20+
21+
if next_action then
22+
print("nextAction: ", next_action.at)
23+
else
24+
print("nextAction: nil")
25+
end
26+
27+
local command = '"'
28+
..pythonFunscriptGenerator
29+
..'" --generator -s '
30+
..( next_action == nil and tostring(currentTimeMs) or tostring(currentTimeMs)..' -e '..tostring(next_action.at) )
31+
..' -i "'
32+
..video
33+
..'" -o "'
34+
..tmpFile
35+
..'"'
36+
37+
38+
print(command)
39+
ofs.SilentCmd(command, true)
40+
41+
local f = io.open(tmpFile)
42+
if not f then
43+
print('lua: funscript generator output file not found')
44+
return
45+
end
46+
47+
local k = 1
48+
for line in f:lines() do
49+
-- first line is header
50+
if k > 1 then
51+
for at, pos in string.gmatch(line, "(%w+);(%w+)") do
52+
ofs.AddAction(script, at, pos, true)
53+
end
54+
end
55+
k = k + 1
56+
end
57+
f:close()
58+
59+
-- save changes
60+
ofs.Commit(script)
61+
end
62+
63+
64+
function load_config()
65+
print("try load config: ", configFile)
66+
67+
local f = io.open(configFile)
68+
if not f then
69+
print('extension config file not found')
70+
return
71+
end
72+
73+
for line in f:lines() do
74+
for k, v in string.gmatch(line, "([^=]+)=(([^=]+))") do
75+
if k == "pythonFunscriptGenerator" then
76+
print("set pythonFunscriptGenerator to", v)
77+
pythonFunscriptGenerator = v
78+
end
79+
end
80+
end
81+
82+
f:close()
83+
end
84+
85+
86+
function save_config()
87+
-- print("save config to: ", configFile)
88+
local f = io.open(configFile, "w")
89+
f:write("pythonFunscriptGenerator="..pythonFunscriptGenerator)
90+
f:close()
91+
end
92+
93+
94+
function init()
95+
load_config()
96+
ofs.Bind("funscript_generator", "execute the funcript generator")
97+
end
98+
99+
100+
function update(delta)
101+
102+
end
103+
104+
105+
function gui()
106+
pythonFunscriptGenerator, valueChanged = ofs.Input("pythonFunscriptGenerator", pythonFunscriptGenerator)
107+
if valueChanged then
108+
save_config()
109+
end
110+
end

0 commit comments

Comments
 (0)