Created
November 14, 2020 16:28
-
-
Save upgradeQ/5d0112e222dc410613eace8873e85bf7 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
local obs = obslua | |
--- name of a scene item | |
local source_name = '' | |
--- get the name of the current scene | |
local function current_scene_name() | |
local source = obs.obs_frontend_get_current_scene() | |
local name = obs.obs_source_get_name(source) | |
obs.obs_source_release(source) | |
return name | |
end | |
--- find the named scene item | |
local function find_scene_item() | |
local source = obs.obs_get_source_by_name(current_scene_name()) | |
if source then | |
local scene = obs.obs_scene_from_source(source) | |
obs.obs_source_release(source) | |
if scene then | |
local items = obs.obs_scene_enum_items(scene) | |
for _, item in ipairs(items) do | |
local item_source = obs.obs_sceneitem_get_source(item) | |
local item_name = obs.obs_source_get_name(item_source) | |
-- print(item_name) | |
if obs.obs_sceneitem_is_group(item) then | |
local group = obs.obs_group_from_source(item_source) | |
local group_items = obs.obs_scene_enum_items(group) | |
for _, group_item in ipairs(group_items) do | |
local group_item_source = obs.obs_sceneitem_get_source(group_item) | |
local group_item_name = obs.obs_source_get_name(group_item_source) | |
if source_name == group_item_name then | |
print('found: ' .. group_item_name) | |
end | |
end | |
obs.sceneitem_list_release(group_items) | |
end | |
end | |
obs.sceneitem_list_release(items) | |
end | |
end | |
scene_item = nil | |
print('done') | |
return false | |
end | |
function script_description() | |
return [[Repro of obs.obs_sceneitem_group_enum_items() bug | |
Open a scene with a Group and select the name of a Source within it {workaround version}]] | |
end | |
function script_properties() | |
local props = obs.obs_properties_create() | |
local source = obs.obs_properties_add_list( | |
props, | |
'source', | |
'Source:', | |
obs.OBS_COMBO_TYPE_EDITABLE, | |
obs.OBS_COMBO_FORMAT_STRING) | |
for _, name in ipairs(get_source_names()) do | |
obs.obs_property_list_add_string(source, name, name) | |
end | |
return props | |
end | |
function script_update(settings) | |
source_name = obs.obs_data_get_string(settings, 'source') | |
find_scene_item() | |
end | |
--- gets a list of source names, sorted alphabetically | |
function get_source_names() | |
local sources = obs.obs_enum_sources() | |
local source_names = {} | |
if sources then | |
for _, source in ipairs(sources) do | |
-- exclude Desktop Audio and Mic/Aux by their capabilities | |
local capability_flags = obs.obs_source_get_output_flags(source) | |
if bit.band(capability_flags, obs.OBS_SOURCE_DO_NOT_SELF_MONITOR) == 0 and | |
capability_flags ~= bit.bor(obs.OBS_SOURCE_AUDIO, obs.OBS_SOURCE_DO_NOT_DUPLICATE) then | |
table.insert(source_names, obs.obs_source_get_name(source)) | |
end | |
end | |
end | |
obs.source_list_release(sources) | |
table.sort(source_names, function(a, b) | |
return string.lower(a) < string.lower(b) | |
end) | |
return source_names | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment