1- -- Version 0.0.1
2- configFile = ofs . ExtensionDir () .. " /config "
3- pythonFunscriptGenerator = ofs . ExtensionDir () .. " /funscript-editor/funscript-editor.exe "
1+ -- Version 0.0.2
2+ processHandle = nil
3+ scriptIdx = 0
44
5- function funscript_generator ()
5+ function start_funscript_generator ()
6+ scriptIdx = ofs .ActiveIdx ()
67 local tmpFile = ofs .ExtensionDir () .. " /funscript_actions.csv"
78 local video = player .CurrentVideo ()
8- local scriptIdx = ofs .ActiveIdx ()
99 local script = ofs .Script (scriptIdx )
1010 local currentTimeMs = player .CurrentTime () * 1000
11+ local cmd = ofs .ExtensionDir () .. " /funscript-editor/funscript-editor.exe"
1112
12- print (" funscriptGenerator " , pythonFunscriptGenerator )
13+ print (" cmd: " , cmd )
1314 print (" tmpFile: " , tmpFile )
1415 print (" video: " , video )
1516 print (" currentScriptIdx: " , scriptIdx )
@@ -20,26 +21,29 @@ function funscript_generator()
2021 next_action = ofs .ClosestActionAfter (script , script .actions [next_action ].at / 1000 )
2122 end
2223
23- if next_action then
24- print (" nextAction: " , script .actions [next_action ].at )
24+ print (" nextAction: " , next_action and tostring (script .actions [next_action ].at ) or " nil" )
25+
26+ if next_action then
27+ processHandle = ofs .CreateProcess (
28+ cmd , " --generator" ,
29+ " -s" , tostring (currentTimeMs ),
30+ " -e" , tostring (script .actions [next_action ].at ),
31+ " -i" , video ,
32+ " -o" , tmpFile
33+ )
2534 else
26- print (" nextAction: nil" )
35+ processHandle = ofs .CreateProcess (
36+ cmd , " --generator" ,
37+ " -s" , tostring (currentTimeMs ),
38+ " -i" , video ,
39+ " -o" , tmpFile
40+ )
2741 end
42+ end
2843
29- local command = ' "'
30- .. pythonFunscriptGenerator
31- .. ' " --generator -s '
32- .. ( next_action == nil and tostring (currentTimeMs ) or tostring (currentTimeMs ).. ' -e ' .. tostring (script .actions [next_action ].at ) )
33- .. ' -i "'
34- .. video
35- .. ' " -o "'
36- .. tmpFile
37- .. ' "'
38-
39-
40- print (" cmd: " , command )
41- ofs .SilentCmd (command , false )
4244
45+ function import_funscript_generator_result ()
46+ local tmpFile = ofs .ExtensionDir () .. " /funscript_actions.csv"
4347 local f = io.open (tmpFile )
4448 if not f then
4549 print (' Funscript Generator output file not found' )
6670
6771
6872function init ()
69- ofs .Bind (" funscript_generator " , " execute the funcript generator" )
73+ ofs .Bind (" start_funscript_generator " , " execute the funcript generator" )
7074end
7175
7276
7377function update (delta )
74-
78+ if processHandle and not ofs .IsProcessAlive (processHandle ) then
79+ print (' funscript generator completed, try import result' )
80+ processHandle = nil
81+ import_funscript_generator_result ()
82+ end
7583end
7684
7785
0 commit comments