|
| 1 | + |
| 2 | +configFile = ofs.ExtensionDir() .. "/config" |
| 3 | +pythonFunscriptGenerator = ofs.ExtensionDir .. "/funscript-editor/funscript-editor.exe" |
| 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("funscriptGenerator", pythonFunscriptGenerator) |
| 12 | + print("tmpFile: ", tmpFile) |
| 13 | + print("video: ", video) |
| 14 | + print("currentScriptIdx: ", ofs.ActiveIdx()) |
| 15 | + print("currentTimeMs: ", currentTimeMs) |
| 16 | + |
| 17 | + local next_action = ofs.ClosestActionAfter(script, currentTimeMs) |
| 18 | + if next_action and next_action.at < currentTimeMs + 500.0 then |
| 19 | + next_action = ofs.ClosestActionAfter(script, next_action.at) |
| 20 | + end |
| 21 | + |
| 22 | + if next_action then |
| 23 | + print("nextAction: ", next_action.at) -- TODO is this in seconds? |
| 24 | + else |
| 25 | + print("nextAction: nil") |
| 26 | + end |
| 27 | + |
| 28 | + local command = '"' |
| 29 | + ..pythonFunscriptGenerator |
| 30 | + ..'" --generator -s ' |
| 31 | + ..( next_action == nil and tostring(currentTimeMs) or tostring(currentTimeMs)..' -e '..tostring(next_action.at) ) |
| 32 | + ..' -i "' |
| 33 | + ..video |
| 34 | + ..'" -o "' |
| 35 | + ..tmpFile |
| 36 | + ..'"' |
| 37 | + |
| 38 | + |
| 39 | + print(command) |
| 40 | + ofs.SilentCmd(command, false) |
| 41 | + |
| 42 | + local f = io.open(tmpFile) |
| 43 | + if not f then |
| 44 | + print('lua: funscript generator output file not found') |
| 45 | + return |
| 46 | + end |
| 47 | + |
| 48 | + script = ofs.Script(ofs.ActiveIdx()) |
| 49 | + local k = 1 |
| 50 | + for line in f:lines() do |
| 51 | + -- first line is header |
| 52 | + if k > 1 then |
| 53 | + for at, pos in string.gmatch(line, "(%w+);(%w+)") do |
| 54 | + ofs.AddAction(script, at, pos, true) |
| 55 | + end |
| 56 | + end |
| 57 | + k = k + 1 |
| 58 | + end |
| 59 | + f:close() |
| 60 | + |
| 61 | + -- save changes |
| 62 | + ofs.Commit(script) |
| 63 | +end |
| 64 | + |
| 65 | + |
| 66 | + |
| 67 | +function init() |
| 68 | + ofs.Bind("funscript_generator", "execute the funcript generator") |
| 69 | +end |
| 70 | + |
| 71 | + |
| 72 | +function update(delta) |
| 73 | + |
| 74 | +end |
| 75 | + |
| 76 | + |
| 77 | +function gui() |
| 78 | + |
| 79 | +end |
0 commit comments