Skip to content

Commit c4a26e7

Browse files
author
arch
committed
add example OFS extension for linux
1 parent 080575c commit c4a26e7

File tree

4 files changed

+127
-8
lines changed

4 files changed

+127
-8
lines changed

.gitignore

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
1-
VERSION.txt
21
*.egg-info
3-
build
4-
dist
5-
debug*
6-
funscript-editor.spec
72
AppDir
8-
AppDir2
9-
linuxdeploy*.AppImage
103
Miniconda3-latest*.sh
4+
VERSION.txt
115
__pycache__
12-
funscript-editor*.AppImage
6+
build
7+
debug*
8+
dist
139
ffmpeg
1410
ffmpeg-git*.tar.xz
11+
funscript-editor*.AppImage
12+
funscript-editor.spec
13+
funscript_actions.csv
14+
linuxdeploy*.AppImage
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
pythonScript=/home/arch/Repos/public/Python-Funscript-Editor/funscript-editor.py
Lines changed: 115 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,115 @@
1+
2+
configFile = ofs.ExtensionDir() .. "/config"
3+
pythonScript = ""
4+
5+
6+
function getPath(str, sep)
7+
return str:match("(.*"..sep..")")
8+
end
9+
10+
11+
function funscript_generator()
12+
local tmpFile = getPath(pythonScript, '/') .. "funscript_actions.csv"
13+
local video = player.CurrentVideo()
14+
local script = ofs.Script(ofs.ActiveIdx())
15+
local currentTimeMs = player.CurrentTime() * 1000
16+
17+
print("tmpFile: ", tmpFile)
18+
print("video: ", video)
19+
print("currentScriptIdx: ", ofs.ActiveIdx())
20+
print("currentTimeMs: ", currentTimeMs)
21+
22+
local next_action = ofs.ClosestActionAfter(script, currentTimeMs)
23+
if next_action and next_action.at < currentTimeMs + 500.0 then
24+
next_action = ofs.ClosestActionAfter(script, next_action.at)
25+
end
26+
27+
if next_action then
28+
print("nextAction: ", next_action.at)
29+
else
30+
print("nextAction: nil")
31+
end
32+
33+
local command = 'python3 "'
34+
..pythonScript
35+
..'" --generator -s '
36+
..( next_action == nil and tostring(currentTimeMs) or tostring(currentTimeMs)..' -e '..tostring(next_action.at) )
37+
..' -i "'
38+
..video
39+
..'" -o "'
40+
..tmpFile
41+
..'"'
42+
43+
print(command)
44+
os.execute(command)
45+
46+
local f = io.open(tmpFile)
47+
if not f then
48+
print('lua: funscript generator output file not found')
49+
return
50+
end
51+
52+
local k = 1
53+
for line in f:lines() do
54+
-- first line is header
55+
if k > 1 then
56+
for at, pos in string.gmatch(line, "(%w+);(%w+)") do
57+
ofs.AddAction(script, at, pos, true)
58+
end
59+
end
60+
k = k + 1
61+
end
62+
f:close()
63+
64+
-- save changes
65+
ofs.Commit(script)
66+
end
67+
68+
69+
function load_config()
70+
print("try load config: ", configFile)
71+
72+
local f = io.open(configFile)
73+
if not f then
74+
print('extension config file not found')
75+
return
76+
end
77+
78+
for line in f:lines() do
79+
for k, v in string.gmatch(line, "([^=]+)=(([^=]+))") do
80+
if k == "pythonScript" then
81+
print("set pythonScript to", v)
82+
pythonScript = v
83+
end
84+
end
85+
end
86+
87+
f:close()
88+
end
89+
90+
91+
function save_config()
92+
-- print("save config to: ", configFile)
93+
local f = io.open(configFile, "w")
94+
f:write("pythonScript="..pythonScript)
95+
f:close()
96+
end
97+
98+
99+
function init()
100+
load_config()
101+
ofs.Bind("funscript_generator", "execute the funcript generator")
102+
end
103+
104+
105+
function update(delta)
106+
107+
end
108+
109+
110+
function gui()
111+
pythonScript, valueChanged = ofs.Input("pythonScript", pythonScript)
112+
if valueChanged then
113+
save_config()
114+
end
115+
end
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
# OFS Extensions
2+
3+
Example OFS Extensions to include the Python Motion Tracking Funscript Generator into OFS.

0 commit comments

Comments
 (0)