-- Delete the last recording in recordings folder, stop and delete, stop and delete + rerecord, and two functions that stop either the last recording and send it to new_path_1, or all files in the recordings folder that are sent to new_path_2 -- Author: Johan Reyes (jrey2125@gmail.com) -- Version 1.2 obs = obslua hotkey_id = obs.OBS_INVALID_HOTKEY_ID hotkey_id2 = obs.OBS_INVALID_HOTKEY_ID hotkey_id3 = obs.OBS_INVALID_HOTKEY_ID hotkey_id4 = obs.OBS_INVALID_HOTKEY_ID hoteky_id5 = obs.OBS_INVALID_HOTKEY_ID time = 0 new_path_1="" new_path_2="" -- Adds buttons that correspond to each function function script_properties(settings) local props = obs.obs_properties_create() obs.obs_properties_add_button(props, "delete_last_recording", "Delete Last Recording", delete_last_recording) obs.obs_properties_add_button(props, "stop_recording_then_delete_last_recording", "Stop Recording + Delete Last Recording", stop_recording_and_delete_last_recording) obs.obs_properties_add_button(props, "stop_delete_then_record", "Stop Recording, Delete, Begin Recording", stop_delete_then_record) obs.obs_properties_add_int(props, "time", "Seconds to Wait Before Starting New Recording", 0, 2147483647, 10) obs.obs_properties_add_button(props,"stop_then_send","Stop Recording, Send Last to Path 1", stop_then_send) obs.obs_properties_add_button(props,"stop_then_send_all","Stop Recording, Send ALL to Path 2", stop_then_send_all) obs.obs_properties_add_path(props, "new_path_1", "Path to Send Last Recording on Send to Path 1 Button",obs.OBS_PATH_DIRECTORY,"", nil) obs.obs_properties_add_path(props, "new_path_2", "Path to Send ALL Recordings on Send All to Path 2 Button",obs.OBS_PATH_DIRECTORY,"", nil) return props end function script_description() return "Adds three hotkeys and buttons to delete the last recording in recordings folder, stop recording and then delete the last recording right after, to do the latter but restart recording after the time variable amount of seconds, and two hotkeys and buttons for stopping recordings then moving the last or all to a designated path. \n \n (PERMANENTLY DELETES RECORDING, NOT TO RECYCLING BIN)" end function script_update(settings) time = obs.obs_data_get_int(settings, "time") new_path_1 = obs.obs_data_get_string(settings, "new_path_1") new_path_2 = obs.obs_data_get_string(settings, "new_path_2") end function script_defaults(settings) obs.obs_data_set_default_int(settings, "time", 0) end function script_load(settings) hotkey_id = obs.obs_hotkey_register_frontend("delete_last_recording", "Delete Last Recording", delete_last_recording) local hotkey_save_array = obs.obs_data_get_array(settings, "delete_last_recording") obs.obs_hotkey_load(hotkey_id, hotkey_save_array) obs.obs_data_array_release(hotkey_save_array) hotkey_id2 = obs.obs_hotkey_register_frontend("stop_recording_then_delete_last_recording", "Stop Recording + Delete Last Recording", stop_recording_and_delete_last_recording) local hotkey_save_array2 = obs.obs_data_get_array(settings, "stop_recording_then_delete_last_recording") obs.obs_hotkey_load(hotkey_id2, hotkey_save_array2) obs.obs_data_array_release(hotkey_save_array2) hotkey_id3 = obs.obs_hotkey_register_frontend("stop_delete_then_record", "Stop Recording, Delete, Begin Recording", stop_delete_then_record) local hotkey_save_array3 = obs.obs_data_get_array(settings, "stop_delete_then_record") obs.obs_hotkey_load(hotkey_id3, hotkey_save_array3) obs.obs_data_array_release(hotkey_save_array3) hotkey_id4 = obs.obs_hotkey_register_frontend("stop_then_send", "Stop Recording, Send Last to Path 1", stop_then_send) local hotkey_save_array4 = obs.obs_data_get_array(settings, "stop_then_send") obs.obs_hotkey_load(hotkey_id4, hotkey_save_array4) obs.obs_data_array_release(hotkey_save_array4) hotkey_id5 = obs.obs_hotkey_register_frontend("stop_then_send_all","Stop Recording, Send ALL to Path 2", stop_then_send_all) local hotkey_save_array5 = obs.obs_data_get_array(settings, "stop_then_send_all") obs.obs_hotkey_load(hotkey_id5, hotkey_save_array5) obs.obs_data_array_release(hotkey_save_array5) time = obs.obs_data_get_int(settings, "time") new_path_1=obs.obs_data_get_string(settings,"new_path_1") new_path_2=obs.obs_data_get_string(settings,"new_path_2") end function script_save(settings) local hotkey_save_array = obs.obs_hotkey_save(hotkey_id) obs.obs_data_set_array(settings, "delete_last_recording", hotkey_save_array) obs.obs_data_array_release(hotkey_save_array) local hotkey_save_array2 = obs.obs_hotkey_save(hotkey_id2) obs.obs_data_set_array(settings, "stop_recording_then_delete_last_recording", hotkey_save_array2) obs.obs_data_array_release(hotkey_save_array2) local hotkey_save_array3 = obs.obs_hotkey_save(hotkey_id3) obs.obs_data_set_array(settings, "stop_delete_then_record", hotkey_save_array3) obs.obs_data_array_release(hotkey_save_array3) local hotkey_save_array4 = obs.obs_hotkey_save(hotkey_id4) obs.obs_data_set_array(settings,"stop_then_send",hotkey_save_array4) obs.obs_data_array_release(hotkey_save_array4) local hotkey_save_array5 = obs.obs_hotkey_save(hotkey_id5) obs.obs_data_set_array(settings,"stop_then_send",hotkey_save_array5) obs.obs_data_array_release(hotkey_save_array5) obs.obs_data_set_int(settings, "time", time) obs.obs_data_set_string(settings,"new_path_1",new_path_1) obs.obs_data_set_string(settings,"new_path_2",new_path_2) end function delete_last_recording() local fileName = obs.obs_frontend_get_last_recording() local result, message = os.remove(fileName) -- if file is removed if result then print("Recording deleted successfully.") else print("Recording deletion failed.", message) end end -- Stops recording, waits 1 second, then deletes function stop_recording_and_delete_last_recording() obs.obs_frontend_recording_stop() sleep(1) delete_last_recording() end function stop_delete_then_record() stop_recording_and_delete_last_recording() sleep(time) obs.obs_frontend_recording_start() end function stop_then_send() obs.obs_frontend_recording_stop() sleep(1) local last = obs.obs_frontend_get_last_recording() local name= last:match("([^\\/]+)$") local dest =new_path_1 .. "\\" .. name local result, message= os.rename(last, dest) if result then print("Moved: " .. last .. " → " .. dest) else print("Couldn't move recording: " .. message) end end function stop_then_send_all() obs.obs_frontend_recording_stop() sleep(1) local fileNames = scandir(obs.obs_frontend_get_current_record_output_path()) local record_path = obs.obs_frontend_get_current_record_output_path() for i = 1, #fileNames do local name = fileNames[i] local filepath = record_path .. "\\" .. name local dest = new_path_2 .. "\\" .. name local result, message = os.rename(filepath, dest) if result then print("Moved: " .. filepath .. " → " .. dest) else print("Couldn't move recording: " .. name .. ": " .. message) end end end -- Source - https://stackoverflow.com/a/11130774 -- i didn't know how to run through all files in a folder and make them into an array in lua so i copy pasted from stack then changed it slightly -- Lua implementation of PHP scandir function function scandir(directory) local i, t, popen = 0, {}, io.popen local pfile = popen('dir "'..directory..'" /b') for filename in pfile:lines() do i = i + 1 t[i] = filename end pfile:close() return t end --waits x amount of sec function sleep(a) local sec = tonumber(os.clock() + a) while (os.clock() < sec) do end end