Created
December 29, 2020 18:38
-
-
Save JonBons/9281b6ea338cd9a6f0842ee69ea80f0d to your computer and use it in GitHub Desktop.
OBSInfoWriter - Scene based hotkey text
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
import json | |
import obspython as obs | |
from itertools import cycle | |
class InfowriterSource: | |
def __init__(self, source_name=None, scene_data=None): | |
self.source_name = source_name | |
self.scene_data = scene_data | |
def update_text(self): | |
source = obs.obs_get_source_by_name(self.source_name) | |
if source is not None: | |
if self.scene_data is not None: | |
current_scene = obs.obs_frontend_get_current_scene() | |
current_scene_name = obs.obs_source_get_name(current_scene) | |
for x in self.scene_data: | |
if x['name'] == current_scene_name: | |
settings = obs.obs_data_create() | |
# hotkey1text through hotkey14text | |
for num, text in enumerate(x['hotkeyTexts'], start=1): | |
if num <= 14: | |
setting_key = "hotkey%stext" % num | |
obs.obs_data_set_string(settings, setting_key, text) | |
obs.obs_source_update(source, settings) | |
obs.obs_data_release(settings) | |
obs.obs_source_release(source) | |
break | |
writer = InfowriterSource() | |
def script_description(): | |
return "Updates the infowriter source text based on the current scene" | |
def script_update(settings): | |
config_path = obs.obs_data_get_string(settings, "config") | |
if config_path != '': | |
with open(config_path) as f: | |
data = json.load(f) | |
writer.scene_data = data | |
writer.source_name = obs.obs_data_get_string(settings, "source") | |
obs.timer_remove(writer.update_text) | |
if writer.source_name != "": | |
obs.timer_add(writer.update_text, 1 * 1000) | |
def script_properties(): # ui | |
props = obs.obs_properties_create() | |
obs.obs_properties_add_path( | |
props, | |
"config", | |
"Scene Config", | |
obs.OBS_PATH_FILE, | |
"JSON file (*.json)", | |
None | |
) | |
p = obs.obs_properties_add_list( | |
props, | |
"source", | |
"InfoWriter Source", | |
obs.OBS_COMBO_TYPE_EDITABLE, | |
obs.OBS_COMBO_FORMAT_STRING, | |
) | |
sources = obs.obs_enum_sources() | |
if sources is not None: | |
for source in sources: | |
source_id = obs.obs_source_get_unversioned_id(source) | |
if source_id == "infowriter": | |
name = obs.obs_source_get_name(source) | |
obs.obs_property_list_add_string(p, name, name) | |
obs.source_list_release(sources) | |
return props |
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
[ | |
{ | |
"name": "Scene", | |
"hotkeyTexts": [ | |
"Something 1", | |
"Something 2", | |
"Something 3", | |
"", | |
"For: Scene" | |
] | |
}, | |
{ | |
"name": "Scene 2", | |
"hotkeyTexts": [ | |
"Something 1", | |
"Something 2", | |
"Something 3", | |
"", | |
"For: Scene 2" | |
] | |
} | |
] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment