mirror of
https://github.com/Mylloon/obs-replay-folders.git
synced 2025-01-15 20:44:31 +01:00
fix: game folders
This commit is contained in:
parent
76d1660a05
commit
6d93ee7510
4 changed files with 60 additions and 48 deletions
5
.gitignore
vendored
5
.gitignore
vendored
|
@ -1,3 +1,6 @@
|
||||||
|
*.c
|
||||||
|
*.cmd
|
||||||
|
|
||||||
# Compiled Lua sources
|
# Compiled Lua sources
|
||||||
luac.out
|
luac.out
|
||||||
|
|
||||||
|
@ -32,10 +35,8 @@ luac.out
|
||||||
*.dylib
|
*.dylib
|
||||||
|
|
||||||
# Executables
|
# Executables
|
||||||
*.exe
|
|
||||||
*.out
|
*.out
|
||||||
*.app
|
*.app
|
||||||
*.i*86
|
*.i*86
|
||||||
*.x86_64
|
*.x86_64
|
||||||
*.hex
|
*.hex
|
||||||
|
|
||||||
|
|
|
@ -1,62 +1,71 @@
|
||||||
obs = obslua
|
obs = obslua
|
||||||
|
|
||||||
function script_description()
|
function script_description()
|
||||||
return [[Saves replays to sub-folders using the Game Capture window name.
|
return [[Saves replays to sub-folders using the Game Capture executable name.
|
||||||
|
|
||||||
Author: redraskal]]
|
Author: redraskal]]
|
||||||
end
|
end
|
||||||
|
|
||||||
function script_load()
|
function script_load()
|
||||||
obs.obs_frontend_add_event_callback(obs_frontend_callback)
|
obs.obs_frontend_add_event_callback(obs_frontend_callback)
|
||||||
|
folder = get_running_game_title()
|
||||||
end
|
end
|
||||||
|
|
||||||
function obs_frontend_callback(event)
|
function obs_frontend_callback(event)
|
||||||
if event == obs.OBS_FRONTEND_EVENT_REPLAY_BUFFER_SAVED then
|
if event == obs.OBS_FRONTEND_EVENT_REPLAY_BUFFER_STARTED then
|
||||||
local path = get_replay_buffer_output()
|
folder = get_running_game_title()
|
||||||
local folder = get_game_capture_window_name()
|
end
|
||||||
if path ~= nil and folder ~= nil then
|
if event == obs.OBS_FRONTEND_EVENT_REPLAY_BUFFER_SAVED then
|
||||||
move(path, folder)
|
local path = get_replay_buffer_output()
|
||||||
end
|
if path ~= nil and folder ~= nil then
|
||||||
end
|
print("Moving " .. path .. " to " .. folder)
|
||||||
|
move(path, folder)
|
||||||
|
end
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
function get_replay_buffer_output()
|
function get_replay_buffer_output()
|
||||||
local replay_buffer = obs.obs_frontend_get_replay_buffer_output()
|
local replay_buffer = obs.obs_frontend_get_replay_buffer_output()
|
||||||
local cd = obs.calldata_create()
|
local cd = obs.calldata_create()
|
||||||
local ph = obs.obs_output_get_proc_handler(replay_buffer)
|
local ph = obs.obs_output_get_proc_handler(replay_buffer)
|
||||||
obs.proc_handler_call(ph, "get_last_replay", cd)
|
obs.proc_handler_call(ph, "get_last_replay", cd)
|
||||||
local path = obs.calldata_string(cd, "path")
|
local path = obs.calldata_string(cd, "path")
|
||||||
obs.calldata_destroy(cd)
|
obs.calldata_destroy(cd)
|
||||||
obs.obs_output_release(replay_buffer)
|
obs.obs_output_release(replay_buffer)
|
||||||
return path
|
return path
|
||||||
end
|
end
|
||||||
|
|
||||||
function get_game_capture_window_name()
|
function get_running_game_title()
|
||||||
-- TODO: Infer source
|
local handle = assert(io.popen("detect_game"))
|
||||||
-- current_scene = obs.obs_frontend_get_current_scene()
|
local result = handle:read("*all")
|
||||||
-- game_capture = obs.obs_scene_find_source(current_scene, "Game Capture")
|
handle:close()
|
||||||
game_capture = obs.obs_get_source_by_name("Game Capture")
|
local len = #result
|
||||||
local properties = obs.obs_source_properties(game_capture)
|
if len == 0 then
|
||||||
local prop = obs.obs_properties_get(properties, "window")
|
return nil
|
||||||
local setting = obs.obs_property_name(prop)
|
end
|
||||||
local settings = obs.obs_source_get_settings(game_capture)
|
local title = ""
|
||||||
local value = obs.obs_data_get_string(settings, setting)
|
local i = 1
|
||||||
obs.obs_data_release(settings)
|
local max = len - 4
|
||||||
obs.obs_properties_destroy(properties)
|
while i <= max do
|
||||||
obs.obs_source_release(game_capture)
|
local char = result:sub(i, i)
|
||||||
-- obs.obs_source_release(current_scene)
|
if char == "\\" then
|
||||||
local i, j = string.find(value, " :")
|
title = ""
|
||||||
local title = string.sub(value, 1, j - 3)
|
else
|
||||||
return title
|
title = title .. char
|
||||||
|
end
|
||||||
|
i = i + 1
|
||||||
|
end
|
||||||
|
print("Current running game: " .. title)
|
||||||
|
return title
|
||||||
end
|
end
|
||||||
|
|
||||||
function move(path, folder)
|
function move(path, folder)
|
||||||
local sep = string.match(path, "^.*()/")
|
local sep = string.match(path, "^.*()/")
|
||||||
local root = string.sub(path, 1, sep) .. folder
|
local root = string.sub(path, 1, sep) .. folder
|
||||||
local file_name = string.sub(path, sep, string.len(path))
|
local file_name = string.sub(path, sep, string.len(path))
|
||||||
local adjusted_path = root .. file_name
|
local adjusted_path = root .. file_name
|
||||||
if obs.os_file_exists(root) == false then
|
if obs.os_file_exists(root) == false then
|
||||||
obs.os_mkdir(root)
|
obs.os_mkdir(root)
|
||||||
end
|
end
|
||||||
obs.os_rename(path, adjusted_path)
|
obs.os_rename(path, adjusted_path)
|
||||||
end
|
end
|
||||||
|
|
|
@ -1,8 +1,10 @@
|
||||||
# obs-replay-folders
|
# obs-replay-folders
|
||||||
|
|
||||||
Saves replay buffer files to game-specific folders (like ShadowPlay).
|
Saves replay buffer files to game-specific folders (like ShadowPlay).
|
||||||
|
|
||||||
## About
|
## Important:
|
||||||
|
|
||||||
Replay Buffer Folders moves replay buffer files to a sub-folder upon creation. The sub-folder is determined by the current window title in the Game Capture source. Tested on Windows.
|
1. The script requires `detect_game.exe` to be added to PATH.
|
||||||
|
2. To update the replay folder, restart the Replay Buffer.
|
||||||
|
|
||||||
### The script requires the Game Capture source to be called "Game Capture".
|
There is no way to run an executable in Lua without breaking fullscreen application focus. So, the current running game will not automatically update.
|
||||||
|
|
BIN
detect_game.exe
Normal file
BIN
detect_game.exe
Normal file
Binary file not shown.
Loading…
Reference in a new issue